xref: /php-src/ext/standard/file.h (revision f756b96e)
1 /*
2    +----------------------------------------------------------------------+
3    | Copyright (c) The PHP Group                                          |
4    +----------------------------------------------------------------------+
5    | This source file is subject to version 3.01 of the PHP license,      |
6    | that is bundled with this package in the file LICENSE, and is        |
7    | available through the world-wide-web at the following url:           |
8    | https://www.php.net/license/3_01.txt                                 |
9    | If you did not receive a copy of the PHP license and are unable to   |
10    | obtain it through the world-wide-web, please send a note to          |
11    | license@php.net so we can mail you a copy immediately.               |
12    +----------------------------------------------------------------------+
13    | Author: Rasmus Lerdorf <rasmus@lerdorf.on.ca>                        |
14    +----------------------------------------------------------------------+
15 */
16 
17 #ifndef FILE_H
18 #define FILE_H
19 
20 #include "php_network.h"
21 
22 PHP_MINIT_FUNCTION(file);
23 PHP_MSHUTDOWN_FUNCTION(file);
24 
25 PHPAPI PHP_FUNCTION(fclose);
26 PHPAPI PHP_FUNCTION(feof);
27 PHPAPI PHP_FUNCTION(fread);
28 PHPAPI PHP_FUNCTION(fgetc);
29 PHPAPI PHP_FUNCTION(fgets);
30 PHPAPI PHP_FUNCTION(fwrite);
31 PHPAPI PHP_FUNCTION(fflush);
32 PHPAPI PHP_FUNCTION(rewind);
33 PHPAPI PHP_FUNCTION(ftell);
34 PHPAPI PHP_FUNCTION(fseek);
35 PHPAPI PHP_FUNCTION(fpassthru);
36 
37 PHP_MINIT_FUNCTION(user_streams);
38 
39 PHPAPI int php_le_stream_context(void);
40 PHPAPI zend_result php_copy_file(const char *src, const char *dest);
41 PHPAPI zend_result php_copy_file_ex(const char *src, const char *dest, int src_flags);
42 PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_flags, php_stream_context *ctx);
43 PHPAPI int php_mkdir_ex(const char *dir, zend_long mode, int options);
44 PHPAPI int php_mkdir(const char *dir, zend_long mode);
45 PHPAPI void php_fstat(php_stream *stream, zval *return_value);
46 PHPAPI void php_flock_common(php_stream *stream, zend_long operation, uint32_t operation_arg_num,
47 	zval *wouldblock, zval *return_value);
48 
49 #define PHP_CSV_NO_ESCAPE EOF
50 #define PHP_CSV_ESCAPE_ERROR -500
51 
52 PHPAPI HashTable *php_bc_fgetcsv_empty_line(void);
53 PHPAPI int php_csv_handle_escape_argument(const zend_string *escape_str, uint32_t arg_num);
54 PHPAPI HashTable *php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int escape_char, size_t buf_len, char *buf);
55 PHPAPI ssize_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, int escape_char, zend_string *eol_str);
56 
57 #define META_DEF_BUFSIZE 8192
58 
59 #define PHP_FILE_USE_INCLUDE_PATH (1 << 0)
60 #define PHP_FILE_IGNORE_NEW_LINES (1 << 1)
61 #define PHP_FILE_SKIP_EMPTY_LINES (1 << 2)
62 #define PHP_FILE_APPEND (1 << 3)
63 #define PHP_FILE_NO_DEFAULT_CONTEXT (1 << 4)
64 
65 #ifndef _WIN32
66 #define PHP_TIMEOUT_ULL_MAX ULLONG_MAX
67 #else
68 #define PHP_TIMEOUT_ULL_MAX UINT64_MAX
69 #endif
70 
71 typedef enum _php_meta_tags_token {
72 	TOK_EOF = 0,
73 	TOK_OPENTAG,
74 	TOK_CLOSETAG,
75 	TOK_SLASH,
76 	TOK_EQUAL,
77 	TOK_SPACE,
78 	TOK_ID,
79 	TOK_STRING,
80 	TOK_OTHER
81 } php_meta_tags_token;
82 
83 typedef struct _php_meta_tags_data {
84 	php_stream *stream;
85 	int ulc;
86 	int lc;
87 	char *input_buffer;
88 	char *token_data;
89 	int token_len;
90 	int in_meta;
91 } php_meta_tags_data;
92 
93 php_meta_tags_token php_next_meta_token(php_meta_tags_data *);
94 
95 typedef struct {
96 	int pclose_ret;
97 	size_t def_chunk_size;
98 	bool auto_detect_line_endings;
99 	zend_long default_socket_timeout;
100 	char *user_agent; /* for the http wrapper */
101 	char *from_address; /* for the ftp and http wrappers */
102 	const char *user_stream_current_filename; /* for simple recursion protection */
103 	php_stream_context *default_context;
104 	HashTable *stream_wrappers;			/* per-request copy of url_stream_wrappers_hash */
105 	HashTable *stream_filters;			/* per-request copy of stream_filters_hash */
106 	HashTable *wrapper_errors;			/* key: wrapper address; value: linked list of char* */
107 	int pclose_wait;
108 #ifdef HAVE_GETHOSTBYNAME_R
109 	struct hostent tmp_host_info;
110 	char *tmp_host_buf;
111 	size_t tmp_host_buf_len;
112 #endif
113 } php_file_globals;
114 
115 #ifdef ZTS
116 #define FG(v) ZEND_TSRMG(file_globals_id, php_file_globals *, v)
117 extern PHPAPI int file_globals_id;
118 #else
119 #define FG(v) (file_globals.v)
120 extern PHPAPI php_file_globals file_globals;
121 #endif
122 
123 
124 #endif /* FILE_H */
125