com php-src: fixed stat usage, yet core only: Zend/zend_strea m.c Zend/zend_stream.h Zend/zend_virtual_cwd.c Zend/zend_virtual_cwd.h
ext/standard/dir.c ext/s tandard/filestat.c main/php_streams.h main/streams/pl ain_wrapper.c main/streams/xp_socket.c win32/gl ob.c win32/glob.h

From: Date: Tue, 12 Nov 2013 20:10:23 +0000
Subject: com php-src: fixed stat usage, yet core only: Zend/zend_strea m.c Zend/zend_stream.h Zend/zend_virtual_cwd.c Zend/zend_virtual_cwd.h
ext/standard/dir.c ext/s tandard/filestat.c main/php_streams.h main/streams/pl ain_wrapper.c main/streams/xp_socket.c win32/gl ob.c win32/glob.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-73943@lists.php.net to get a copy of this message
Commit: 468b2923ca1f80e45a46e957b93cd62da6328780 Author: Anatol Belski <ab@php.net> Tue, 12 Nov 2013 21:10:23 +0100 Parents: e9c7342a80fad73bf54605e7c4373a5b0579ed8f Branches: str_size_and_int64 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=468b2923ca1f80e45a46e957b93cd62da6328780 Log: fixed stat usage, yet core only - defined php_stat_t as replacement for struct stat - on _WIN64 use _fstat64 Changed paths: M Zend/zend_stream.c M Zend/zend_stream.h M Zend/zend_virtual_cwd.c M Zend/zend_virtual_cwd.h M ext/standard/dir.c M ext/standard/filestat.c M main/php_streams.h M main/streams/plain_wrapper.c M main/streams/xp_socket.c M win32/glob.c M win32/glob.h

diff --git a/Zend/zend_stream.c b/Zend/zend_stream.c index 480657c..6befc79 100644 --- a/Zend/zend_stream.c +++ b/Zend/zend_stream.c @@ -24,9 +24,8 @@ #include "zend.h" #include "zend_compile.h" +#include "zend_stream.h" -#include <sys/types.h> -#include <sys/stat.h> #if HAVE_MMAP # if HAVE_UNISTD_H # include <unistd.h> @@ -64,8 +63,8 @@ static void zend_stream_stdio_closer(void *handle TSRMLS_DC) /* {{{ */ static size_t zend_stream_stdio_fsizer(void *handle TSRMLS_DC) /* {{{ */ { - struct stat buf; - if (handle && fstat(fileno((FILE*)handle), &buf) == 0) { + zend_stat_t buf; + if (handle && zend_fstat(fileno((FILE*)handle), &buf) == 0) { #ifdef S_ISREG if (!S_ISREG(buf.st_mode)) { return 0; diff --git a/Zend/zend_stream.h b/Zend/zend_stream.h index 04684ab..4bb39d2 100644 --- a/Zend/zend_stream.h +++ b/Zend/zend_stream.h @@ -24,6 +24,9 @@ #ifndef ZEND_STREAM_H #define ZEND_STREAM_H +#include <sys/types.h> +#include <sys/stat.h> + /* Lightweight stream implementation for the ZE scanners. * These functions are private to the engine. * */ @@ -82,10 +85,14 @@ END_EXTERN_C() # define zend_fseek _fseeki64 # define zend_ftell _ftelli64 # define zend_lseek _lseeki64 +# define zend_fstat _fstat64 +typedef struct __stat64 zend_stat_t; #else # define zend_fseek fseek # define zend_ftell ftell # define zend_lseek lseek +# define zend_fstat stat +typedef struct stat zend_stat_t; #endif #endif diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index d9da5cf..4f52c2b 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -291,7 +291,7 @@ CWD_API int php_sys_readlink(const char *link, char *target, size_t target_len){ } /* }}} */ -CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat) /* {{{ */ +CWD_API int php_sys_stat_ex(const char *path, zend_stat_t *buf, int lstat) /* {{{ */ { WIN32_FILE_ATTRIBUTE_DATA data; __int64 t; @@ -407,7 +407,7 @@ CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat) /* {{ static int php_is_dir_ok(const cwd_state *state) /* {{{ */ { - struct stat buf; + zend_stat_t buf; if (php_sys_stat(state->cwd, &buf) == 0 && S_ISDIR(buf.st_mode)) return (0); @@ -418,7 +418,7 @@ static int php_is_dir_ok(const cwd_state *state) /* {{{ */ static int php_is_file_ok(const cwd_state *state) /* {{{ */ { - struct stat buf; + zend_stat_t buf; if (php_sys_stat(state->cwd, &buf) == 0 && S_ISREG(buf.st_mode)) return (0); @@ -784,7 +784,7 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i HANDLE hFind; ALLOCA_FLAG(use_heap_large) #else - struct stat st; + zend_stat_t st; #endif realpath_cache_bucket *bucket; char *tmp; @@ -1739,7 +1739,7 @@ CWD_API int virtual_rename(const char *oldname, const char *newname TSRMLS_DC) / } /* }}} */ -CWD_API int virtual_stat(const char *path, struct stat *buf TSRMLS_DC) /* {{{ */ +CWD_API int virtual_stat(const char *path, zend_stat_t *buf TSRMLS_DC) /* {{{ */ { cwd_state new_state; int retval; @@ -1757,7 +1757,7 @@ CWD_API int virtual_stat(const char *path, struct stat *buf TSRMLS_DC) /* {{{ */ } /* }}} */ -CWD_API int virtual_lstat(const char *path, struct stat *buf TSRMLS_DC) /* {{{ */ +CWD_API int virtual_lstat(const char *path, zend_stat_t *buf TSRMLS_DC) /* {{{ */ { cwd_state new_state; int retval; diff --git a/Zend/zend_virtual_cwd.h b/Zend/zend_virtual_cwd.h index a6ac0ae..2a70660 100644 --- a/Zend/zend_virtual_cwd.h +++ b/Zend/zend_virtual_cwd.h @@ -130,7 +130,7 @@ typedef unsigned short mode_t; #endif #ifdef TSRM_WIN32 -CWD_API int php_sys_stat_ex(const char *path, struct stat *buf, int lstat); +CWD_API int php_sys_stat_ex(const char *path, zend_stat_t *buf, int lstat); # define php_sys_stat(path, buf) php_sys_stat_ex(path, buf, 0) # define php_sys_lstat(path, buf) php_sys_stat_ex(path, buf, 1) CWD_API int php_sys_readlink(const char *link, char *target, size_t target_len); @@ -164,8 +164,8 @@ CWD_API FILE *virtual_fopen(const char *path, const char *mode TSRMLS_DC); CWD_API int virtual_open(const char *path TSRMLS_DC, int flags, ...); CWD_API int virtual_creat(const char *path, mode_t mode TSRMLS_DC); CWD_API int virtual_rename(const char *oldname, const char *newname TSRMLS_DC); -CWD_API int virtual_stat(const char *path, struct stat *buf TSRMLS_DC); -CWD_API int virtual_lstat(const char *path, struct stat *buf TSRMLS_DC); +CWD_API int virtual_stat(const char *path, zend_stat_t *buf TSRMLS_DC); +CWD_API int virtual_lstat(const char *path, zend_stat_t *buf TSRMLS_DC); CWD_API int virtual_unlink(const char *path TSRMLS_DC); CWD_API int virtual_mkdir(const char *pathname, mode_t mode TSRMLS_DC); CWD_API int virtual_rmdir(const char *pathname TSRMLS_DC); diff --git a/ext/standard/dir.c b/ext/standard/dir.c index 2015cc4..a34254f 100644 --- a/ext/standard/dir.c +++ b/ext/standard/dir.c @@ -526,7 +526,7 @@ no_results: * able to filter directories out. */ if (flags & GLOB_ONLYDIR) { - struct stat s; + php_stat_t s; if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) { continue; diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 2c57d27..c4c9300 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -850,7 +850,7 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int typ { zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev, *stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks; - struct stat *stat_sb; + zend_stat_t *stat_sb; php_stream_statbuf ssb; int flags = 0, rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH; /* access rights defaults to other */ char *stat_sb_names[13] = { @@ -962,21 +962,21 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int typ switch (type) { case FS_PERMS: - RETURN_LONG((long)ssb.sb.st_mode); + RETURN_LONG((php_int_t)ssb.sb.st_mode); case FS_INODE: - RETURN_LONG((long)ssb.sb.st_ino); + RETURN_LONG((php_int_t)ssb.sb.st_ino); case FS_SIZE: - RETURN_LONG((long)ssb.sb.st_size); + RETURN_LONG((php_int_t)ssb.sb.st_size); case FS_OWNER: - RETURN_LONG((long)ssb.sb.st_uid); + RETURN_LONG((php_int_t)ssb.sb.st_uid); case FS_GROUP: - RETURN_LONG((long)ssb.sb.st_gid); + RETURN_LONG((php_int_t)ssb.sb.st_gid); case FS_ATIME: - RETURN_LONG((long)ssb.sb.st_atime); + RETURN_LONG((php_int_t)ssb.sb.st_atime); case FS_MTIME: - RETURN_LONG((long)ssb.sb.st_mtime); + RETURN_LONG((php_int_t)ssb.sb.st_mtime); case FS_CTIME: - RETURN_LONG((long)ssb.sb.st_ctime); + RETURN_LONG((php_int_t)ssb.sb.st_ctime); case FS_TYPE: if (S_ISLNK(ssb.sb.st_mode)) { RETURN_STRING("link", 1); @@ -1019,7 +1019,15 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int typ MAKE_LONG_ZVAL_INCREF(stat_uid, stat_sb->st_uid); MAKE_LONG_ZVAL_INCREF(stat_gid, stat_sb->st_gid); #ifdef HAVE_ST_RDEV +# ifdef _WIN64 + if (stat_sb->st_rdev < ((_dev_t)-1)) { + MAKE_LONG_ZVAL_INCREF(stat_rdev, stat_sb->st_rdev); + } else { + MAKE_LONG_ZVAL_INCREF(stat_rdev, -1); + } +# else MAKE_LONG_ZVAL_INCREF(stat_rdev, stat_sb->st_rdev); +# endif #else MAKE_LONG_ZVAL_INCREF(stat_rdev, -1); #endif diff --git a/main/php_streams.h b/main/php_streams.h index a87f3ac..d6381c5 100644 --- a/main/php_streams.h +++ b/main/php_streams.h @@ -103,8 +103,16 @@ typedef struct _php_stream_filter php_stream_filter; #include "streams/php_stream_context.h" #include "streams/php_stream_filter_api.h" +#ifdef _WIN64 +# define php_fstat _fstat64 +typedef struct __stat64 php_stat_t; +#else +# define php_fstat fstat +typedef struct stat php_stat_t; +#endif + typedef struct _php_stream_statbuf { - struct stat sb; /* regular info */ + zend_stat_t sb; /* regular info */ /* extended info to go here some day: content-type etc. etc. */ } php_stream_statbuf; diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index fafc98c..5ed1421 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.c @@ -136,7 +136,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 @@ -147,7 +147,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; @@ -1106,7 +1106,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) @@ -1169,7 +1169,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; zend_str_size_int dir_len = strlen(dir); int offset = 0; char buf[MAXPATHLEN]; diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index c0f9927..6244969 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -233,7 +233,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 } diff --git a/win32/glob.c b/win32/glob.c index 1aeac78..a1d0ddc 100644 --- a/win32/glob.c +++ b/win32/glob.c @@ -139,10 +139,10 @@ typedef char Char; static int compare(const void *, const void *); static int g_Ctoc(const Char *, char *, u_int); -static int g_lstat(Char *, struct stat *, glob_t *); +static int g_lstat(Char *, php_stat_t *, glob_t *); static DIR *g_opendir(Char *, glob_t *); static Char *g_strchr(Char *, int); -static int g_stat(Char *, struct stat *, glob_t *); +static int g_stat(Char *, php_stat_t *, glob_t *); static int glob0(const Char *, glob_t *); static int glob1(Char *, Char *, glob_t *, size_t *); static int glob2(Char *, Char *, Char *, Char *, Char *, Char *, @@ -552,7 +552,7 @@ glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, glob_t *pglob; size_t *limitp; { - struct stat sb; + php_stat_t sb; Char *p, *q; int anymeta; @@ -849,7 +849,7 @@ g_opendir(str, pglob) static int g_lstat(fn, sb, pglob) register Char *fn; - struct stat *sb; + php_stat_t *sb; glob_t *pglob; { char buf[MAXPATHLEN]; @@ -864,7 +864,7 @@ g_lstat(fn, sb, pglob) static int g_stat(fn, sb, pglob) register Char *fn; - struct stat *sb; + php_stat_t *sb; glob_t *pglob; { char buf[MAXPATHLEN]; diff --git a/win32/glob.h b/win32/glob.h index 3f7a57a..a03fda9 100644 --- a/win32/glob.h +++ b/win32/glob.h @@ -47,7 +47,7 @@ # include <sys/cdefs.h> #endif -struct stat; +php_stat_t; typedef struct { int gl_pathc; /* Count of total paths so far. */ int gl_matchc; /* Count of paths matching pattern. */ @@ -65,8 +65,8 @@ typedef struct { void (*gl_closedir)(void *); struct dirent *(*gl_readdir)(void *); void *(*gl_opendir)(const char *); - int (*gl_lstat)(const char *, struct stat *); - int (*gl_stat)(const char *, struct stat *); + int (*gl_lstat)(const char *, php_stat_t *); + int (*gl_stat)(const char *, php_stat_t *); } glob_t; /* Flags */
« previous php.cvs (#73943) next »