xref: /PHP-7.4/ext/standard/basic_functions.h (revision 1806ce9c)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 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 PHP_FUNCTION(sapi_windows_set_ctrl_handler);
142 PHP_FUNCTION(sapi_windows_generate_ctrl_event);
143 #endif
144 
145 PHP_FUNCTION(str_rot13);
146 PHP_FUNCTION(stream_get_filters);
147 PHP_FUNCTION(stream_filter_register);
148 PHP_FUNCTION(stream_bucket_make_writeable);
149 PHP_FUNCTION(stream_bucket_prepend);
150 PHP_FUNCTION(stream_bucket_append);
151 PHP_FUNCTION(stream_bucket_new);
152 PHP_MINIT_FUNCTION(user_filters);
153 PHP_RSHUTDOWN_FUNCTION(user_filters);
154 PHP_RSHUTDOWN_FUNCTION(browscap);
155 
156 /* Left for BC (not binary safe!) */
157 PHPAPI int _php_error_log(int opt_err, char *message, char *opt, char *headers);
158 PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, char *opt, char *headers);
159 PHPAPI int php_prefix_varname(zval *result, const zval *prefix, const char *var_name, size_t var_name_len, zend_bool add_underscore);
160 
161 #define MT_N (624)
162 
163 /* Deprecated type aliases -- use the standard types instead */
164 typedef uint32_t php_uint32;
165 typedef int32_t php_int32;
166 
167 typedef struct _php_basic_globals {
168 	HashTable *user_shutdown_function_names;
169 	HashTable putenv_ht;
170 	zval  strtok_zval;
171 	char *strtok_string;
172 	zend_string *locale_string; /* current LC_CTYPE locale (or NULL for 'C') */
173 	zend_bool locale_changed;   /* locale was changed and has to be restored */
174 	char *strtok_last;
175 	char strtok_table[256];
176 	zend_ulong strtok_len;
177 	char str_ebuf[40];
178 	zend_fcall_info array_walk_fci;
179 	zend_fcall_info_cache array_walk_fci_cache;
180 	zend_fcall_info user_compare_fci;
181 	zend_fcall_info_cache user_compare_fci_cache;
182 	zend_llist *user_tick_functions;
183 
184 	zval active_ini_file_section;
185 
186 	/* pageinfo.c */
187 	zend_long page_uid;
188 	zend_long page_gid;
189 	zend_long page_inode;
190 	time_t page_mtime;
191 
192 	/* filestat.c && main/streams/streams.c */
193 	char *CurrentStatFile, *CurrentLStatFile;
194 	php_stream_statbuf ssb, lssb;
195 
196 	/* mt_rand.c */
197 	uint32_t state[MT_N+1];  /* state vector + 1 extra to not violate ANSI C */
198 	uint32_t *next;       /* next random value is computed from here */
199 	int      left;        /* can *next++ this many times before reloading */
200 
201 	zend_bool mt_rand_is_seeded; /* Whether mt_rand() has been seeded */
202 	zend_long mt_rand_mode;
203 
204 	/* syslog.c */
205 	char *syslog_device;
206 
207 	/* var.c */
208 	zend_class_entry *incomplete_class;
209 	unsigned serialize_lock; /* whether to use the locally supplied var_hash instead (__sleep/__wakeup) */
210 	struct {
211 		struct php_serialize_data *data;
212 		unsigned level;
213 	} serialize;
214 	struct {
215 		struct php_unserialize_data *data;
216 		unsigned level;
217 	} unserialize;
218 
219 	/* url_scanner_ex.re */
220 	url_adapt_state_ex_t url_adapt_session_ex;
221 	HashTable url_adapt_session_hosts_ht;
222 	url_adapt_state_ex_t url_adapt_output_ex;
223 	HashTable url_adapt_output_hosts_ht;
224 
225 #ifdef HAVE_MMAP
226 	void *mmap_file;
227 	size_t mmap_len;
228 #endif
229 
230 	HashTable *user_filter_map;
231 
232 	/* file.c */
233 #if defined(_REENTRANT) && defined(HAVE_MBRLEN) && defined(HAVE_MBSTATE_T)
234 	mbstate_t mblen_state;
235 #endif
236 
237 	int umask;
238 	zend_long unserialize_max_depth;
239 } php_basic_globals;
240 
241 #ifdef ZTS
242 #define BG(v) ZEND_TSRMG(basic_globals_id, php_basic_globals *, v)
243 PHPAPI extern int basic_globals_id;
244 #else
245 #define BG(v) (basic_globals.v)
246 PHPAPI extern php_basic_globals basic_globals;
247 #endif
248 
249 #if HAVE_PUTENV
250 typedef struct {
251 	char *putenv_string;
252 	char *previous_value;
253 	char *key;
254 	size_t key_len;
255 } putenv_entry;
256 #endif
257 
258 PHPAPI double php_get_nan(void);
259 PHPAPI double php_get_inf(void);
260 
261 typedef struct _php_shutdown_function_entry {
262 	zval *arguments;
263 	int arg_count;
264 } php_shutdown_function_entry;
265 
266 PHPAPI extern zend_bool register_user_shutdown_function(char *function_name, size_t function_len, php_shutdown_function_entry *shutdown_function_entry);
267 PHPAPI extern zend_bool remove_user_shutdown_function(char *function_name, size_t function_len);
268 PHPAPI extern zend_bool append_user_shutdown_function(php_shutdown_function_entry shutdown_function_entry);
269 
270 PHPAPI void php_call_shutdown_functions(void);
271 PHPAPI void php_free_shutdown_functions(void);
272 
273 
274 #endif /* BASIC_FUNCTIONS_H */
275