diff options
Diffstat (limited to 'main/streams/plain_wrapper.c')
-rw-r--r-- | main/streams/plain_wrapper.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 87312b9ef8..de84c01a11 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -53,6 +53,12 @@ extern int php_get_uid_by_name(const char *name, uid_t *uid TSRMLS_DC); extern int php_get_gid_by_name(const char *name, gid_t *gid TSRMLS_DC); #endif +#if defined(PHP_WIN32) +# define PLAIN_WRAP_BUF_SIZE(st) (((st) > UINT_MAX) ? UINT_MAX : (unsigned int)(st)) +#else +# define PLAIN_WRAP_BUF_SIZE(st) (st) +#endif + /* parse standard "fopen" modes into open() flags */ PHPAPI int php_stream_parse_fopen_modes(const char *mode, int *open_flags) { @@ -132,7 +138,7 @@ typedef struct { HANDLE file_mapping; #endif - struct stat sb; + zend_stat_t sb; } php_stdio_stream_data; #define PHP_STDIOP_GET_FD(anfd, data) anfd = (data)->file ? fileno((data)->file) : (data)->fd @@ -143,7 +149,7 @@ static int do_fstat(php_stdio_stream_data *d, int force) int r; PHP_STDIOP_GET_FD(fd, d); - r = fstat(fd, &d->sb); + r = zend_fstat(fd, &d->sb); d->cached_fstat = r == 0; return r; @@ -246,9 +252,9 @@ PHPAPI php_stream *_php_stream_fopen_from_fd(int fd, const char *mode, const cha if (self->is_pipe) { stream->flags |= PHP_STREAM_FLAG_NO_SEEK; } else { - stream->position = lseek(self->fd, 0, SEEK_CUR); + stream->position = zend_lseek(self->fd, 0, SEEK_CUR); #ifdef ESPIPE - if (stream->position == (off_t)-1 && errno == ESPIPE) { + if (stream->position == (zend_off_t)-1 && errno == ESPIPE) { stream->position = 0; stream->flags |= PHP_STREAM_FLAG_NO_SEEK; self->is_pipe = 1; @@ -285,7 +291,7 @@ PHPAPI php_stream *_php_stream_fopen_from_file(FILE *file, const char *mode STRE if (self->is_pipe) { stream->flags |= PHP_STREAM_FLAG_NO_SEEK; } else { - stream->position = ftell(file); + stream->position = zend_ftell(file); } } @@ -342,13 +348,13 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS assert(data != NULL); if (data->fd >= 0) { - ret = read(data->fd, buf, count); + ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count)); if (ret == (size_t)-1 && errno == EINTR) { /* Read was interrupted, retry once, If read still fails, giveup with feof==0 so script can retry if desired */ - ret = read(data->fd, buf, count); + ret = read(data->fd, buf, PLAIN_WRAP_BUF_SIZE(count)); } stream->eof = (ret == 0 || (ret == (size_t)-1 && errno != EWOULDBLOCK && errno != EINTR && errno != EBADF)); @@ -356,7 +362,7 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS } else { #if HAVE_FLUSHIO if (!data->is_pipe && data->last_op == 'w') - fseek(data->file, 0, SEEK_CUR); + zend_fseek(data->file, 0, SEEK_CUR); data->last_op = 'r'; #endif @@ -445,7 +451,7 @@ static int php_stdiop_flush(php_stream *stream TSRMLS_DC) return 0; } -static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) +static int php_stdiop_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset TSRMLS_DC) { php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract; int ret; @@ -458,18 +464,18 @@ static int php_stdiop_seek(php_stream *stream, off_t offset, int whence, off_t * } if (data->fd >= 0) { - off_t result; + zend_off_t result; - result = lseek(data->fd, offset, whence); - if (result == (off_t)-1) + result = zend_lseek(data->fd, offset, whence); + if (result == (zend_off_t)-1) return -1; *newoffset = result; return 0; } else { - ret = fseek(data->file, offset, whence); - *newoffset = ftell(data->file); + ret = zend_fseek(data->file, offset, whence); + *newoffset = zend_ftell(data->file); return ret; } } @@ -831,7 +837,7 @@ static int php_plain_files_dirstream_close(php_stream *stream, int close_handle return closedir((DIR *)stream->abstract); } -static int php_plain_files_dirstream_rewind(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_plain_files_dirstream_rewind(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) { rewinddir((DIR *)stream->abstract); return 0; @@ -1096,7 +1102,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f #ifndef PHP_WIN32 # ifdef EXDEV if (errno == EXDEV) { - struct stat sb; + zend_stat_t sb; if (php_copy_file(url_from, url_to TSRMLS_CC) == SUCCESS) { if (VCWD_STAT(url_from, &sb) == 0) { # if !defined(TSRM_WIN32) && !defined(NETWARE) @@ -1159,7 +1165,7 @@ static int php_plain_files_mkdir(php_stream_wrapper *wrapper, const char *dir, i } else { /* we look for directory separator from the end of string, thus hopefuly reducing our work load */ char *e; - struct stat sb; + zend_stat_t sb; int dir_len = strlen(dir); int offset = 0; char buf[MAXPATHLEN]; @@ -1330,7 +1336,7 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url break; #endif case PHP_STREAM_META_ACCESS: - mode = (mode_t)*(long *)value; + mode = (mode_t)*(zend_long *)value; ret = VCWD_CHMOD(url, mode); break; default: |