42# define O_RDONLY _O_RDONLY
48# ifdef HAVE_SYS_PARAM_H
49# include <sys/param.h>
51# ifdef HAVE_SYS_SELECT_H
52# include <sys/select.h>
54# include <sys/socket.h>
55# include <netinet/in.h>
57# ifdef HAVE_ARPA_INET_H
58# include <arpa/inet.h>
67# include "win32/pwd.h"
94#if defined(HAVE_FNMATCH) && !defined(PHP_WIN32)
105#define PHP_STREAM_FROM_ZVAL(stream, arg) \
106 ZEND_ASSERT(Z_TYPE_P(arg) == IS_RESOURCE); \
107 php_stream_from_res(stream, Z_RES_P(arg));
112static int le_stream_context =
FAILURE;
116 return le_stream_context;
139#if defined(HAVE_GETHOSTBYNAME_R)
140 if (file_globals_p->tmp_host_buf) {
141 free(file_globals_p->tmp_host_buf);
146static PHP_INI_MH(OnUpdateAutoDetectLineEndings)
151 return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
166 ts_allocate_id(&file_globals_id,
sizeof(
php_file_globals), (ts_allocate_ctor) file_globals_ctor, (ts_allocate_dtor) file_globals_dtor);
173 register_file_symbols(module_number);
195 if (act < 1 || act > 3) {
235#define PHP_META_UNSAFE ".\\+*?[^]$() "
243 int in_tag = 0, done = 0;
244 int looking_for_val = 0, have_name = 0, have_content = 0;
245 int saw_name = 0, saw_content = 0;
251 memset(&md, 0,
sizeof(md));
275 }
else if (tok_last ==
TOK_SLASH && in_tag) {
280 }
else if (tok_last ==
TOK_EQUAL && looking_for_val) {
286 while (temp && *temp) {
294 }
else if (saw_content) {
320 while (temp && *temp) {
328 }
else if (saw_content) {
336 if (looking_for_val) {
338 have_name = saw_name = 0;
339 have_content = saw_content = 0;
354 }
else if (have_content) {
361 in_tag = looking_for_val = 0;
362 have_name = saw_name = 0;
363 have_content = saw_content = 0;
450 ssize_t numbytes = 0;
476 if (
strncasecmp(filename,
"file://",
sizeof(
"file://") - 1)) {
486 if (stream ==
NULL) {
496 if (
mode[0] ==
'c') {
533 ssize_t bytes_written;
542 if (bytes_written !=
ZSTR_LEN(str)) {
544 zend_tmp_string_release(t);
549 zend_tmp_string_release(t);
564 zval_ptr_dtor_str(&
out);
583#define PHP_FILE_BUF_SIZE 80
592 char eol_marker =
'\n';
595 bool include_new_line;
596 bool skip_blank_lines;
644 if (include_new_line) {
650 }
while ((
p = memchr(
p, eol_marker, (e-
p))));
654 if (
p !=
ZSTR_VAL(target_buf) && eol_marker ==
'\n' && *(
p - 1) ==
'\r') {
657 if (skip_blank_lines && !(
p-
s-windows_eol)) {
663 }
while ((
p = memchr(
p, eol_marker, (e-
p))));
674 zend_string_free(target_buf);
684 size_t dir_len, prefix_len;
729 char *filename, *
mode;
748 if (stream ==
NULL) {
784 char *command, *
mode;
798 char *z = memchr(posix_mode,
'b',
mode_len);
808 (
mode_len == 1 && (*posix_mode !=
'r' && *posix_mode !=
'w')) ||
809 (
mode_len == 2 && (memcmp(posix_mode,
"rb", 2) && memcmp(posix_mode,
"wb", 2)))
825 if (stream ==
NULL) {
880 bool len_is_null = 1;
909 str = zend_string_alloc(
len, 0);
911 zend_string_efree(str);
916 if (line_len < (
size_t)
len / 2) {
917 str = zend_string_truncate(str, line_len, 0);
1009 num_bytes = inputlen;
1010 }
else if (
maxlen <= 0) {
1013 num_bytes =
MIN((
size_t)
maxlen, inputlen);
1191 bool mask_is_null = 1;
1199 oldumask =
umask(077);
1236 char *old_name, *new_name;
1237 size_t old_name_len, new_name_len;
1251 if (!wrapper || !wrapper->
wops) {
1291 if (!wrapper || !wrapper->
wops) {
1372 zval stat_dev, stat_ino, stat_mode, stat_nlink, stat_uid, stat_gid, stat_rdev,
1373 stat_size, stat_atime, stat_mtime, stat_ctime, stat_blksize, stat_blocks;
1374 char *stat_sb_names[13] = {
1375 "dev",
"ino",
"mode",
"nlink",
"uid",
"gid",
"rdev",
1376 "size",
"atime",
"mtime",
"ctime",
"blksize",
"blocks"
1391#ifdef HAVE_STRUCT_STAT_ST_RDEV
1400#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1405#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1460 char *source, *target;
1461 size_t source_len, target_len;
1533 if (!src_s.
sb.st_ino || !dest_s.
sb.st_ino) {
1536 if (src_s.
sb.st_ino == dest_s.
sb.st_ino && src_s.
sb.st_dev == dest_s.
sb.st_dev) {
1618static const char *php_fgetcsv_lookup_trailing_spaces(
const char *
ptr,
size_t len)
1621 unsigned char last_chars[2] = { 0, 0 };
1635 last_chars[0] = last_chars[1];
1636 last_chars[1] = *
ptr;
1643 switch (last_chars[1]) {
1645 if (last_chars[0] ==
'\r') {
1658 if (escape_str !=
NULL) {
1667 return (
unsigned char)
ZSTR_VAL(escape_str)[0];
1674 return (
unsigned char)
'\\';
1678#define FPUTCSV_FLD_CHK(c) memchr(ZSTR_VAL(field_str), c, ZSTR_LEN(field_str))
1683 char delimiter =
',';
1684 char enclosure =
'"';
1688 char *delimiter_str =
NULL, *enclosure_str =
NULL;
1690 size_t delimiter_str_len = 0, enclosure_str_len = 0;
1703 if (delimiter_str !=
NULL) {
1705 if (delimiter_str_len != 1) {
1711 delimiter = *delimiter_str;
1714 if (enclosure_str !=
NULL) {
1715 if (enclosure_str_len != 1) {
1720 enclosure = *enclosure_str;
1730 ret =
php_fputcsv(stream, fields, delimiter, enclosure, escape_char, eol_str);
1741 uint32_t
count, i = 0;
1750 zend_string *field_str = zval_get_tmp_string(field_tmp, &tmp_field_str);
1765 smart_str_appendc(&csvline, enclosure);
1769 }
else if (!escaped && *
ch == enclosure) {
1770 smart_str_appendc(&csvline, enclosure);
1774 smart_str_appendc(&csvline, *
ch);
1777 smart_str_appendc(&csvline, enclosure);
1779 smart_str_append(&csvline, field_str);
1783 smart_str_appendl(&csvline, &delimiter, 1);
1785 zend_tmp_string_release(tmp_field_str);
1789 smart_str_append(&csvline, eol_str);
1791 smart_str_appendc(&csvline,
'\n');
1793 smart_str_0(&csvline);
1797 smart_str_free(&csvline);
1806 char delimiter =
',';
1807 char enclosure =
'"';
1815 bool len_is_null = 1;
1816 char *delimiter_str =
NULL;
1817 size_t delimiter_str_len = 0;
1818 char *enclosure_str =
NULL;
1819 size_t enclosure_str_len = 0;
1831 if (delimiter_str !=
NULL) {
1833 if (delimiter_str_len != 1) {
1839 delimiter = delimiter_str[0];
1842 if (enclosure_str !=
NULL) {
1843 if (enclosure_str_len != 1) {
1849 enclosure = enclosure_str[0];
1857 if (len_is_null ||
len == 0) {
1879 if (values ==
NULL) {
1897 char *temp, *bptr, *line_end, *limit;
1898 size_t temp_len, line_end_len;
1900 bool first_field =
true;
1912 line_end = limit = (
char *)php_fgetcsv_lookup_trailing_spaces(
buf, buf_len);
1913 line_end_len = buf_len - (size_t)(limit -
buf);
1917 temp =
emalloc(temp_len + line_end_len + 1);
1925 char *comp_end, *hunk_begin;
1928 inc_len = (bptr < limit ? (*bptr ==
'\0' ? 1 :
php_mblen(bptr, limit - bptr)): 0);
1931 while ((*tmp != delimiter) && isspace((
int)*(
unsigned char *)tmp)) {
1934 if (*tmp == enclosure && tmp < limit) {
1939 if (first_field && bptr == line_end) {
1944 first_field =
false;
1946 if (inc_len != 0 && *bptr == enclosure) {
1958 tptr = zend_mempcpy(tptr, hunk_begin, (bptr - hunk_begin - 1));
1963 tptr = zend_mempcpy(tptr, hunk_begin, (bptr - hunk_begin));
1968 if (hunk_begin != line_end) {
1969 tptr = zend_mempcpy(tptr, hunk_begin, (bptr - hunk_begin));
1974 tptr = zend_mempcpy(tptr, line_end, line_end_len);
1977 if (stream ==
NULL) {
1982 if (hunk_begin == bptr) {
2000 if (hunk_begin == bptr) {
2008 temp_len += new_len;
2009 char *new_temp =
erealloc(temp, temp_len);
2010 tptr = new_temp + (size_t)(tptr - temp);
2015 bptr =
buf = new_buf;
2018 line_end = limit = (
char *)php_fgetcsv_lookup_trailing_spaces(
buf, buf_len);
2019 line_end_len = buf_len - (size_t)(limit -
buf);
2039 if (*bptr != enclosure) {
2041 tptr = zend_mempcpy(tptr, hunk_begin, bptr - hunk_begin - 1);
2045 tptr = zend_mempcpy(tptr, hunk_begin, bptr - hunk_begin);
2051 if (*bptr == enclosure) {
2065 tptr = zend_mempcpy(tptr, hunk_begin, bptr - hunk_begin - 1);
2070 tptr = zend_mempcpy(tptr, hunk_begin, bptr - hunk_begin);
2080 inc_len = (bptr < limit ? (*bptr ==
'\0' ? 1 :
php_mblen(bptr, limit - bptr)): 0);
2096 if (*bptr == delimiter) {
2104 inc_len = (bptr < limit ? (*bptr ==
'\0' ? 1 :
php_mblen(bptr, limit - bptr)): 0);
2108 tptr = zend_mempcpy(tptr, hunk_begin, bptr - hunk_begin);
2126 if (*bptr == delimiter) {
2134 inc_len = (bptr < limit ? (*bptr ==
'\0' ? 1 :
php_mblen(bptr, limit - bptr)): 0);
2137 tptr = zend_mempcpy(tptr, hunk_begin, bptr - hunk_begin);
2139 comp_end = (
char *)php_fgetcsv_lookup_trailing_spaces(temp, tptr - temp);
2140 if (*bptr == delimiter) {
2151 }
while (inc_len > 0);
2191#define PHP_META_HTML401_CHARS "-_.:"
2197 int ch = 0, compliment;
2240 if (
ch ==
'<' ||
ch ==
'>') {
2277 if (!isalpha(
ch) &&
ch !=
'-') {
2301 char *pattern, *filename;
readfile(string $filename, bool $use_include_path=false, $context=null)
unlink(string $filename, $context=null)
ftruncate($stream, int $size)
rename(string $from, string $to, $context=null)
file_get_contents(string $filename, bool $use_include_path=false, $context=null, int $offset=0, ?int $length=null)
fputcsv($stream, array $fields, string $separator=",", string $enclosure="\"", string $escape="\\", string $eol="\n")
file(string $filename, int $flags=0, $context=null)
fgetcsv($stream, ?int $length=null, string $separator=",", string $enclosure="\"", string $escape="\\")
tempnam(string $directory, string $prefix)
copy(string $from, string $to, $context=null)
fseek($stream, int $offset, int $whence=SEEK_SET)
file_put_contents(string $filename, mixed $data, int $flags=0, $context=null)
fwrite($stream, string $data, ?int $length=null)
rmdir(string $directory, $context=null)
dir(string $directory, $context=null)
get_meta_tags(string $filename, bool $use_include_path=false)
popen(string $command, string $mode)
fnmatch(string $pattern, string $filename, int $flags=0)
fopen(string $filename, string $mode, bool $use_include_path=false, $context=null)
count(Countable|array $value, int $mode=COUNT_NORMAL)
fscanf($stream, string $format, mixed &... $vars)
fread($stream, int $length)
flock($stream, int $operation, &$would_block=null)
mkdir(string $directory, int $permissions=0777, bool $recursive=false, $context=null)
fgets($stream, ?int $length=null)
strchr(string $haystack, string $needle, bool $before_needle=false)
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
PHPAPI void php_fstat(php_stream *stream, zval *return_value)
PHPAPI HashTable * php_bc_fgetcsv_empty_line(void)
#define PHP_META_HTML401_CHARS
#define PHP_STREAM_FROM_ZVAL(stream, arg)
php_file_globals file_globals
PHPAPI zend_result php_copy_file(const char *src, const char *dest)
PHPAPI int php_le_stream_context(void)
PHPAPI HashTable * php_fgetcsv(php_stream *stream, char delimiter, char enclosure, int escape_char, size_t buf_len, char *buf)
PHPAPI int php_csv_handle_escape_argument(const zend_string *escape_str, uint32_t arg_num)
PHPAPI ssize_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, char enclosure, int escape_char, zend_string *eol_str)
PHPAPI zend_result php_copy_file_ex(const char *src, const char *dest, int src_flags)
#define FPUTCSV_FLD_CHK(c)
PHPAPI void php_flock_common(php_stream *stream, zend_long operation, uint32_t operation_arg_num, zval *wouldblock, zval *return_value)
PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_flags, php_stream_context *ctx)
php_meta_tags_token php_next_meta_token(php_meta_tags_data *md)
PHPAPI int php_check_open_basedir(const char *path)
PHPAPI char * expand_filepath(const char *filepath, char *real_path)
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
PHPAPI ZEND_COLD void php_error_docref2(const char *docref, const char *param1, const char *param2, int type, const char *format,...)
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
unsigned const char * end
#define STD_PHP_INI_ENTRY
#define STD_PHP_INI_BOOLEAN
#define PHP_SOCK_CHUNK_SIZE
PHPAPI int php_open_temporary_fd_ex(const char *dir, const char *pfx, zend_string **opened_path_p, uint32_t flags)
PHPAPI const char * php_get_temporary_directory(void)
#define PHP_TMP_FILE_OPEN_BASEDIR_CHECK_ALWAYS
#define php_stream_context_from_zval(zcontext, nocontext)
PHPAPI void php_stream_context_free(php_stream_context *context)
#define php_stream_fopen_tmpfile()
PHPAPI php_stream_wrapper php_plain_files_wrapper
#define php_stream_fopen_from_pipe(file, mode)
#define php_stream_truncate_supported(stream)
#define PHP_STREAM_IS_STDIO
struct _php_stream php_stream
struct _php_stream_context php_stream_context
PHPAPI const char * php_stream_locate_eol(php_stream *stream, zend_string *buf)
#define php_stream_stat_path_ex(path, flags, ssb, context)
#define php_stream_from_zval(xstr, pzval)
#define PHP_STREAM_URL_STAT_IGNORE_OPEN_BASEDIR
#define PHP_STREAM_FREE_CLOSE_PERSISTENT
#define php_stream_rewind(stream)
#define php_stream_sync(stream, d)
#define php_stream_get_line(stream, buf, maxlen, retlen)
#define php_stream_mkdir(path, mode, options, context)
#define PHP_STREAM_COPY_ALL
#define php_stream_getc(stream)
#define PHP_STREAM_BUFFER_NONE
#define php_stream_seek(stream, offset, whence)
#define php_stream_flush(stream)
#define PHP_STREAM_MKDIR_RECURSIVE
#define php_stream_supports_lock(stream)
PHPAPI zend_string * php_stream_read_to_str(php_stream *stream, size_t len)
#define php_stream_to_zval(stream, zval)
#define php_stream_truncate_set_size(stream, size)
#define php_stream_eof(stream)
#define php_stream_open_wrapper_ex(path, mode, options, opened, context)
#define php_stream_free(stream, close_options)
#define php_stream_close(stream)
#define PHP_STREAM_FREE_CLOSE
#define php_stream_is(stream, anops)
#define php_stream_tell(stream)
#define STREAM_DISABLE_OPEN_BASEDIR
#define php_stream_copy_to_mem(src, maxlen, persistent)
#define php_stream_sync_supported(stream)
#define PHP_STREAM_OPTION_READ_BUFFER
#define php_stream_lock(stream, mode)
#define php_stream_open_wrapper(path, mode, options, opened)
#define PHP_STREAM_FREE_KEEP_RSRC
PHPAPI int php_file_le_pstream(void)
#define php_stream_stat(stream, ssb)
struct _php_stream_wrapper php_stream_wrapper
#define php_stream_rmdir(path, options, context)
#define PHP_STREAM_FLAG_NO_FCLOSE
#define PHP_STREAM_FLAG_EOL_MAC
#define php_stream_copy_to_stream_ex(src, dest, maxlen, len)
PHPAPI php_stream_wrapper * php_stream_locate_url_wrapper(const char *path, const char **path_for_open, int options)
#define php_stream_set_option(stream, option, value, ptrvalue)
#define PHP_STREAM_URL_STAT_QUIET
#define php_stream_passthru(stream)
struct _php_stream_statbuf php_stream_statbuf
#define php_stream_write(stream, buf, count)
PHPAPI int php_file_le_stream(void)
PHPAPI zend_string * php_basename(const char *s, size_t len, const char *suffix, size_t sufflen)
#define php_mblen(ptr, len)
PHPAPI int php_sscanf_internal(char *string, char *format, int argCount, zval *args, int varStart, zval *return_value)
#define SCAN_ERROR_WRONG_PARAM_COUNT
#define PHP_FILE_USE_INCLUDE_PATH
#define PHP_FILE_NO_DEFAULT_CONTEXT
#define PHP_CSV_NO_ESCAPE
#define PHP_FILE_IGNORE_NEW_LINES
#define PHP_FILE_SKIP_EMPTY_LINES
#define PHP_CSV_ESCAPE_ERROR
enum _php_meta_tags_token php_meta_tags_token
struct _php_meta_tags_data php_meta_tags_data
int(* rename)(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context)
int(* unlink)(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context)
const php_stream_wrapper_ops * wops
ZEND_API ZEND_COLD void zend_error(int type, const char *format,...)
ZEND_API void add_index_stringl(zval *arg, zend_ulong index, const char *str, size_t length)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
#define ZEND_PARSE_PARAMETERS_END()
#define Z_PARAM_RESOURCE(dest)
#define Z_PARAM_STR_OR_NULL(dest)
#define ZEND_PARSE_PARAMETERS_NONE()
#define Z_PARAM_STRING(dest, dest_len)
#define Z_PARAM_STR(dest)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define RETVAL_EMPTY_STRING()
#define ZEND_TRY_ASSIGN_REF_LONG(zv, lval)
#define Z_PARAM_LONG(dest)
#define Z_PARAM_VARIADIC(spec, dest, dest_num)
#define RETURN_NEW_STR(s)
#define Z_PARAM_LONG_OR_NULL(dest, is_null)
#define Z_PARAM_BOOL(dest)
#define Z_PARAM_PATH(dest, dest_len)
#define Z_PARAM_ARRAY(dest)
#define Z_PARAM_RESOURCE_OR_NULL(dest)
#define Z_PARAM_ZVAL(dest)
#define ZVAL_STRINGL(z, s, l)
#define WRONG_PARAM_COUNT
#define RETVAL_STRINGL(s, l)
#define estrndup(s, length)
#define erealloc(ptr, size)
strcmp(string $string1, string $string2)
zend_string_release_ex(func->internal_function.function_name, 0)
#define strncasecmp(s1, s2, n)
#define strcasecmp(s1, s2)
ZEND_API zval *ZEND_FASTCALL zend_hash_next_index_insert(HashTable *ht, zval *pData)
ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_add_new(HashTable *ht, const char *str, size_t len, zval *pData)
#define zend_new_array(size)
#define ZEND_HASH_FOREACH_END()
#define ZEND_HASH_FOREACH_VAL(ht, _val)
ZEND_API bool zend_ini_parse_bool(zend_string *str)
#define REGISTER_INI_ENTRIES()
ZEND_API void * zend_fetch_resource2(zend_resource *res, const char *resource_type_name, int resource_type1, int resource_type2)
ZEND_API void ZEND_FASTCALL zend_list_close(zend_resource *res)
ZEND_API int zend_register_list_destructors_ex(rsrc_dtor_func_t ld, rsrc_dtor_func_t pld, const char *type_name, int module_number)
#define ZEND_RSRC_DTOR_FUNC(name)
struct _zend_string zend_string
ZEND_API zend_result zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, int type)
ZEND_API void ZEND_FASTCALL zend_str_tolower(char *str, size_t length)
#define convert_to_string(op)
#define UNEXPECTED(condition)
#define Z_STRVAL_P(zval_p)
#define Z_ARRVAL_P(zval_p)
struct _zend_array HashTable
#define Z_OBJ_HT_P(zval_p)
#define Z_STRLEN_P(zval_p)
ZEND_RESULT_CODE zend_result
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
#define VCWD_POPEN(command, type)
#define VCWD_ACCESS(pathname, mode)
#define VCWD_REALPATH(path, real_path)