xref: /PHP-7.2/ext/standard/basic_functions.h (revision 7a7ec01a)
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@zend.com>                                |
16    |          Zeev Suraski <zeev@zend.com>                                |
17    +----------------------------------------------------------------------+
18 */
19 
20 /* $Id$ */
21 
22 #ifndef BASIC_FUNCTIONS_H
23 #define BASIC_FUNCTIONS_H
24 
25 #include <sys/stat.h>
26 
27 #ifdef HAVE_WCHAR_H
28 #include <wchar.h>
29 #endif
30 
31 #include "php_filestat.h"
32 
33 #include "zend_highlight.h"
34 
35 #include "url_scanner_ex.h"
36 
37 #if defined(_WIN32) && defined(__clang__)
38 #include <intrin.h>
39 #endif
40 
41 extern zend_module_entry basic_functions_module;
42 #define basic_functions_module_ptr &basic_functions_module
43 
44 PHP_MINIT_FUNCTION(basic);
45 PHP_MSHUTDOWN_FUNCTION(basic);
46 PHP_RINIT_FUNCTION(basic);
47 PHP_RSHUTDOWN_FUNCTION(basic);
48 PHP_MINFO_FUNCTION(basic);
49 
50 PHP_FUNCTION(constant);
51 PHP_FUNCTION(sleep);
52 PHP_FUNCTION(usleep);
53 #if HAVE_NANOSLEEP
54 PHP_FUNCTION(time_nanosleep);
55 PHP_FUNCTION(time_sleep_until);
56 #endif
57 PHP_FUNCTION(flush);
58 #ifdef HAVE_INET_NTOP
59 PHP_NAMED_FUNCTION(php_inet_ntop);
60 #endif
61 #ifdef HAVE_INET_PTON
62 PHP_NAMED_FUNCTION(php_inet_pton);
63 #endif
64 PHP_FUNCTION(ip2long);
65 PHP_FUNCTION(long2ip);
66 
67 /* system functions */
68 PHP_FUNCTION(getenv);
69 PHP_FUNCTION(putenv);
70 
71 PHP_FUNCTION(getopt);
72 
73 PHP_FUNCTION(get_current_user);
74 PHP_FUNCTION(set_time_limit);
75 
76 PHP_FUNCTION(header_register_callback);
77 
78 PHP_FUNCTION(get_cfg_var);
79 PHP_FUNCTION(get_magic_quotes_runtime);
80 PHP_FUNCTION(get_magic_quotes_gpc);
81 
82 PHP_FUNCTION(error_log);
83 PHP_FUNCTION(error_get_last);
84 PHP_FUNCTION(error_clear_last);
85 
86 PHP_FUNCTION(call_user_func);
87 PHP_FUNCTION(call_user_func_array);
88 PHP_FUNCTION(forward_static_call);
89 PHP_FUNCTION(forward_static_call_array);
90 
91 PHP_FUNCTION(register_shutdown_function);
92 PHP_FUNCTION(highlight_file);
93 PHP_FUNCTION(highlight_string);
94 PHP_FUNCTION(php_strip_whitespace);
95 ZEND_API void php_get_highlight_struct(zend_syntax_highlighter_ini *syntax_highlighter_ini);
96 
97 PHP_FUNCTION(ini_get);
98 PHP_FUNCTION(ini_get_all);
99 PHP_FUNCTION(ini_set);
100 PHP_FUNCTION(ini_restore);
101 PHP_FUNCTION(get_include_path);
102 PHP_FUNCTION(set_include_path);
103 PHP_FUNCTION(restore_include_path);
104 
105 PHP_FUNCTION(print_r);
106 PHP_FUNCTION(fprintf);
107 PHP_FUNCTION(vfprintf);
108 
109 PHP_FUNCTION(connection_aborted);
110 PHP_FUNCTION(connection_status);
111 PHP_FUNCTION(ignore_user_abort);
112 
113 PHP_FUNCTION(getservbyname);
114 PHP_FUNCTION(getservbyport);
115 PHP_FUNCTION(getprotobyname);
116 PHP_FUNCTION(getprotobynumber);
117 
118 PHP_NAMED_FUNCTION(php_if_crc32);
119 
120 PHP_FUNCTION(register_tick_function);
121 PHP_FUNCTION(unregister_tick_function);
122 #ifdef HAVE_GETLOADAVG
123 PHP_FUNCTION(sys_getloadavg);
124 #endif
125 
126 PHP_FUNCTION(is_uploaded_file);
127 PHP_FUNCTION(move_uploaded_file);
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, zval *prefix, 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 	int 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