diff options
author | Anatol Belski <ab@php.net> | 2014-08-16 11:16:11 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2014-08-16 11:16:11 +0200 |
commit | 8ee2a4a9b5de682c0b37670e1f4f86242b1650ce (patch) | |
tree | 7768898294c125f79de082a986e962aa6cb23094 /main/streams | |
parent | 735ec33b828bc4429c4ec8de7ba547925a4b44e3 (diff) | |
download | php-git-8ee2a4a9b5de682c0b37670e1f4f86242b1650ce.tar.gz |
first shot on merging the core fro the int64 branch
Diffstat (limited to 'main/streams')
-rw-r--r-- | main/streams/cast.c | 14 | ||||
-rw-r--r-- | main/streams/glob_wrapper.c | 2 | ||||
-rw-r--r-- | main/streams/memory.c | 10 | ||||
-rw-r--r-- | main/streams/mmap.c | 2 | ||||
-rw-r--r-- | main/streams/php_stream_mmap.h | 2 | ||||
-rw-r--r-- | main/streams/plain_wrapper.c | 40 | ||||
-rw-r--r-- | main/streams/streams.c | 8 | ||||
-rw-r--r-- | main/streams/transports.c | 4 | ||||
-rw-r--r-- | main/streams/userspace.c | 142 | ||||
-rw-r--r-- | main/streams/xp_socket.c | 28 |
10 files changed, 133 insertions, 119 deletions
diff --git a/main/streams/cast.c b/main/streams/cast.c index 78073c6187..4780d46eea 100644 --- a/main/streams/cast.c +++ b/main/streams/cast.c @@ -76,7 +76,7 @@ static int stream_cookie_writer(void *cookie, const char *buffer, int size) return php_stream_write((php_stream *)cookie, (char *)buffer, size); } -static PHP_FPOS_T stream_cookie_seeker(void *cookie, off_t position, int whence) +static PHP_FPOS_T stream_cookie_seeker(void *cookie, zend_off_t position, int whence) { TSRMLS_FETCH(); @@ -114,7 +114,7 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence) { TSRMLS_FETCH(); - *position = php_stream_seek((php_stream *)cookie, (off_t)*position, whence); + *position = php_stream_seek((php_stream *)cookie, (zend_off_t)*position, whence); if (*position == -1) { return -1; @@ -122,7 +122,7 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence) return 0; } # else -static int stream_cookie_seeker(void *cookie, off_t position, int whence) +static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence) { TSRMLS_FETCH(); @@ -206,7 +206,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show if (ret && castas != PHP_STREAM_AS_FD_FOR_SELECT) { php_stream_flush(stream); if (stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0) { - off_t dummy; + zend_off_t dummy; stream->ops->seek(stream, stream->position, SEEK_SET, &dummy TSRMLS_CC); stream->readpos = stream->writepos = 0; @@ -246,7 +246,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show } if (*ret != NULL) { - off_t pos; + zend_off_t pos; stream->fclose_stdiocast = PHP_STREAM_FCLOSE_FOPENCOOKIE; @@ -254,7 +254,7 @@ PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show * the stdio layer to believe it's real location. */ pos = php_stream_tell(stream); if (pos > 0) { - fseek(*ret, pos, SEEK_SET); + zend_fseek(*ret, pos, SEEK_SET); } goto exit_success; @@ -334,7 +334,7 @@ exit_success: * will be accessing the stream. Emit a warning so that the end-user will * know that they should try something else */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld bytes of buffered data lost during stream conversion!", (long)(stream->writepos - stream->readpos)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, ZEND_INT_FMT " bytes of buffered data lost during stream conversion!", (php_int_t)(stream->writepos - stream->readpos)); } if (castas == PHP_STREAM_AS_STDIO && ret) { diff --git a/main/streams/glob_wrapper.c b/main/streams/glob_wrapper.c index 5a48584f4e..ceb60d5b07 100644 --- a/main/streams/glob_wrapper.c +++ b/main/streams/glob_wrapper.c @@ -180,7 +180,7 @@ static int php_glob_stream_close(php_stream *stream, int close_handle TSRMLS_DC) } /* {{{ */ -static int php_glob_stream_rewind(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) /* {{{ */ +static int php_glob_stream_rewind(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) /* {{{ */ { glob_s_t *pglob = (glob_s_t *)stream->abstract; diff --git a/main/streams/memory.c b/main/streams/memory.c index 5da0c8decd..71e9005fa7 100644 --- a/main/streams/memory.c +++ b/main/streams/memory.c @@ -127,7 +127,7 @@ static int php_stream_memory_flush(php_stream *stream TSRMLS_DC) /* {{{ */ -static int php_stream_memory_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_stream_memory_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) { php_stream_memory_data *ms = (php_stream_memory_data*)stream->abstract; assert(ms != NULL); @@ -442,7 +442,7 @@ static int php_stream_temp_flush(php_stream *stream TSRMLS_DC) /* {{{ */ -static int php_stream_temp_seek(php_stream *stream, off_t offset, int whence, off_t *newoffs TSRMLS_DC) +static int php_stream_temp_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffs TSRMLS_DC) { php_stream_temp_data *ts = (php_stream_temp_data*)stream->abstract; int ret; @@ -468,7 +468,7 @@ static int php_stream_temp_cast(php_stream *stream, int castas, void **ret TSRML php_stream *file; size_t memsize; char *membuf; - off_t pos; + zend_off_t pos; assert(ts != NULL); @@ -584,7 +584,7 @@ PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char { php_stream *stream; php_stream_temp_data *ts; - off_t newoffs; + zend_off_t newoffs; if ((stream = php_stream_temp_create_rel(mode, max_memory_usage)) != NULL) { if (length) { @@ -618,7 +618,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con php_stream_temp_data *ts; char *comma, *semi, *sep, *key; size_t mlen, dlen, plen, vlen; - off_t newoffs; + zend_off_t newoffs; zval meta; int base64 = 0, ilen; zend_string *base64_comma = NULL; diff --git a/main/streams/mmap.c b/main/streams/mmap.c index 050e95f285..a99c8994aa 100644 --- a/main/streams/mmap.c +++ b/main/streams/mmap.c @@ -51,7 +51,7 @@ PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC) return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0; } -PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC) +PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden TSRMLS_DC) { int ret = 1; diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h index b3570be48c..5d200d729a 100644 --- a/main/streams/php_stream_mmap.h +++ b/main/streams/php_stream_mmap.h @@ -74,7 +74,7 @@ PHPAPI char *_php_stream_mmap_range(php_stream *stream, size_t offset, size_t le PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC); #define php_stream_mmap_unmap(stream) _php_stream_mmap_unmap((stream) TSRMLS_CC) -PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC); +PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, zend_off_t readden TSRMLS_DC); #define php_stream_mmap_unmap_ex(stream, readden) _php_stream_mmap_unmap_ex((stream), (readden) TSRMLS_CC) END_EXTERN_C() diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index 87312b9ef8..d9f058e3cc 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; + php_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 = php_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; + php_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; + php_stat_t sb; int dir_len = strlen(dir); int offset = 0; char buf[MAXPATHLEN]; diff --git a/main/streams/streams.c b/main/streams/streams.c index 89537bdaeb..1a6c4d24a0 100644 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -675,7 +675,7 @@ static void php_stream_fill_read_buffer(php_stream *stream, size_t size TSRMLS_D } else { /* is there enough data in the buffer ? */ - if (stream->writepos - stream->readpos < (off_t)size) { + if (stream->writepos - stream->readpos < (zend_off_t)size) { size_t justread = 0; /* reduce buffer memory consumption if possible, to avoid a realloc */ @@ -1269,12 +1269,12 @@ PHPAPI size_t _php_stream_printf(php_stream *stream TSRMLS_DC, const char *fmt, return count; } -PHPAPI off_t _php_stream_tell(php_stream *stream TSRMLS_DC) +PHPAPI zend_off_t _php_stream_tell(php_stream *stream TSRMLS_DC) { return stream->position; } -PHPAPI int _php_stream_seek(php_stream *stream, off_t offset, int whence TSRMLS_DC) +PHPAPI int _php_stream_seek(php_stream *stream, zend_off_t offset, int whence TSRMLS_DC) { if (stream->fclose_stdiocast == PHP_STREAM_FCLOSE_FOPENCOOKIE) { /* flush to commit data written to the fopencookie FILE* */ @@ -2136,7 +2136,7 @@ PHPAPI php_stream *_php_stream_open_wrapper_ex(const char *path, const char *mod } if (stream && stream->ops->seek && (stream->flags & PHP_STREAM_FLAG_NO_SEEK) == 0 && strchr(mode, 'a') && stream->position == 0) { - off_t newpos = 0; + zend_off_t newpos = 0; /* if opened for append, we need to revise our idea of the initial file position */ if (0 == stream->ops->seek(stream, 0, SEEK_CUR, &newpos TSRMLS_CC)) { diff --git a/main/streams/transports.c b/main/streams/transports.c index 7792e24fef..7f1d13faaa 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -163,8 +163,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, size_t namelen, in if (PHP_STREAM_CONTEXT(stream) && (zbacklog = php_stream_context_get_option(PHP_STREAM_CONTEXT(stream), "socket", "backlog")) != NULL) { zval *ztmp = zbacklog; - convert_to_long_ex(ztmp); - backlog = Z_LVAL_P(ztmp); + convert_to_int_ex(ztmp); + backlog = Z_IVAL_P(ztmp); if (ztmp != zbacklog) { zval_ptr_dtor(ztmp); } diff --git a/main/streams/userspace.c b/main/streams/userspace.c index c41826155c..82ff445c4f 100644 --- a/main/streams/userspace.c +++ b/main/streams/userspace.c @@ -86,35 +86,35 @@ PHP_MINIT_FUNCTION(user_streams) if (le_protocols == FAILURE) return FAILURE; - REGISTER_LONG_CONSTANT("STREAM_USE_PATH", USE_PATH, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_IGNORE_URL", IGNORE_URL, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_REPORT_ERRORS", REPORT_ERRORS, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_MUST_SEEK", STREAM_MUST_SEEK, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_URL_STAT_LINK", PHP_STREAM_URL_STAT_LINK, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_URL_STAT_QUIET", PHP_STREAM_URL_STAT_QUIET, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_MKDIR_RECURSIVE", PHP_STREAM_MKDIR_RECURSIVE, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_IS_URL", PHP_STREAM_IS_URL, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_OPTION_BLOCKING", PHP_STREAM_OPTION_BLOCKING, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_OPTION_READ_TIMEOUT", PHP_STREAM_OPTION_READ_TIMEOUT, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_OPTION_READ_BUFFER", PHP_STREAM_OPTION_READ_BUFFER, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_OPTION_WRITE_BUFFER", PHP_STREAM_OPTION_WRITE_BUFFER, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_BUFFER_NONE", PHP_STREAM_BUFFER_NONE, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_BUFFER_LINE", PHP_STREAM_BUFFER_LINE, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_BUFFER_FULL", PHP_STREAM_BUFFER_FULL, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_CAST_AS_STREAM", PHP_STREAM_AS_STDIO, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_CAST_FOR_SELECT", PHP_STREAM_AS_FD_FOR_SELECT, CONST_CS|CONST_PERSISTENT); - - REGISTER_LONG_CONSTANT("STREAM_META_TOUCH", PHP_STREAM_META_TOUCH, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_META_OWNER", PHP_STREAM_META_OWNER, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_META_OWNER_NAME", PHP_STREAM_META_OWNER_NAME, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_META_GROUP", PHP_STREAM_META_GROUP, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_META_GROUP_NAME", PHP_STREAM_META_GROUP_NAME, CONST_CS|CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("STREAM_META_ACCESS", PHP_STREAM_META_ACCESS, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_USE_PATH", USE_PATH, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_IGNORE_URL", IGNORE_URL, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_REPORT_ERRORS", REPORT_ERRORS, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_MUST_SEEK", STREAM_MUST_SEEK, CONST_CS|CONST_PERSISTENT); + + REGISTER_INT_CONSTANT("STREAM_URL_STAT_LINK", PHP_STREAM_URL_STAT_LINK, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_URL_STAT_QUIET", PHP_STREAM_URL_STAT_QUIET, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_MKDIR_RECURSIVE", PHP_STREAM_MKDIR_RECURSIVE, CONST_CS|CONST_PERSISTENT); + + REGISTER_INT_CONSTANT("STREAM_IS_URL", PHP_STREAM_IS_URL, CONST_CS|CONST_PERSISTENT); + + REGISTER_INT_CONSTANT("STREAM_OPTION_BLOCKING", PHP_STREAM_OPTION_BLOCKING, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_OPTION_READ_TIMEOUT", PHP_STREAM_OPTION_READ_TIMEOUT, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_OPTION_READ_BUFFER", PHP_STREAM_OPTION_READ_BUFFER, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_OPTION_WRITE_BUFFER", PHP_STREAM_OPTION_WRITE_BUFFER, CONST_CS|CONST_PERSISTENT); + + REGISTER_INT_CONSTANT("STREAM_BUFFER_NONE", PHP_STREAM_BUFFER_NONE, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_BUFFER_LINE", PHP_STREAM_BUFFER_LINE, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_BUFFER_FULL", PHP_STREAM_BUFFER_FULL, CONST_CS|CONST_PERSISTENT); + + REGISTER_INT_CONSTANT("STREAM_CAST_AS_STREAM", PHP_STREAM_AS_STDIO, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_CAST_FOR_SELECT", PHP_STREAM_AS_FD_FOR_SELECT, CONST_CS|CONST_PERSISTENT); + + REGISTER_INT_CONSTANT("STREAM_META_TOUCH", PHP_STREAM_META_TOUCH, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_META_OWNER", PHP_STREAM_META_OWNER, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_META_OWNER_NAME", PHP_STREAM_META_OWNER_NAME, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_META_GROUP", PHP_STREAM_META_GROUP, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_META_GROUP_NAME", PHP_STREAM_META_GROUP_NAME, CONST_CS|CONST_PERSISTENT); + REGISTER_INT_CONSTANT("STREAM_META_ACCESS", PHP_STREAM_META_ACCESS, CONST_CS|CONST_PERSISTENT); return SUCCESS; } @@ -367,7 +367,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * /* call it's stream_open method - set up params first */ ZVAL_STRING(&args[0], filename); ZVAL_STRING(&args[1], mode); - ZVAL_LONG(&args[2], options); + ZVAL_INT(&args[2], options); ZVAL_NEW_REF(&args[3], &EG(uninitialized_zval)); ZVAL_STRING(&zfuncname, USERSTREAM_OPEN); @@ -385,7 +385,7 @@ static php_stream *user_wrapper_opener(php_stream_wrapper *wrapper, const char * /* if the opened path is set, copy it out */ if (Z_ISREF(args[3]) && Z_TYPE_P(Z_REFVAL(args[3])) == IS_STRING && opened_path) { - *opened_path = estrndup(Z_STRVAL_P(Z_REFVAL(args[3])), Z_STRLEN_P(Z_REFVAL(args[3]))); + *opened_path = estrndup(Z_STRVAL_P(Z_REFVAL(args[3])), Z_STRSIZE_P(Z_REFVAL(args[3]))); } /* set wrapper data to be a reference to our object */ @@ -443,7 +443,7 @@ static php_stream *user_wrapper_opendir(php_stream_wrapper *wrapper, const char /* call it's dir_open method - set up params first */ ZVAL_STRING(&args[0], filename); - ZVAL_LONG(&args[1], options); + ZVAL_INT(&args[1], options); ZVAL_STRING(&zfuncname, USERSTREAM_DIR_OPEN); @@ -490,7 +490,7 @@ PHP_FUNCTION(stream_wrapper_register) zend_string *protocol, *classname; struct php_user_stream_wrapper * uwrap; zend_resource *rsrc; - long flags = 0; + php_int_t flags = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "SS|l", &protocol, &classname, &flags) == FAILURE) { RETURN_FALSE; @@ -608,8 +608,8 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t didwrite = 0; if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { - convert_to_long(&retval); - didwrite = Z_LVAL(retval); + convert_to_int(&retval); + didwrite = Z_IVAL(retval); } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " is not implemented!", us->wrapper->classname); @@ -617,9 +617,9 @@ static size_t php_userstreamop_write(php_stream *stream, const char *buf, size_t /* don't allow strange buffer overruns due to bogus return */ if (didwrite > count) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " wrote %ld bytes more data than requested (%ld written, %ld max)", + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_WRITE " wrote " ZEND_INT_FMT " bytes more data than requested (" ZEND_INT_FMT " written, " ZEND_INT_FMT " max)", us->wrapper->classname, - (long)(didwrite - count), (long)didwrite, (long)count); + (php_int_t)(didwrite - count), (php_int_t)didwrite, (php_int_t)count); didwrite = count; } @@ -641,7 +641,7 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count ZVAL_STRINGL(&func_name, USERSTREAM_READ, sizeof(USERSTREAM_READ)-1); - ZVAL_LONG(&args[0], count); + ZVAL_INT(&args[0], count); call_result = call_user_function_ex(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, @@ -652,10 +652,10 @@ static size_t php_userstreamop_read(php_stream *stream, char *buf, size_t count if (call_result == SUCCESS && Z_TYPE(retval) != IS_UNDEF) { convert_to_string(&retval); - didread = Z_STRLEN(retval); + didread = Z_STRSIZE(retval); if (didread > count) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " - read %ld bytes more data than requested (%ld read, %ld max) - excess data will be lost", - us->wrapper->classname, (long)(didread - count), (long)didread, (long)count); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_READ " - read " ZEND_INT_FMT " bytes more data than requested (" ZEND_INT_FMT " read, " ZEND_INT_FMT " max) - excess data will be lost", + us->wrapper->classname, (php_int_t)(didread - count), (php_int_t)didread, (php_int_t)count); didread = count; } if (didread > 0) @@ -763,8 +763,8 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o ZVAL_STRINGL(&func_name, USERSTREAM_SEEK, sizeof(USERSTREAM_SEEK)-1); - ZVAL_LONG(&args[0], offset); - ZVAL_LONG(&args[1], whence); + ZVAL_INT(&args[0], offset); + ZVAL_INT(&args[1], whence); call_result = call_user_function_ex(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, @@ -807,8 +807,8 @@ static int php_userstreamop_seek(php_stream *stream, off_t offset, int whence, o &retval, 0, NULL, 0, NULL TSRMLS_CC); - if (call_result == SUCCESS && Z_TYPE(retval) == IS_LONG) { - *newoffs = Z_LVAL(retval); + if (call_result == SUCCESS && Z_TYPE(retval) == IS_INT) { + *newoffs = Z_IVAL(retval); ret = 0; } else if (call_result == FAILURE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s::" USERSTREAM_TELL " is not implemented!", us->wrapper->classname); @@ -831,8 +831,8 @@ static int statbuf_from_array(zval *array, php_stream_statbuf *ssb TSRMLS_DC) #define STAT_PROP_ENTRY_EX(name, name2) \ if (NULL != (elem = zend_hash_str_find(Z_ARRVAL_P(array), #name, sizeof(#name)-1))) { \ SEPARATE_ZVAL(elem); \ - convert_to_long(elem); \ - ssb->sb.st_##name2 = Z_LVAL_P(elem); \ + convert_to_int(elem); \ + ssb->sb.st_##name2 = Z_IVAL_P(elem); \ } #define STAT_PROP_ENTRY(name) STAT_PROP_ENTRY_EX(name,name) @@ -927,20 +927,20 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value break; case PHP_STREAM_OPTION_LOCKING: - ZVAL_LONG(&args[0], 0); + ZVAL_INT(&args[0], 0); if (value & LOCK_NB) { - Z_LVAL_P(&args[0]) |= PHP_LOCK_NB; + Z_IVAL_P(&args[0]) |= PHP_LOCK_NB; } switch(value & ~LOCK_NB) { case LOCK_SH: - Z_LVAL_P(&args[0]) |= PHP_LOCK_SH; + Z_IVAL_P(&args[0]) |= PHP_LOCK_SH; break; case LOCK_EX: - Z_LVAL_P(&args[0]) |= PHP_LOCK_EX; + Z_IVAL_P(&args[0]) |= PHP_LOCK_EX; break; case LOCK_UN: - Z_LVAL_P(&args[0]) |= PHP_LOCK_UN; + Z_IVAL_P(&args[0]) |= PHP_LOCK_UN; break; } @@ -987,7 +987,7 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value case PHP_STREAM_TRUNCATE_SET_SIZE: { ptrdiff_t new_size = *(ptrdiff_t*) ptrparam; if (new_size >= 0 && new_size <= (ptrdiff_t)LONG_MAX) { - ZVAL_LONG(&args[0], (long)new_size); + ZVAL_INT(&args[0], (long)new_size); call_result = call_user_function_ex(NULL, Z_ISUNDEF(us->object)? NULL : &us->object, &func_name, @@ -1025,28 +1025,28 @@ static int php_userstreamop_set_option(php_stream *stream, int option, int value ZVAL_STRINGL(&func_name, USERSTREAM_SET_OPTION, sizeof(USERSTREAM_SET_OPTION)-1); - ZVAL_LONG(&args[0], option); + ZVAL_INT(&args[0], option); ZVAL_NULL(&args[1]); ZVAL_NULL(&args[2]); switch(option) { case PHP_STREAM_OPTION_READ_BUFFER: case PHP_STREAM_OPTION_WRITE_BUFFER: - ZVAL_LONG(&args[1], value); + ZVAL_INT(&args[1], value); if (ptrparam) { - ZVAL_LONG(&args[2], *(long *)ptrparam); + ZVAL_INT(&args[2], *(long *)ptrparam); } else { - ZVAL_LONG(&args[2], BUFSIZ); + ZVAL_INT(&args[2], BUFSIZ); } break; case PHP_STREAM_OPTION_READ_TIMEOUT: { struct timeval tv = *(struct timeval*)ptrparam; - ZVAL_LONG(&args[1], tv.tv_sec); - ZVAL_LONG(&args[2], tv.tv_usec); + ZVAL_INT(&args[1], tv.tv_sec); + ZVAL_INT(&args[2], tv.tv_usec); break; } case PHP_STREAM_OPTION_BLOCKING: - ZVAL_LONG(&args[1], value); + ZVAL_INT(&args[1], value); break; default: break; @@ -1189,8 +1189,8 @@ static int user_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url, int /* call the mkdir method */ ZVAL_STRING(&args[0], url); - ZVAL_LONG(&args[1], mode); - ZVAL_LONG(&args[2], options); + ZVAL_INT(&args[1], mode); + ZVAL_INT(&args[2], options); ZVAL_STRING(&zfuncname, USERSTREAM_MKDIR); @@ -1237,7 +1237,7 @@ static int user_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, /* call the rmdir method */ ZVAL_STRING(&args[0], url); - ZVAL_LONG(&args[1], options); + ZVAL_INT(&args[1], options); ZVAL_STRING(&zfuncname, USERSTREAM_RMDIR); @@ -1280,14 +1280,14 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, i array_init(&args[2]); if(value) { struct utimbuf *newtime = (struct utimbuf *)value; - add_index_long(&args[2], 0, newtime->modtime); - add_index_long(&args[2], 1, newtime->actime); + add_index_int(&args[2], 0, newtime->modtime); + add_index_int(&args[2], 1, newtime->actime); } break; case PHP_STREAM_META_GROUP: case PHP_STREAM_META_OWNER: case PHP_STREAM_META_ACCESS: - ZVAL_LONG(&args[2], *(long *)value); + ZVAL_INT(&args[2], *(long *)value); break; case PHP_STREAM_META_GROUP_NAME: case PHP_STREAM_META_OWNER_NAME: @@ -1308,7 +1308,7 @@ static int user_wrapper_metadata(php_stream_wrapper *wrapper, const char *url, i /* call the mkdir method */ ZVAL_STRING(&args[0], url); - ZVAL_LONG(&args[1], option); + ZVAL_INT(&args[1], option); ZVAL_STRING(&zfuncname, USERSTREAM_METADATA); @@ -1356,7 +1356,7 @@ static int user_wrapper_stat_url(php_stream_wrapper *wrapper, const char *url, i /* call it's stat_url method - set up params first */ ZVAL_STRING(&args[0], url); - ZVAL_LONG(&args[1], flags); + ZVAL_INT(&args[1], flags); ZVAL_STRING(&zfuncname, USERSTREAM_STATURL); @@ -1414,7 +1414,7 @@ static size_t php_userstreamop_readdir(php_stream *stream, char *buf, size_t cou if (call_result == SUCCESS && Z_TYPE(retval) != IS_FALSE && Z_TYPE(retval) != IS_TRUE) { convert_to_string(&retval); - PHP_STRLCPY(ent->d_name, Z_STRVAL(retval), sizeof(ent->d_name), Z_STRLEN(retval)); + PHP_STRLCPY(ent->d_name, Z_STRVAL(retval), sizeof(ent->d_name), Z_STRSIZE(retval)); didread = sizeof(php_stream_dirent); } else if (call_result == FAILURE) { @@ -1489,10 +1489,10 @@ static int php_userstreamop_cast(php_stream *stream, int castas, void **retptr T switch(castas) { case PHP_STREAM_AS_FD_FOR_SELECT: - ZVAL_LONG(&args[0], PHP_STREAM_AS_FD_FOR_SELECT); + ZVAL_INT(&args[0], PHP_STREAM_AS_FD_FOR_SELECT); break; default: - ZVAL_LONG(&args[0], PHP_STREAM_AS_STDIO); + ZVAL_INT(&args[0], PHP_STREAM_AS_STDIO); break; } diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index dad78beb13..d2aaef0bc3 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -39,6 +39,13 @@ # define MSG_PEEK 0 #endif +#ifdef PHP_WIN32 +/* send/recv family on windows expects int */ +# define XP_SOCK_BUF_SIZE(sz) (((sz) > INT_MAX) ? INT_MAX : (int)(sz)) +#else +# define XP_SOCK_BUF_SIZE(sz) (sz) +#endif + php_stream_ops php_stream_generic_socket_ops; PHPAPI php_stream_ops php_stream_socket_ops; php_stream_ops php_stream_udp_socket_ops; @@ -67,7 +74,7 @@ static size_t php_sockop_write(php_stream *stream, const char *buf, size_t count ptimeout = &sock->timeout; retry: - didwrite = send(sock->socket, buf, count, (sock->is_blocked && ptimeout) ? MSG_DONTWAIT : 0); + didwrite = send(sock->socket, buf, XP_SOCK_BUF_SIZE(count), (sock->is_blocked && ptimeout) ? MSG_DONTWAIT : 0); if (didwrite <= 0) { long err = php_socket_errno(); @@ -95,8 +102,8 @@ retry: } while (err == EINTR); } estr = php_socket_strerror(err, NULL, 0); - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "send of %ld bytes failed with errno=%ld %s", - (long)count, err, estr); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "send of " ZEND_INT_FMT " bytes failed with errno=%ld %s", + (php_int_t)count, err, estr); efree(estr); } @@ -144,7 +151,7 @@ static void php_sock_stream_wait_for_data(php_stream *stream, php_netstream_data static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS_DC) { php_netstream_data_t *sock = (php_netstream_data_t*)stream->abstract; - int nr_bytes = 0; + ssize_t nr_bytes = 0; if (!sock || sock->socket == -1) { return 0; @@ -156,7 +163,7 @@ static size_t php_sockop_read(php_stream *stream, char *buf, size_t count TSRMLS return 0; } - nr_bytes = recv(sock->socket, buf, count, (sock->is_blocked && sock->timeout.tv_sec != -1) ? MSG_DONTWAIT : 0); + nr_bytes = recv(sock->socket, buf, XP_SOCK_BUF_SIZE(count), (sock->is_blocked && sock->timeout.tv_sec != -1) ? MSG_DONTWAIT : 0); stream->eof = (nr_bytes == 0 || (nr_bytes == -1 && php_socket_errno() != EWOULDBLOCK)); @@ -230,7 +237,7 @@ static int php_sockop_stat(php_stream *stream, php_stream_statbuf *ssb TSRMLS_DC #if ZEND_WIN32 return 0; #else - return fstat(sock->socket, &ssb->sb); + return php_fstat(sock->socket, &ssb->sb); #endif } @@ -240,7 +247,8 @@ static inline int sock_sendto(php_netstream_data_t *sock, const char *buf, size_ { int ret; if (addr) { - ret = sendto(sock->socket, buf, buflen, flags, addr, addrlen); + ret = sendto(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags, addr, XP_SOCK_BUF_SIZE(addrlen)); + return (ret == SOCK_CONN_ERR) ? -1 : ret; } return ((ret = send(sock->socket, buf, buflen, flags)) == SOCK_CONN_ERR) ? -1 : ret; @@ -257,12 +265,12 @@ static inline int sock_recvfrom(php_netstream_data_t *sock, char *buf, size_t bu int want_addr = textaddr || addr; if (want_addr) { - ret = recvfrom(sock->socket, buf, buflen, flags, (struct sockaddr*)&sa, &sl); + ret = recvfrom(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags, (struct sockaddr*)&sa, &sl); ret = (ret == SOCK_CONN_ERR) ? -1 : ret; php_network_populate_name_from_sockaddr((struct sockaddr*)&sa, sl, textaddr, addr, addrlen TSRMLS_CC); } else { - ret = recv(sock->socket, buf, buflen, flags); + ret = recv(sock->socket, buf, XP_SOCK_BUF_SIZE(buflen), flags); ret = (ret == SOCK_CONN_ERR) ? -1 : ret; } @@ -694,7 +702,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_ efree(host); return -1; } - bindto = parse_ip_address_ex(Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC); + bindto = parse_ip_address_ex(Z_STRVAL_P(tmpzval), Z_STRSIZE_P(tmpzval), &bindport, xparam->want_errortext, &xparam->outputs.error_text TSRMLS_CC); } #ifdef SO_BROADCAST |