version 1.1.1.2, 2012/05/29 12:34:35
|
version 1.1.1.5, 2014/06/15 20:04:01
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2014 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 736 PHPAPI size_t _php_stream_read(php_stream *stream, cha
|
Line 736 PHPAPI size_t _php_stream_read(php_stream *stream, cha
|
|
|
if (!stream->readfilters.head && (stream->flags & PHP_STREAM_FLAG_NO_BUFFER || stream->chunk_size == 1)) { |
if (!stream->readfilters.head && (stream->flags & PHP_STREAM_FLAG_NO_BUFFER || stream->chunk_size == 1)) { |
toread = stream->ops->read(stream, buf, size TSRMLS_CC); |
toread = stream->ops->read(stream, buf, size TSRMLS_CC); |
|
if (toread == (size_t) -1) { |
|
/* e.g. underlying read(2) returned -1 */ |
|
break; |
|
} |
} else { |
} else { |
php_stream_fill_read_buffer(stream, size TSRMLS_CC); |
php_stream_fill_read_buffer(stream, size TSRMLS_CC); |
|
|
Line 1028 PHPAPI char *php_stream_get_record(php_stream *stream,
|
Line 1032 PHPAPI char *php_stream_get_record(php_stream *stream,
|
char *ret_buf, /* returned buffer */ |
char *ret_buf, /* returned buffer */ |
*found_delim = NULL; |
*found_delim = NULL; |
size_t buffered_len, |
size_t buffered_len, |
tent_ret_len; /* tentative returned length*/ | tent_ret_len; /* tentative returned length */ |
int has_delim = delim_len > 0 && delim[0] != '\0'; | int has_delim = delim_len > 0; |
|
|
if (maxlen == 0) { |
if (maxlen == 0) { |
return NULL; |
return NULL; |
Line 1060 PHPAPI char *php_stream_get_record(php_stream *stream,
|
Line 1064 PHPAPI char *php_stream_get_record(php_stream *stream,
|
if (has_delim) { |
if (has_delim) { |
/* search for delimiter, but skip buffered_len (the number of bytes |
/* search for delimiter, but skip buffered_len (the number of bytes |
* buffered before this loop iteration), as they have already been |
* buffered before this loop iteration), as they have already been |
* searched for the delimiter */ | * searched for the delimiter. |
| * The left part of the delimiter may still remain in the buffer, |
| * so subtract up to <delim_len - 1> from buffered_len, which is |
| * the ammount of data we skip on this search as an optimization |
| */ |
found_delim = _php_stream_search_delim( |
found_delim = _php_stream_search_delim( |
stream, maxlen, buffered_len, delim, delim_len TSRMLS_CC); | stream, maxlen, |
| buffered_len >= (delim_len - 1) |
| ? buffered_len - (delim_len - 1) |
| : 0, |
| delim, delim_len TSRMLS_CC); |
if (found_delim) { |
if (found_delim) { |
break; |
break; |
} |
} |
Line 1393 PHPAPI size_t _php_stream_passthru(php_stream * stream
|
Line 1405 PHPAPI size_t _php_stream_passthru(php_stream * stream
|
p = php_stream_mmap_range(stream, php_stream_tell(stream), PHP_STREAM_MMAP_ALL, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); |
p = php_stream_mmap_range(stream, php_stream_tell(stream), PHP_STREAM_MMAP_ALL, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); |
|
|
if (p) { |
if (p) { |
PHPWRITE(p, mapped); | do { |
| /* output functions return int, so pass in int max */ |
| if (0 < (b = PHPWRITE(p, MIN(mapped - bcount, INT_MAX)))) { |
| bcount += b; |
| } |
| } while (b > 0 && mapped > bcount); |
|
|
php_stream_mmap_unmap_ex(stream, mapped); |
php_stream_mmap_unmap_ex(stream, mapped); |
|
|
return mapped; | return bcount; |
} |
} |
} |
} |
|
|
Line 1437 PHPAPI size_t _php_stream_copy_to_mem(php_stream *src,
|
Line 1454 PHPAPI size_t _php_stream_copy_to_mem(php_stream *src,
|
len += ret; |
len += ret; |
ptr += ret; |
ptr += ret; |
} |
} |
*ptr = '\0'; | if (len) { |
| *ptr = '\0'; |
| } else { |
| pefree(*buf, persistent); |
| *buf = NULL; |
| } |
return len; |
return len; |
} |
} |
|
|
Line 1481 PHPAPI int _php_stream_copy_to_stream_ex(php_stream *s
|
Line 1503 PHPAPI int _php_stream_copy_to_stream_ex(php_stream *s
|
char buf[CHUNK_SIZE]; |
char buf[CHUNK_SIZE]; |
size_t readchunk; |
size_t readchunk; |
size_t haveread = 0; |
size_t haveread = 0; |
size_t didread; | size_t didread, didwrite, towrite; |
size_t dummy; |
size_t dummy; |
php_stream_statbuf ssbuf; |
php_stream_statbuf ssbuf; |
|
|
Line 1516 PHPAPI int _php_stream_copy_to_stream_ex(php_stream *s
|
Line 1538 PHPAPI int _php_stream_copy_to_stream_ex(php_stream *s
|
p = php_stream_mmap_range(src, php_stream_tell(src), maxlen, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); |
p = php_stream_mmap_range(src, php_stream_tell(src), maxlen, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); |
|
|
if (p) { |
if (p) { |
mapped = php_stream_write(dest, p, mapped); | didwrite = php_stream_write(dest, p, mapped); |
|
|
php_stream_mmap_unmap_ex(src, mapped); |
php_stream_mmap_unmap_ex(src, mapped); |
|
|
*len = mapped; | *len = didwrite; |
|
|
/* we've got at least 1 byte to read. | /* we've got at least 1 byte to read |
* less than 1 is an error */ | * less than 1 is an error |
| * AND read bytes match written */ |
if (mapped > 0) { | if (mapped > 0 && mapped == didwrite) { |
return SUCCESS; |
return SUCCESS; |
} |
} |
return FAILURE; |
return FAILURE; |
Line 1543 PHPAPI int _php_stream_copy_to_stream_ex(php_stream *s
|
Line 1565 PHPAPI int _php_stream_copy_to_stream_ex(php_stream *s
|
|
|
if (didread) { |
if (didread) { |
/* extra paranoid */ |
/* extra paranoid */ |
size_t didwrite, towrite; |
|
char *writeptr; |
char *writeptr; |
|
|
towrite = didread; |
towrite = didread; |
Line 1908 PHPAPI int _php_stream_stat_path(char *path, int flags
|
Line 1929 PHPAPI int _php_stream_stat_path(char *path, int flags
|
char *path_to_open = path; |
char *path_to_open = path; |
int ret; |
int ret; |
|
|
/* Try to hit the cache first */ | if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) { |
if (flags & PHP_STREAM_URL_STAT_LINK) { | /* Try to hit the cache first */ |
if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) { | if (flags & PHP_STREAM_URL_STAT_LINK) { |
memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf)); | if (BG(CurrentLStatFile) && strcmp(path, BG(CurrentLStatFile)) == 0) { |
return 0; | memcpy(ssb, &BG(lssb), sizeof(php_stream_statbuf)); |
| return 0; |
| } |
| } else { |
| if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) { |
| memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf)); |
| return 0; |
| } |
} |
} |
} else { |
|
if (BG(CurrentStatFile) && strcmp(path, BG(CurrentStatFile)) == 0) { |
|
memcpy(ssb, &BG(ssb), sizeof(php_stream_statbuf)); |
|
return 0; |
|
} |
|
} |
} |
|
|
wrapper = php_stream_locate_url_wrapper(path, &path_to_open, 0 TSRMLS_CC); |
wrapper = php_stream_locate_url_wrapper(path, &path_to_open, 0 TSRMLS_CC); |
if (wrapper && wrapper->wops->url_stat) { |
if (wrapper && wrapper->wops->url_stat) { |
ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC); |
ret = wrapper->wops->url_stat(wrapper, path_to_open, flags, ssb, context TSRMLS_CC); |
if (ret == 0) { |
if (ret == 0) { |
/* Drop into cache */ | if (!(flags & PHP_STREAM_URL_STAT_NOCACHE)) { |
if (flags & PHP_STREAM_URL_STAT_LINK) { | /* Drop into cache */ |
if (BG(CurrentLStatFile)) { | if (flags & PHP_STREAM_URL_STAT_LINK) { |
efree(BG(CurrentLStatFile)); | if (BG(CurrentLStatFile)) { |
| efree(BG(CurrentLStatFile)); |
| } |
| BG(CurrentLStatFile) = estrdup(path); |
| memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf)); |
| } else { |
| if (BG(CurrentStatFile)) { |
| efree(BG(CurrentStatFile)); |
| } |
| BG(CurrentStatFile) = estrdup(path); |
| memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf)); |
} |
} |
BG(CurrentLStatFile) = estrdup(path); |
|
memcpy(&BG(lssb), ssb, sizeof(php_stream_statbuf)); |
|
} else { |
|
if (BG(CurrentStatFile)) { |
|
efree(BG(CurrentStatFile)); |
|
} |
|
BG(CurrentStatFile) = estrdup(path); |
|
memcpy(&BG(ssb), ssb, sizeof(php_stream_statbuf)); |
|
} |
} |
} |
} |
return ret; |
return ret; |
Line 2327 PHPAPI int _php_stream_scandir(char *dirname, char **n
|
Line 2352 PHPAPI int _php_stream_scandir(char *dirname, char **n
|
php_stream *stream; |
php_stream *stream; |
php_stream_dirent sdp; |
php_stream_dirent sdp; |
char **vector = NULL; |
char **vector = NULL; |
int vector_size = 0; | unsigned int vector_size = 0; |
int nfiles = 0; | unsigned int nfiles = 0; |
|
|
if (!namelist) { |
if (!namelist) { |
return FAILURE; |
return FAILURE; |
Line 2344 PHPAPI int _php_stream_scandir(char *dirname, char **n
|
Line 2369 PHPAPI int _php_stream_scandir(char *dirname, char **n
|
if (vector_size == 0) { |
if (vector_size == 0) { |
vector_size = 10; |
vector_size = 10; |
} else { |
} else { |
|
if(vector_size*2 < vector_size) { |
|
/* overflow */ |
|
php_stream_closedir(stream); |
|
efree(vector); |
|
return FAILURE; |
|
} |
vector_size *= 2; |
vector_size *= 2; |
} |
} |
vector = (char **) erealloc(vector, vector_size * sizeof(char *)); | vector = (char **) safe_erealloc(vector, vector_size, sizeof(char *), 0); |
} |
} |
|
|
vector[nfiles] = estrdup(sdp.d_name); |
vector[nfiles] = estrdup(sdp.d_name); |
|
|
nfiles++; |
nfiles++; |
|
if(vector_size < 10 || nfiles == 0) { |
|
/* overflow */ |
|
php_stream_closedir(stream); |
|
efree(vector); |
|
return FAILURE; |
|
} |
} |
} |
php_stream_closedir(stream); |
php_stream_closedir(stream); |
|
|
*namelist = vector; |
*namelist = vector; |
|
|
if (compare) { | if (nfiles > 0 && compare) { |
qsort(*namelist, nfiles, sizeof(char *), (int(*)(const void *, const void *))compare); |
qsort(*namelist, nfiles, sizeof(char *), (int(*)(const void *, const void *))compare); |
} |
} |
return nfiles; |
return nfiles; |