summaryrefslogtreecommitdiff
path: root/main/streams/plain_wrapper.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/streams/plain_wrapper.c')
-rw-r--r--main/streams/plain_wrapper.c71
1 files changed, 41 insertions, 30 deletions
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 6d8b5c203d..40099a1700 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2014 The PHP Group |
+----------------------------------------------------------------------+
@@ -41,6 +41,7 @@
#include "php_streams_int.h"
#ifdef PHP_WIN32
# include "win32/winutil.h"
+# include "win32/time.h"
#endif
#define php_stream_fopen_from_fd_int(fd, mode, persistent_id) _php_stream_fopen_from_fd_int((fd), (mode), (persistent_id) STREAMS_CC TSRMLS_CC)
@@ -53,6 +54,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 +139,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 +150,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 +253,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 +292,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);
}
}
@@ -318,7 +325,11 @@ static size_t php_stdiop_write(php_stream *stream, const char *buf, size_t count
assert(data != NULL);
if (data->fd >= 0) {
+#ifdef PHP_WIN32
+ int bytes_written = write(data->fd, buf, (unsigned int)count);
+#else
int bytes_written = write(data->fd, buf, count);
+#endif
if (bytes_written < 0) return 0;
return (size_t) bytes_written;
} else {
@@ -370,13 +381,13 @@ static size_t php_stdiop_read(php_stream *stream, char *buf, size_t count TSRMLS
}
}
#endif
- 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));
@@ -384,7 +395,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
@@ -473,7 +484,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;
@@ -486,18 +497,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;
}
}
@@ -769,8 +780,8 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
GetSystemInfo(&info);
gran = info.dwAllocationGranularity;
- loffs = (range->offset / gran) * gran;
- delta = range->offset - loffs;
+ loffs = ((DWORD)range->offset / gran) * gran;
+ delta = (DWORD)range->offset - loffs;
}
data->last_mapped_addr = MapViewOfFile(data->file_mapping, acc, 0, loffs, range->length + delta);
@@ -859,7 +870,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;
@@ -1084,11 +1095,11 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, const char *url_f
}
#ifdef PHP_WIN32
- if (!php_win32_check_trailing_space(url_from, strlen(url_from))) {
+ if (!php_win32_check_trailing_space(url_from, (int)strlen(url_from))) {
php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC);
return 0;
}
- if (!php_win32_check_trailing_space(url_to, strlen(url_to))) {
+ if (!php_win32_check_trailing_space(url_to, (int)strlen(url_to))) {
php_win32_docref2_from_error(ERROR_INVALID_NAME, url_from, url_to TSRMLS_CC);
return 0;
}
@@ -1112,7 +1123,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)
@@ -1173,8 +1184,8 @@ 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;
- int dir_len = strlen(dir);
+ zend_stat_t sb;
+ int dir_len = (int)strlen(dir);
int offset = 0;
char buf[MAXPATHLEN];
@@ -1252,7 +1263,7 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, i
}
#if PHP_WIN32
- int url_len = strlen(url);
+ int url_len = (int)strlen(url);
#endif
if (php_check_open_basedir(url TSRMLS_CC)) {
return 0;
@@ -1286,7 +1297,7 @@ static int php_plain_files_metadata(php_stream_wrapper *wrapper, const char *url
mode_t mode;
int ret = 0;
#if PHP_WIN32
- int url_len = strlen(url);
+ int url_len = (int)strlen(url);
#endif
#if PHP_WIN32
@@ -1345,7 +1356,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:
@@ -1375,7 +1386,7 @@ static php_stream_wrapper_ops php_plain_files_wrapper_ops = {
php_plain_files_metadata
};
-php_stream_wrapper php_plain_files_wrapper = {
+PHPAPI php_stream_wrapper php_plain_files_wrapper = {
&php_plain_files_wrapper_ops,
NULL,
0
@@ -1402,7 +1413,7 @@ PHPAPI php_stream *_php_stream_fopen_with_path(const char *filename, const char
return NULL;
}
- filename_length = strlen(filename);
+ filename_length = (int)strlen(filename);
/* Relative path open */
if (*filename == '.' && (IS_SLASH(filename[1]) || filename[1] == '.')) {
@@ -1467,8 +1478,8 @@ not_relative_path:
*/
if (zend_is_executing(TSRMLS_C)) {
exec_fname = zend_get_executed_filename(TSRMLS_C);
- exec_fname_length = strlen(exec_fname);
- path_length = strlen(path);
+ exec_fname_length = (int)strlen(exec_fname);
+ path_length = (int)strlen(path);
while ((--exec_fname_length >= 0) && !IS_SLASH(exec_fname[exec_fname_length]));
if ((exec_fname && exec_fname[0] == '[')