version 1.1.1.2, 2012/05/29 12:34:35
|
version 1.1.1.3, 2013/07/22 01:32:11
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2013 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 1028 PHPAPI char *php_stream_get_record(php_stream *stream,
|
Line 1028 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 1060 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 1437 PHPAPI size_t _php_stream_copy_to_mem(php_stream *src,
|
Line 1445 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 1494 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 1529 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 1556 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 2327 PHPAPI int _php_stream_scandir(char *dirname, char **n
|
Line 2339 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 2356 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 */ |
|
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 */ |
|
efree(vector); |
|
return FAILURE; |
|
} |
} |
} |
php_stream_closedir(stream); |
php_stream_closedir(stream); |
|
|