xref: /PHP-7.3/ext/standard/basic_functions.h (revision 9afce019)
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    | Authors: Andi Gutmans <andi@php.net>                                 |
16    |          Zeev Suraski <zeev@php.net>                                 |
17    +----------------------------------------------------------------------+
18 */
19 
20 #ifndef BASIC_FUNCTIONS_H
21 #define BASIC_FUNCTIONS_H
22 
23 #include <sys/stat.h>
24 
25 #ifdef HAVE_WCHAR_H
26 #include <wchar.h>
27 #endif
28 
29 #include "php_filestat.h"
30 
31 #include "zend_highlight.h"
32 
33 #include "url_scanner_ex.h"
34 
35 #if defined(_WIN32) && !defined(__clang__)
36 #include <intrin.h>
37 #endif
38 
39 extern zend_module_entry basic_functions_module;
40 #define basic_functions_module_ptr &basic_functions_module
41 
42 PHP_MINIT_FUNCTION(basic);
43 PHP_MSHUTDOWN_FUNCTION(basic);
44 PHP_RINIT_FUNCTION(basic);
45 PHP_RSHUTDOWN_FUNCTION(basic);
46 PHP_MINFO_FUNCTION(basic);
47 
48 PHP_FUNCTION(constant);
49 PHP_FUNCTION(sleep);
50 PHP_FUNCTION(usleep);
51 #if HAVE_NANOSLEEP
52 PHP_FUNCTION(time_nanosleep);
53 PHP_FUNCTION(time_sleep_until);
54 #endif
55 PHP_FUNCTION(flush);
56 #ifdef HAVE_INET_NTOP
57 PHP_NAMED_FUNCTION(zif_inet_ntop);
58 #endif
59 #ifdef HAVE_INET_PTON
60 PHP_NAMED_FUNCTION(php_inet_pton);
61 #endif
62 PHP_FUNCTION(ip2long);
63 PHP_FUNCTION(long2ip);
64 
65 /* system functions */
66 PHP_FUNCTION(getenv);
67 PHP_FUNCTION(putenv);
68 
69 PHP_FUNCTION(getopt);
70 
71 PHP_FUNCTION(get_current_user);
72 PHP_FUNCTION(set_time_limit);
73 
74 PHP_FUNCTION(header_register_callback);
75 
76 PHP_FUNCTION(get_cfg_var);
77 PHP_FUNCTION(get_magic_quotes_runtime);
78 PHP_FUNCTION(get_magic_quotes_gpc);
79 
80 PHP_FUNCTION(error_log);
81 PHP_FUNCTION(error_get_last);
82 PHP_FUNCTION(error_clear_last);
83 
84 PHP_FUNCTION(call_user_func);
85 PHP_FUNCTION(call_user_func_array);
86 PHP_FUNCTION(forward_static_call);
87 PHP_FUNCTION(forward_static_call_array);
88 
89 PHP_FUNCTION(register_shutdown_function);
90 PHP_FUNCTION(highlight_file);
91 PHP_FUNCTION(highlight_string);
92 PHP_FUNCTION(php_strip_whitespace);
93 ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini);
94 
95 PHP_FUNCTION(ini_get);
96 PHP_FUNCTION(ini_get_all);
97 PHP_FUNCTION(ini_set);
98 PHP_FUNCTION(ini_restore);
99 PHP_FUNCTION(get_include_path);
100 PHP_FUNCTION(set_include_path);
101 PHP_FUNCTION(restore_include_path);
102 
103 PHP_FUNCTION(print_r);
104 PHP_FUNCTION(fprintf);
105 PHP_FUNCTION(vfprintf);
106 
107 PHP_FUNCTION(connection_aborted);
108 PHP_FUNCTION(connection_status);
109 PHP_FUNCTION(ignore_user_abort);
110 
111 PHP_FUNCTION(getservbyname);
112 PHP_FUNCTION(getservbyport);
113 PHP_FUNCTION(getprotobyname);
114 PHP_FUNCTION(getprotobynumber);
115 
116 PHP_NAMED_FUNCTION(php_if_crc32);
117 
118 PHP_FUNCTION(register_tick_function);
119 PHP_FUNCTION(unregister_tick_function);
120 #ifdef HAVE_GETLOADAVG
121 PHP_FUNCTION(sys_getloadavg);
122 #endif
123 
124 PHP_FUNCTION(is_uploaded_file);
125 PHP_FUNCTION(move_uploaded_file);
126 
127 PHP_FUNCTION(net_get_interfaces);
128 
129 /* From the INI parser */
130 PHP_FUNCTION(parse_ini_file);
131 PHP_FUNCTION(parse_ini_string);
132 #if ZEND_DEBUG
133 PHP_FUNCTION(config_get_hash);
134 #endif
135 
136 #if defined(PHP_WIN32)
137 PHP_FUNCTION(sapi_windows_cp_set);
138 PHP_FUNCTION(sapi_windows_cp_get);
139 PHP_FUNCTION(sapi_windows_cp_is_utf8);
140 PHP_FUNCTION(sapi_windows_cp_conv);
141 #endif
142 
143 PHP_FUNCTION(str_rot13);
144 PHP_FUNCTION(stream_get_filters);
145 PHP_FUNCTION(stream_filter_register);
146 PHP_FUNCTION(stream_bucket_make_writeable);
147 PHP_FUNCTION(stream_bucket_prepend);
148 PHP_FUNCTION(stream_bucket_append);
149 PHP_FUNCTION(stream_bucket_new);
150 PHP_MINIT_FUNCTION(user_filters);
151 PHP_RSHUTDOWN_FUNCTION(user_filters);
152 PHP_RSHUTDOWN_FUNCTION(browscap);
153 
154 /* Left for BC (not binary safe!) */
155 PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers);
156 PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, char *opt, char *headers);
157 PHPAPI int php_prefix_varname(zval *result, const zval *prefix, const char *var_name, size_t var_name_len, zend_bool add_underscore);
158 
159 #define MT_N (624)
160 
161 /* Deprecated type aliases -- use the standard types instead */
162 typedef uint32_t php_uint32;
163 typedef int32_t php_int32;
164 
165 typedef struct _php_basic_globals {
166 	HashTable *user_shutdown_function_names;
167 	HashTable putenv_ht;
168 	zval  strtok_zval;
169 	char *strtok_string;
170 	zend_string *locale_string; /* current LC_CTYPE locale (or NULL for 'C') */
171 	zend_bool locale_changed;   /* locale was changed and has to be restored */
172 	char *strtok_last;
173 	char strtok_table[256];
174 	zend_ulong strtok_len;
175 	char str_ebuf[40];
176 	zend_fcall_info array_walk_fci;
177 	zend_fcall_info_cache array_walk_fci_cache;
178 	zend_fcall_info user_compare_fci;
179 	zend_fcall_info_cache user_compare_fci_cache;
180 	zend_llist *user_tick_functions;
181 
182 	zval active_ini_file_section;
183 
184 	/* pageinfo.c */
185 	zend_long page_uid;
186 	zend_long page_gid;
187 	zend_long page_inode;
188 	time_t page_mtime;
189 
190 	/* filestat.c && main/streams/streams.c */
191 	char *CurrentStatFile, *CurrentLStatFile;
192 	php_stream_statbuf ssb, lssb;
193 
194 	/* mt_rand.c */
195 	uint32_t state[MT_N+1];  /* state vector + 1 extra to not violate ANSI C */
196 	uint32_t *next;       /* next random value is computed from here */
197 	int      left;        /* can *next++ this many times before reloading */
198 
199 	zend_bool mt_rand_is_seeded; /* Whether mt_rand() has been seeded */
200 	zend_long mt_rand_mode;
201 
202 	/* syslog.c */
203 	char *syslog_device;
204 
205 	/* var.c */
206 	zend_class_entry *incomplete_class;
207 	unsigned serialize_lock; /* whether to use the locally supplied var_hash instead (__sleep/__wakeup) */
208 	struct {
209 		struct php_serialize_data *data;
210 		unsigned level;
211 	} serialize;
212 	struct {
213 		struct php_unserialize_data *data;
214 		unsigned level;
215 	} unserialize;
216 
217 	/* url_scanner_ex.re */
218 	url_adapt_state_ex_t url_adapt_session_ex;
219 	HashTable url_adapt_session_hosts_ht;
220 	url_adapt_state_ex_t url_adapt_output_ex;
221 	HashTable url_adapt_output_hosts_ht;
222 
223 #ifdef HAVE_MMAP
224 	void *mmap_file;
225 	size_t mmap_len;
226 #endif
227 
228 	HashTable *user_filter_map;
229 
230 	/* file.c */
231 #if defined(_REENTRANT) && defined(HAVE_MBRLEN) && defined(HAVE_MBSTATE_T)
232 	mbstate_t mblen_state;
233 #endif
234 
235 	int umask;
236 } php_basic_globals;
237 
238 #ifdef ZTS
239 #define BG(v) ZEND_TSRMG(basic_globals_id, php_basic_globals *, v)
240 PHPAPI extern int basic_globals_id;
241 #else
242 #define BG(v) (basic_globals.v)
243 PHPAPI extern php_basic_globals basic_globals;
244 #endif
245 
246 #if HAVE_PUTENV
247 typedef struct {
248 	char *putenv_string;
249 	char *previous_value;
250 	char *key;
251 	size_t key_len;
252 } putenv_entry;
253 #endif
254 
255 PHPAPI double php_get_nan(void);
256 PHPAPI double php_get_inf(void);
257 
258 typedef struct _php_shutdown_function_entry {
259 	zval *arguments;
260 	int arg_count;
261 } php_shutdown_function_entry;
262 
263 PHPAPI extern zend_bool register_user_shutdown_function(char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry);
264 PHPAPI extern zend_bool remove_user_shutdown_function(char *function_name, size_t function_len);
265 PHPAPI extern zend_bool append_user_shutdown_function(php_shutdown_function_entry shutdown_function_entry);
266 
267 PHPAPI void php_call_shutdown_functions(void);
268 PHPAPI void php_free_shutdown_functions(void);
269 
270 
271 #endif /* BASIC_FUNCTIONS_H */
272