xref: /PHP-7.3/ext/standard/file.h (revision 81cefab7)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca>                        |
16    +----------------------------------------------------------------------+
17 */
18 
19 #ifndef FILE_H
20 #define FILE_H
21 
22 #include "php_network.h"
23 
24 PHP_MINIT_FUNCTION(file);
25 PHP_MSHUTDOWN_FUNCTION(file);
26 
27 PHP_FUNCTION(tempnam);
28 PHP_NAMED_FUNCTION(php_if_tmpfile);
29 PHP_NAMED_FUNCTION(php_if_fopen);
30 PHPAPI PHP_FUNCTION(fclose);
31 PHP_FUNCTION(popen);
32 PHP_FUNCTION(pclose);
33 PHPAPI PHP_FUNCTION(feof);
34 PHPAPI PHP_FUNCTION(fread);
35 PHPAPI PHP_FUNCTION(fgetc);
36 PHPAPI PHP_FUNCTION(fgets);
37 PHP_FUNCTION(fscanf);
38 PHPAPI PHP_FUNCTION(fgetss);
39 PHP_FUNCTION(fgetcsv);
40 PHP_FUNCTION(fputcsv);
41 PHPAPI PHP_FUNCTION(fwrite);
42 PHPAPI PHP_FUNCTION(fflush);
43 PHPAPI PHP_FUNCTION(rewind);
44 PHPAPI PHP_FUNCTION(ftell);
45 PHPAPI PHP_FUNCTION(fseek);
46 PHP_FUNCTION(mkdir);
47 PHP_FUNCTION(rmdir);
48 PHPAPI PHP_FUNCTION(fpassthru);
49 PHP_FUNCTION(readfile);
50 PHP_FUNCTION(umask);
51 PHP_FUNCTION(rename);
52 PHP_FUNCTION(unlink);
53 PHP_FUNCTION(copy);
54 PHP_FUNCTION(file);
55 PHP_FUNCTION(file_get_contents);
56 PHP_FUNCTION(file_put_contents);
57 PHP_FUNCTION(get_meta_tags);
58 PHP_FUNCTION(flock);
59 PHP_FUNCTION(fd_set);
60 PHP_FUNCTION(fd_isset);
61 #if HAVE_REALPATH || defined(ZTS)
62 PHP_FUNCTION(realpath);
63 #endif
64 #ifdef HAVE_FNMATCH
65 PHP_FUNCTION(fnmatch);
66 #endif
67 PHP_NAMED_FUNCTION(php_if_ftruncate);
68 PHP_NAMED_FUNCTION(php_if_fstat);
69 PHP_FUNCTION(sys_get_temp_dir);
70 
71 PHP_MINIT_FUNCTION(user_streams);
72 
73 PHPAPI int php_le_stream_context(void);
74 PHPAPI int php_set_sock_blocking(php_socket_t socketd, int block);
75 PHPAPI int php_copy_file(const char *src, const char *dest);
76 PHPAPI int php_copy_file_ex(const char *src, const char *dest, int src_chk);
77 PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_chk, php_stream_context *ctx);
78 PHPAPI int php_mkdir_ex(const char *dir, zend_long mode, int options);
79 PHPAPI int php_mkdir(const char *dir, zend_long mode);
80 PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char escape_char, size_t buf_len, char *buf, zval *return_value);
81 PHPAPI size_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, char escape_char);
82 
83 #define META_DEF_BUFSIZE 8192
84 
85 #define PHP_FILE_USE_INCLUDE_PATH 1
86 #define PHP_FILE_IGNORE_NEW_LINES 2
87 #define PHP_FILE_SKIP_EMPTY_LINES 4
88 #define PHP_FILE_APPEND 8
89 #define PHP_FILE_NO_DEFAULT_CONTEXT 16
90 
91 typedef enum _php_meta_tags_token {
92 	TOK_EOF = 0,
93 	TOK_OPENTAG,
94 	TOK_CLOSETAG,
95 	TOK_SLASH,
96 	TOK_EQUAL,
97 	TOK_SPACE,
98 	TOK_ID,
99 	TOK_STRING,
100 	TOK_OTHER
101 } php_meta_tags_token;
102 
103 typedef struct _php_meta_tags_data {
104 	php_stream *stream;
105 	int ulc;
106 	int lc;
107 	char *input_buffer;
108 	char *token_data;
109 	int token_len;
110 	int in_meta;
111 } php_meta_tags_data;
112 
113 php_meta_tags_token php_next_meta_token(php_meta_tags_data *);
114 
115 typedef struct {
116 	int pclose_ret;
117 	size_t def_chunk_size;
118 	zend_long auto_detect_line_endings;
119 	zend_long default_socket_timeout;
120 	char *user_agent; /* for the http wrapper */
121 	char *from_address; /* for the ftp and http wrappers */
122 	const char *user_stream_current_filename; /* for simple recursion protection */
123 	php_stream_context *default_context;
124 	HashTable *stream_wrappers;			/* per-request copy of url_stream_wrappers_hash */
125 	HashTable *stream_filters;			/* per-request copy of stream_filters_hash */
126 	HashTable *wrapper_errors;			/* key: wrapper address; value: linked list of char* */
127 	int pclose_wait;
128 #if defined(HAVE_GETHOSTBYNAME_R)
129 	struct hostent tmp_host_info;
130 	char *tmp_host_buf;
131 	size_t tmp_host_buf_len;
132 #endif
133 } php_file_globals;
134 
135 #ifdef ZTS
136 #define FG(v) ZEND_TSRMG(file_globals_id, php_file_globals *, v)
137 extern PHPAPI int file_globals_id;
138 #else
139 #define FG(v) (file_globals.v)
140 extern PHPAPI php_file_globals file_globals;
141 #endif
142 
143 
144 #endif /* FILE_H */
145