summaryrefslogtreecommitdiff
path: root/ext/standard/filestat.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/filestat.c')
-rw-r--r--ext/standard/filestat.c75
1 files changed, 43 insertions, 32 deletions
diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c
index 9fb35ef344..c26170e4b6 100644
--- a/ext/standard/filestat.c
+++ b/ext/standard/filestat.c
@@ -158,7 +158,7 @@ static int php_disk_total_space(char *path, double *space TSRMLS_DC) /* {{{ */
/* i know - this is ugly, but i works <thies@thieso.net> */
bytestotal = TotalNumberOfBytes.HighPart *
- (double) (((unsigned long)1) << 31) * 2.0 +
+ (double) (((zend_ulong)1) << 31) * 2.0 +
TotalNumberOfBytes.LowPart;
} else { /* If it's not available, we just use GetDiskFreeSpace */
if (GetDiskFreeSpace(path,
@@ -233,7 +233,7 @@ PHP_FUNCTION(disk_total_space)
{
double bytestotal;
char *path;
- int path_len;
+ size_t path_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &path, &path_len) == FAILURE) {
return;
@@ -290,7 +290,7 @@ static int php_disk_free_space(char *path, double *space TSRMLS_DC) /* {{{ */
/* i know - this is ugly, but i works <thies@thieso.net> */
bytesfree = FreeBytesAvailableToCaller.HighPart *
- (double) (((unsigned long)1) << 31) * 2.0 +
+ (double) (((zend_ulong)1) << 31) * 2.0 +
FreeBytesAvailableToCaller.LowPart;
} else { /* If it's not available, we just use GetDiskFreeSpace */
if (GetDiskFreeSpace(path,
@@ -368,7 +368,7 @@ PHP_FUNCTION(disk_free_space)
{
double bytesfree;
char *path;
- int path_len;
+ size_t path_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &path, &path_len) == FAILURE) {
return;
@@ -420,7 +420,7 @@ PHPAPI int php_get_gid_by_name(const char *name, gid_t *gid TSRMLS_DC)
static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */
{
char *filename;
- int filename_len;
+ size_t filename_len;
zval *group;
#if !defined(WINDOWS)
gid_t gid;
@@ -557,7 +557,7 @@ PHPAPI uid_t php_get_uid_by_name(const char *name, uid_t *uid TSRMLS_DC)
static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */
{
char *filename;
- int filename_len;
+ size_t filename_len;
zval *user;
#if !defined(WINDOWS)
uid_t uid;
@@ -667,8 +667,8 @@ PHP_FUNCTION(lchown)
PHP_FUNCTION(chmod)
{
char *filename;
- int filename_len;
- long mode;
+ size_t filename_len;
+ zend_long mode;
int ret;
mode_t imode;
php_stream_wrapper *wrapper;
@@ -713,8 +713,8 @@ PHP_FUNCTION(chmod)
PHP_FUNCTION(touch)
{
char *filename;
- int filename_len;
- long filetime = 0, fileatime = 0;
+ size_t filename_len;
+ zend_long filetime = 0, fileatime = 0;
int ret, argc = ZEND_NUM_ARGS();
FILE *file;
struct utimbuf newtimebuf;
@@ -829,7 +829,7 @@ PHP_FUNCTION(clearstatcache)
{
zend_bool clear_realpath_cache = 0;
char *filename = NULL;
- int filename_len = 0;
+ size_t filename_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bp", &clear_realpath_cache, &filename, &filename_len) == FAILURE) {
return;
@@ -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((zend_long)ssb.sb.st_mode);
case FS_INODE:
- RETURN_LONG((long)ssb.sb.st_ino);
+ RETURN_LONG((zend_long)ssb.sb.st_ino);
case FS_SIZE:
- RETURN_LONG((long)ssb.sb.st_size);
+ RETURN_LONG((zend_long)ssb.sb.st_size);
case FS_OWNER:
- RETURN_LONG((long)ssb.sb.st_uid);
+ RETURN_LONG((zend_long)ssb.sb.st_uid);
case FS_GROUP:
- RETURN_LONG((long)ssb.sb.st_gid);
+ RETURN_LONG((zend_long)ssb.sb.st_gid);
case FS_ATIME:
- RETURN_LONG((long)ssb.sb.st_atime);
+ RETURN_LONG((zend_long)ssb.sb.st_atime);
case FS_MTIME:
- RETURN_LONG((long)ssb.sb.st_mtime);
+ RETURN_LONG((zend_long)ssb.sb.st_mtime);
case FS_CTIME:
- RETURN_LONG((long)ssb.sb.st_ctime);
+ RETURN_LONG((zend_long)ssb.sb.st_ctime);
case FS_TYPE:
if (S_ISLNK(ssb.sb.st_mode)) {
RETURN_STRING("link");
@@ -1019,7 +1019,18 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int typ
ZVAL_LONG(&stat_uid, stat_sb->st_uid);
ZVAL_LONG(&stat_gid, stat_sb->st_gid);
#ifdef HAVE_ST_RDEV
+# ifdef PHP_WIN32
+ /* It is unsigned, so if a negative came from userspace, it'll
+ convert to UINT_MAX, but we wan't to keep the userspace value.
+ Almost the same as in php_if_fstat. */
+ if ((int)stat_sb->st_rdev < 0) {
+ ZVAL_LONG(&stat_rdev, (int)stat_sb->st_rdev);
+ } else {
ZVAL_LONG(&stat_rdev, stat_sb->st_rdev);
+ }
+# else
+ ZVAL_LONG(&stat_rdev, stat_sb->st_rdev);
+# endif
#else
ZVAL_LONG(&stat_rdev, -1);
#endif
@@ -1081,7 +1092,7 @@ PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int typ
# define FileFunction(name, funcnum) \
void name(INTERNAL_FUNCTION_PARAMETERS) { \
char *filename; \
- int filename_len; \
+ size_t filename_len; \
\
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p", &filename, &filename_len) == FAILURE) { \
return; \
@@ -1093,7 +1104,7 @@ void name(INTERNAL_FUNCTION_PARAMETERS) { \
# define FileFunction(name, funcnum) \
void name(INTERNAL_FUNCTION_PARAMETERS) { \
char *filename; \
- int filename_len; \
+ size_t filename_len; \
\
ZEND_PARSE_PARAMETERS_START(1, 1) \
Z_PARAM_PATH(filename, filename_len) \
@@ -1223,19 +1234,19 @@ PHP_FUNCTION(realpath_cache_get)
array_init(&entry);
/* bucket->key is unsigned long */
- if (LONG_MAX >= bucket->key) {
- add_assoc_long(&entry, "key", bucket->key);
+ if (ZEND_LONG_MAX >= bucket->key) {
+ add_assoc_long_ex(&entry, "key", sizeof("key") - 1, bucket->key);
} else {
- add_assoc_double(&entry, "key", (double)bucket->key);
+ add_assoc_double_ex(&entry, "key", sizeof("key") - 1, (double)bucket->key);
}
- add_assoc_bool(&entry, "is_dir", bucket->is_dir);
- add_assoc_stringl(&entry, "realpath", bucket->realpath, bucket->realpath_len);
- add_assoc_long(&entry, "expires", bucket->expires);
+ add_assoc_bool_ex(&entry, "is_dir", sizeof("is_dir") - 1, bucket->is_dir);
+ add_assoc_stringl_ex(&entry, "realpath", sizeof("realpath") - 1, bucket->realpath, bucket->realpath_len);
+ add_assoc_long_ex(&entry, "expires", sizeof("expires") - 1, bucket->expires);
#ifdef PHP_WIN32
- add_assoc_bool(&entry, "is_rvalid", bucket->is_rvalid);
- add_assoc_bool(&entry, "is_wvalid", bucket->is_wvalid);
- add_assoc_bool(&entry, "is_readable", bucket->is_readable);
- add_assoc_bool(&entry, "is_writable", bucket->is_writable);
+ add_assoc_bool_ex(&entry, "is_rvalid", sizeof("is_rvalid") - 1, bucket->is_rvalid);
+ add_assoc_bool_ex(&entry, "is_wvalid", sizeof("is_wvalid") - 1, bucket->is_wvalid);
+ add_assoc_bool_ex(&entry, "is_readable", sizeof("is_readable") - 1, bucket->is_readable);
+ add_assoc_bool_ex(&entry, "is_writable", sizeof("is_writable") - 1, bucket->is_writable);
#endif
zend_hash_str_update(Z_ARRVAL_P(return_value), bucket->path, bucket->path_len, &entry);
bucket = bucket->next;