PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/standard - filestat.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 312 385 81.0 %
Date: 2016-09-18 Functions: 37 39 94.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2016 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Author:  Jim Winstead <jimw@php.net>                                 |
      16             :    +----------------------------------------------------------------------+
      17             :  */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #include "php.h"
      22             : #include "fopen_wrappers.h"
      23             : #include "php_globals.h"
      24             : 
      25             : #include <stdlib.h>
      26             : #include <sys/stat.h>
      27             : #include <string.h>
      28             : #include <errno.h>
      29             : #include <ctype.h>
      30             : #include <time.h>
      31             : 
      32             : #if HAVE_UNISTD_H
      33             : # include <unistd.h>
      34             : #endif
      35             : 
      36             : #if HAVE_SYS_PARAM_H
      37             : # include <sys/param.h>
      38             : #endif
      39             : 
      40             : #if HAVE_SYS_VFS_H
      41             : # include <sys/vfs.h>
      42             : #endif
      43             : 
      44             : #ifdef OS2
      45             : #  define INCL_DOS
      46             : #  include <os2.h>
      47             : #endif
      48             : 
      49             : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
      50             : # include <sys/statvfs.h>
      51             : #elif defined(HAVE_SYS_STATFS_H) && defined(HAVE_STATFS)
      52             : # include <sys/statfs.h>
      53             : #elif defined(HAVE_SYS_MOUNT_H) && defined(HAVE_STATFS)
      54             : # include <sys/mount.h>
      55             : #endif
      56             : 
      57             : #if HAVE_PWD_H
      58             : # ifdef PHP_WIN32
      59             : #  include "win32/pwd.h"
      60             : # else
      61             : #  include <pwd.h>
      62             : # endif
      63             : #endif
      64             : 
      65             : #if HAVE_GRP_H
      66             : # ifdef PHP_WIN32
      67             : #  include "win32/grp.h"
      68             : # else
      69             : #  include <grp.h>
      70             : # endif
      71             : #endif
      72             : 
      73             : #if HAVE_UTIME
      74             : # ifdef PHP_WIN32
      75             : #  include <sys/utime.h>
      76             : # else
      77             : #  include <utime.h>
      78             : # endif
      79             : #endif
      80             : 
      81             : #ifdef PHP_WIN32
      82             : #include "win32/winutil.h"
      83             : #endif
      84             : 
      85             : #include "basic_functions.h"
      86             : #include "php_filestat.h"
      87             : 
      88       23876 : PHP_RINIT_FUNCTION(filestat) /* {{{ */
      89             : {
      90       23876 :         BG(CurrentStatFile)=NULL;
      91       23876 :         BG(CurrentLStatFile)=NULL;
      92       23876 :         return SUCCESS;
      93             : }
      94             : /* }}} */
      95             : 
      96       23919 : PHP_RSHUTDOWN_FUNCTION(filestat) /* {{{ */
      97             : {
      98       23919 :         if (BG(CurrentStatFile)) {
      99         509 :                 efree (BG(CurrentStatFile));
     100         509 :                 BG(CurrentStatFile) = NULL;
     101             :         }
     102       23919 :         if (BG(CurrentLStatFile)) {
     103          35 :                 efree (BG(CurrentLStatFile));
     104          35 :                 BG(CurrentLStatFile) = NULL;
     105             :         }
     106       23919 :         return SUCCESS;
     107             : }
     108             : /* }}} */
     109             : 
     110          19 : static int php_disk_total_space(char *path, double *space) /* {{{ */
     111             : #if defined(WINDOWS) /* {{{ */
     112             : {
     113             :         ULARGE_INTEGER FreeBytesAvailableToCaller;
     114             :         ULARGE_INTEGER TotalNumberOfBytes;
     115             :         ULARGE_INTEGER TotalNumberOfFreeBytes;
     116             :         PHP_WIN32_IOUTIL_INIT_W(path)
     117             : 
     118             :         if (GetDiskFreeSpaceExW(pathw, &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes) == 0) {
     119             :                 php_error_docref(NULL, E_WARNING, "%s", php_win_err());
     120             :                 PHP_WIN32_IOUTIL_CLEANUP_W()
     121             :                 return FAILURE;
     122             :         }
     123             : 
     124             :         /* i know - this is ugly, but i works <thies@thieso.net> */
     125             :         *space = TotalNumberOfBytes.HighPart * (double) (((zend_ulong)1) << 31) * 2.0 + TotalNumberOfBytes.LowPart;
     126             : 
     127             :         PHP_WIN32_IOUTIL_CLEANUP_W()
     128             : 
     129             :         return SUCCESS;
     130             : }
     131             : /* }}} */
     132             : #elif defined(OS2) /* {{{ */
     133             : {
     134             :         double bytestotal = 0;
     135             :         FSALLOCATE fsinfo;
     136             :         char drive = path[0] & 95;
     137             : 
     138             :         if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) {
     139             :                 bytestotal = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnit;
     140             :                 *space = bytestotal;
     141             :                 return SUCCESS;
     142             :         }
     143             :         return FAILURE;
     144             : }
     145             : /* }}} */
     146             : #else /* {{{ if !defined(OS2) && !defined(WINDOWS) */
     147             : {
     148          19 :         double bytestotal = 0;
     149             : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
     150             :         struct statvfs buf;
     151             : #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
     152             :         struct statfs buf;
     153             : #endif
     154             : 
     155             : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
     156          19 :         if (statvfs(path, &buf)) {
     157           3 :                 php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
     158           3 :                 return FAILURE;
     159             :         }
     160          16 :         if (buf.f_frsize) {
     161          16 :                 bytestotal = (((double)buf.f_blocks) * ((double)buf.f_frsize));
     162             :         } else {
     163           0 :                 bytestotal = (((double)buf.f_blocks) * ((double)buf.f_bsize));
     164             :         }
     165             : 
     166             : #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
     167             :         if (statfs(path, &buf)) {
     168             :                 php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
     169             :                 return FAILURE;
     170             :         }
     171             :         bytestotal = (((double)buf.f_bsize) * ((double)buf.f_blocks));
     172             : #endif
     173             : 
     174          16 :         *space = bytestotal;
     175          16 :         return SUCCESS;
     176             : }
     177             : #endif
     178             : /* }}} */
     179             : /* }}} */
     180             : 
     181             : /* {{{ proto float disk_total_space(string path)
     182             :    Get total disk space for filesystem that path is on */
     183          26 : PHP_FUNCTION(disk_total_space)
     184             : {
     185             :         double bytestotal;
     186             :         char *path;
     187             :         size_t path_len;
     188             : 
     189          26 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &path, &path_len) == FAILURE) {
     190           7 :                 return;
     191             :         }
     192             : 
     193          19 :         if (php_check_open_basedir(path)) {
     194           0 :                 RETURN_FALSE;
     195             :         }
     196             : 
     197          19 :         if (php_disk_total_space(path, &bytestotal) == SUCCESS) {
     198          16 :                 RETURN_DOUBLE(bytestotal);
     199             :         }
     200           3 :         RETURN_FALSE;
     201             : }
     202             : /* }}} */
     203             : 
     204          33 : static int php_disk_free_space(char *path, double *space) /* {{{ */
     205             : #if defined(WINDOWS) /* {{{ */
     206             : {
     207             :         ULARGE_INTEGER FreeBytesAvailableToCaller;
     208             :         ULARGE_INTEGER TotalNumberOfBytes;
     209             :         ULARGE_INTEGER TotalNumberOfFreeBytes;
     210             :         PHP_WIN32_IOUTIL_INIT_W(path)
     211             : 
     212             :         if (GetDiskFreeSpaceExW(pathw, &FreeBytesAvailableToCaller, &TotalNumberOfBytes, &TotalNumberOfFreeBytes) == 0) {
     213             :                 php_error_docref(NULL, E_WARNING, "%s", php_win_err());
     214             :                 PHP_WIN32_IOUTIL_CLEANUP_W()
     215             :                 return FAILURE;
     216             :         }
     217             : 
     218             :         /* i know - this is ugly, but i works <thies@thieso.net> */
     219             :         *space = FreeBytesAvailableToCaller.HighPart * (double) (((zend_ulong)1) << 31) * 2.0 + FreeBytesAvailableToCaller.LowPart;
     220             : 
     221             :         PHP_WIN32_IOUTIL_CLEANUP_W()
     222             : 
     223             :         return SUCCESS;
     224             : }
     225             : /* }}} */
     226             : #elif defined(OS2) /* {{{ */
     227             : {
     228             :         double bytesfree = 0;
     229             :         FSALLOCATE fsinfo;
     230             :         char drive = path[0] & 95;
     231             : 
     232             :         if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) {
     233             :                 bytesfree = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnitAvail;
     234             :                 *space = bytesfree;
     235             :                 return SUCCESS;
     236             :         }
     237             :         return FAILURE;
     238             : }
     239             : /* }}} */
     240             : #else /* {{{ if !defined(OS2) && !defined(WINDOWS) */
     241             : {
     242          33 :         double bytesfree = 0;
     243             : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
     244             :         struct statvfs buf;
     245             : #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
     246             :         struct statfs buf;
     247             : #endif
     248             : 
     249             : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
     250          33 :         if (statvfs(path, &buf)) {
     251           4 :                 php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
     252           4 :                 return FAILURE;
     253             :         }
     254          29 :         if (buf.f_frsize) {
     255          29 :                 bytesfree = (((double)buf.f_bavail) * ((double)buf.f_frsize));
     256             :         } else {
     257           0 :                 bytesfree = (((double)buf.f_bavail) * ((double)buf.f_bsize));
     258             :         }
     259             : #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
     260             :         if (statfs(path, &buf)) {
     261             :                 php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
     262             :                 return FAILURE;
     263             :         }
     264             : #ifdef NETWARE
     265             :         bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bfree));
     266             : #else
     267             :         bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bavail));
     268             : #endif
     269             : #endif
     270             : 
     271          29 :         *space = bytesfree;
     272          29 :         return SUCCESS;
     273             : }
     274             : #endif
     275             : /* }}} */
     276             : /* }}} */
     277             : 
     278             : /* {{{ proto float disk_free_space(string path)
     279             :    Get free disk space for filesystem that path is on */
     280          54 : PHP_FUNCTION(disk_free_space)
     281             : {
     282             :         double bytesfree;
     283             :         char *path;
     284             :         size_t path_len;
     285             : 
     286          54 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &path, &path_len) == FAILURE) {
     287          13 :                 return;
     288             :         }
     289             : 
     290          41 :         if (php_check_open_basedir(path)) {
     291           8 :                 RETURN_FALSE;
     292             :         }
     293             : 
     294          33 :         if (php_disk_free_space(path, &bytesfree) == SUCCESS) {
     295          29 :                 RETURN_DOUBLE(bytesfree);
     296             :         }
     297           4 :         RETURN_FALSE;
     298             : }
     299             : /* }}} */
     300             : 
     301             : #if !defined(WINDOWS) && !defined(NETWARE)
     302           0 : PHPAPI int php_get_gid_by_name(const char *name, gid_t *gid)
     303             : {
     304             : #if defined(ZTS) && defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX)
     305             :                 struct group gr;
     306             :                 struct group *retgrptr;
     307             :                 long grbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
     308             :                 char *grbuf;
     309             : 
     310             :                 if (grbuflen < 1) {
     311             :                         return FAILURE;
     312             :                 }
     313             : 
     314             :                 grbuf = emalloc(grbuflen);
     315             :                 if (getgrnam_r(name, &gr, grbuf, grbuflen, &retgrptr) != 0 || retgrptr == NULL) {
     316             :                         efree(grbuf);
     317             :                         return FAILURE;
     318             :                 }
     319             :                 efree(grbuf);
     320             :                 *gid = gr.gr_gid;
     321             : #else
     322           0 :                 struct group *gr = getgrnam(name);
     323             : 
     324           0 :                 if (!gr) {
     325           0 :                         return FAILURE;
     326             :                 }
     327           0 :                 *gid = gr->gr_gid;
     328             : #endif
     329           0 :                 return SUCCESS;
     330             : }
     331             : #endif
     332             : 
     333           4 : static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */
     334             : {
     335             :         char *filename;
     336             :         size_t filename_len;
     337             :         zval *group;
     338             : #if !defined(WINDOWS)
     339             :         gid_t gid;
     340             :         int ret;
     341             : #endif
     342             :         php_stream_wrapper *wrapper;
     343             : 
     344           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "pz/", &filename, &filename_len, &group) == FAILURE) {
     345           0 :                 RETURN_FALSE;
     346             :         }
     347             : 
     348           4 :         wrapper = php_stream_locate_url_wrapper(filename, NULL, 0);
     349           4 :         if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) {
     350           2 :                 if(wrapper && wrapper->wops->stream_metadata) {
     351             :                         int option;
     352             :                         void *value;
     353           4 :                         if (Z_TYPE_P(group) == IS_LONG) {
     354           1 :                                 option = PHP_STREAM_META_GROUP;
     355           1 :                                 value = &Z_LVAL_P(group);
     356           2 :                         } else if (Z_TYPE_P(group) == IS_STRING) {
     357           1 :                                 option = PHP_STREAM_META_GROUP_NAME;
     358           1 :                                 value = Z_STRVAL_P(group);
     359             :                         } else {
     360           0 :                                 php_error_docref(NULL, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(group));
     361           0 :                                 RETURN_FALSE;
     362             :                         }
     363           2 :                         if(wrapper->wops->stream_metadata(wrapper, filename, option, value, NULL)) {
     364           0 :                                 RETURN_TRUE;
     365             :                         } else {
     366           2 :                                 RETURN_FALSE;
     367             :                         }
     368             :                 } else {
     369             : #if !defined(WINDOWS)
     370             : /* On Windows, we expect regular chgrp to fail silently by default */
     371           0 :                         php_error_docref(NULL, E_WARNING, "Can not call chgrp() for a non-standard stream");
     372             : #endif
     373           0 :                         RETURN_FALSE;
     374             :                 }
     375             :         }
     376             : 
     377             : #if defined(WINDOWS)
     378             :         /* We have no native chgrp on Windows, nothing left to do if stream doesn't have own implementation */
     379             :         RETURN_FALSE;
     380             : #else
     381           4 :         if (Z_TYPE_P(group) == IS_LONG) {
     382           1 :                 gid = (gid_t)Z_LVAL_P(group);
     383           2 :         } else if (Z_TYPE_P(group) == IS_STRING) {
     384           0 :                 if(php_get_gid_by_name(Z_STRVAL_P(group), &gid) != SUCCESS) {
     385           0 :                         php_error_docref(NULL, E_WARNING, "Unable to find gid for %s", Z_STRVAL_P(group));
     386           0 :                         RETURN_FALSE;
     387             :                 }
     388             :         } else {
     389           1 :                 php_error_docref(NULL, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(group));
     390           1 :                 RETURN_FALSE;
     391             :         }
     392             : 
     393             :         /* Check the basedir */
     394           1 :         if (php_check_open_basedir(filename)) {
     395           0 :                 RETURN_FALSE;
     396             :         }
     397             : 
     398           1 :         if (do_lchgrp) {
     399             : #if HAVE_LCHOWN
     400           1 :                 ret = VCWD_LCHOWN(filename, -1, gid);
     401             : #endif
     402             :         } else {
     403           0 :                 ret = VCWD_CHOWN(filename, -1, gid);
     404             :         }
     405           1 :         if (ret == -1) {
     406           0 :                 php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
     407           0 :                 RETURN_FALSE;
     408             :         }
     409           1 :         RETURN_TRUE;
     410             : #endif
     411             : }
     412             : /* }}} */
     413             : 
     414             : #ifndef NETWARE
     415             : /* {{{ proto bool chgrp(string filename, mixed group)
     416             :    Change file group */
     417           3 : PHP_FUNCTION(chgrp)
     418             : {
     419           3 :         php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
     420           3 : }
     421             : /* }}} */
     422             : 
     423             : /* {{{ proto bool lchgrp(string filename, mixed group)
     424             :    Change symlink group */
     425             : #if HAVE_LCHOWN
     426           1 : PHP_FUNCTION(lchgrp)
     427             : {
     428             : # if !defined(WINDOWS)
     429           1 :         php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
     430             : # else
     431             :         RETURN_FALSE;
     432             : # endif
     433           1 : }
     434             : #endif
     435             : /* }}} */
     436             : #endif /* !NETWARE */
     437             : 
     438             : #if !defined(WINDOWS) && !defined(NETWARE)
     439           0 : PHPAPI uid_t php_get_uid_by_name(const char *name, uid_t *uid)
     440             : {
     441             : #if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R)
     442             :                 struct passwd pw;
     443             :                 struct passwd *retpwptr = NULL;
     444             :                 long pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
     445             :                 char *pwbuf;
     446             : 
     447             :                 if (pwbuflen < 1) {
     448             :                         return FAILURE;
     449             :                 }
     450             : 
     451             :                 pwbuf = emalloc(pwbuflen);
     452             :                 if (getpwnam_r(name, &pw, pwbuf, pwbuflen, &retpwptr) != 0 || retpwptr == NULL) {
     453             :                         efree(pwbuf);
     454             :                         return FAILURE;
     455             :                 }
     456             :                 efree(pwbuf);
     457             :                 *uid = pw.pw_uid;
     458             : #else
     459           0 :                 struct passwd *pw = getpwnam(name);
     460             : 
     461           0 :                 if (!pw) {
     462           0 :                         return FAILURE;
     463             :                 }
     464           0 :                 *uid = pw->pw_uid;
     465             : #endif
     466           0 :                 return SUCCESS;
     467             : }
     468             : #endif
     469             : 
     470          10 : static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */
     471             : {
     472             :         char *filename;
     473             :         size_t filename_len;
     474             :         zval *user;
     475             : #if !defined(WINDOWS)
     476             :         uid_t uid;
     477             :         int ret;
     478             : #endif
     479             :         php_stream_wrapper *wrapper;
     480             : 
     481          10 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "pz/", &filename, &filename_len, &user) == FAILURE) {
     482           4 :                 return;
     483             :         }
     484             : 
     485           6 :         wrapper = php_stream_locate_url_wrapper(filename, NULL, 0);
     486           6 :         if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) {
     487           2 :                 if(wrapper && wrapper->wops->stream_metadata) {
     488             :                         int option;
     489             :                         void *value;
     490           4 :                         if (Z_TYPE_P(user) == IS_LONG) {
     491           1 :                                 option = PHP_STREAM_META_OWNER;
     492           1 :                                 value = &Z_LVAL_P(user);
     493           2 :                         } else if (Z_TYPE_P(user) == IS_STRING) {
     494           1 :                                 option = PHP_STREAM_META_OWNER_NAME;
     495           1 :                                 value = Z_STRVAL_P(user);
     496             :                         } else {
     497           0 :                                 php_error_docref(NULL, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(user));
     498           0 :                                 RETURN_FALSE;
     499             :                         }
     500           2 :                         if(wrapper->wops->stream_metadata(wrapper, filename, option, value, NULL)) {
     501           0 :                                 RETURN_TRUE;
     502             :                         } else {
     503           2 :                                 RETURN_FALSE;
     504             :                         }
     505             :                 } else {
     506             : #if !defined(WINDOWS)
     507             : /* On Windows, we expect regular chown to fail silently by default */
     508           0 :                         php_error_docref(NULL, E_WARNING, "Can not call chown() for a non-standard stream");
     509             : #endif
     510           0 :                         RETURN_FALSE;
     511             :                 }
     512             :         }
     513             : 
     514             : #if defined(WINDOWS)
     515             :         /* We have no native chown on Windows, nothing left to do if stream doesn't have own implementation */
     516             :         RETURN_FALSE;
     517             : #else
     518             : 
     519           8 :         if (Z_TYPE_P(user) == IS_LONG) {
     520           3 :                 uid = (uid_t)Z_LVAL_P(user);
     521           2 :         } else if (Z_TYPE_P(user) == IS_STRING) {
     522           0 :                 if(php_get_uid_by_name(Z_STRVAL_P(user), &uid) != SUCCESS) {
     523           0 :                         php_error_docref(NULL, E_WARNING, "Unable to find uid for %s", Z_STRVAL_P(user));
     524           0 :                         RETURN_FALSE;
     525             :                 }
     526             :         } else {
     527           1 :                 php_error_docref(NULL, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(user));
     528           1 :                 RETURN_FALSE;
     529             :         }
     530             : 
     531             :         /* Check the basedir */
     532           3 :         if (php_check_open_basedir(filename)) {
     533           0 :                 RETURN_FALSE;
     534             :         }
     535             : 
     536           3 :         if (do_lchown) {
     537             : #if HAVE_LCHOWN
     538           3 :                 ret = VCWD_LCHOWN(filename, uid, -1);
     539             : #endif
     540             :         } else {
     541           0 :                 ret = VCWD_CHOWN(filename, uid, -1);
     542             :         }
     543           3 :         if (ret == -1) {
     544           2 :                 php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
     545           2 :                 RETURN_FALSE;
     546             :         }
     547           1 :         RETURN_TRUE;
     548             : #endif
     549             : }
     550             : /* }}} */
     551             : 
     552             : 
     553             : #ifndef NETWARE
     554             : /* {{{ proto bool chown (string filename, mixed user)
     555             :    Change file owner */
     556           3 : PHP_FUNCTION(chown)
     557             : {
     558           3 :         php_do_chown(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
     559           3 : }
     560             : /* }}} */
     561             : 
     562             : /* {{{ proto bool chown (string filename, mixed user)
     563             :    Change file owner */
     564             : #if HAVE_LCHOWN
     565           7 : PHP_FUNCTION(lchown)
     566             : {
     567             : # if !defined(WINDOWS)
     568           7 :         RETVAL_TRUE;
     569           7 :         php_do_chown(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
     570             : # else
     571             :         RETURN_FALSE;
     572             : # endif
     573           7 : }
     574             : #endif
     575             : /* }}} */
     576             : #endif /* !NETWARE */
     577             : 
     578             : /* {{{ proto bool chmod(string filename, int mode)
     579             :    Change file mode */
     580       10500 : PHP_FUNCTION(chmod)
     581             : {
     582             :         char *filename;
     583             :         size_t filename_len;
     584             :         zend_long mode;
     585             :         int ret;
     586             :         mode_t imode;
     587             :         php_stream_wrapper *wrapper;
     588             : 
     589       10500 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "pl", &filename, &filename_len, &mode) == FAILURE) {
     590          31 :                 return;
     591             :         }
     592             : 
     593       10469 :         wrapper = php_stream_locate_url_wrapper(filename, NULL, 0);
     594       10469 :         if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) {
     595           1 :                 if(wrapper && wrapper->wops->stream_metadata) {
     596           1 :                         if(wrapper->wops->stream_metadata(wrapper, filename, PHP_STREAM_META_ACCESS, &mode, NULL)) {
     597           0 :                                 RETURN_TRUE;
     598             :                         } else {
     599           1 :                                 RETURN_FALSE;
     600             :                         }
     601             :                 } else {
     602           0 :                         php_error_docref(NULL, E_WARNING, "Can not call chmod() for a non-standard stream");
     603           0 :                         RETURN_FALSE;
     604             :                 }
     605             :         }
     606             : 
     607             :         /* Check the basedir */
     608       10468 :         if (php_check_open_basedir(filename)) {
     609           8 :                 RETURN_FALSE;
     610             :         }
     611             : 
     612       10460 :         imode = (mode_t) mode;
     613             : 
     614       10460 :         ret = VCWD_CHMOD(filename, imode);
     615       10460 :         if (ret == -1) {
     616          27 :                 php_error_docref(NULL, E_WARNING, "%s", strerror(errno));
     617          27 :                 RETURN_FALSE;
     618             :         }
     619       10433 :         RETURN_TRUE;
     620             : }
     621             : /* }}} */
     622             : 
     623             : #if HAVE_UTIME
     624             : /* {{{ proto bool touch(string filename [, int time [, int atime]])
     625             :    Set modification time of file */
     626         301 : PHP_FUNCTION(touch)
     627             : {
     628             :         char *filename;
     629             :         size_t filename_len;
     630         301 :         zend_long filetime = 0, fileatime = 0;
     631         301 :         int ret, argc = ZEND_NUM_ARGS();
     632             :         FILE *file;
     633             :         struct utimbuf newtimebuf;
     634         301 :         struct utimbuf *newtime = &newtimebuf;
     635             :         php_stream_wrapper *wrapper;
     636             : 
     637         301 :         if (zend_parse_parameters(argc, "p|ll", &filename, &filename_len, &filetime, &fileatime) == FAILURE) {
     638          31 :                 return;
     639             :         }
     640             : 
     641         270 :         if (!filename_len) {
     642           3 :                 RETURN_FALSE;
     643             :         }
     644             : 
     645         267 :         switch (argc) {
     646             :                 case 1:
     647             : #ifdef HAVE_UTIME_NULL
     648         210 :                         newtime = NULL;
     649             : #else
     650             :                         newtime->modtime = newtime->actime = time(NULL);
     651             : #endif
     652         210 :                         break;
     653             :                 case 2:
     654          10 :                         newtime->modtime = newtime->actime = filetime;
     655          10 :                         break;
     656             :                 case 3:
     657          47 :                         newtime->modtime = filetime;
     658          47 :                         newtime->actime = fileatime;
     659          47 :                         break;
     660             :                 default:
     661             :                         /* Never reached */
     662           0 :                         WRONG_PARAM_COUNT;
     663             :         }
     664             : 
     665         267 :         wrapper = php_stream_locate_url_wrapper(filename, NULL, 0);
     666         267 :         if(wrapper != &php_plain_files_wrapper || strncasecmp("file://", filename, 7) == 0) {
     667           4 :                 if(wrapper && wrapper->wops->stream_metadata) {
     668           4 :                         if(wrapper->wops->stream_metadata(wrapper, filename, PHP_STREAM_META_TOUCH, newtime, NULL)) {
     669           1 :                                 RETURN_TRUE;
     670             :                         } else {
     671           3 :                                 RETURN_FALSE;
     672             :                         }
     673             :                 } else {
     674             :                         php_stream *stream;
     675           0 :                         if(argc > 1) {
     676           0 :                                 php_error_docref(NULL, E_WARNING, "Can not call touch() for a non-standard stream");
     677           0 :                                 RETURN_FALSE;
     678             :                         }
     679           0 :                         stream = php_stream_open_wrapper_ex(filename, "c", REPORT_ERRORS, NULL, NULL);
     680           0 :                         if(stream != NULL) {
     681           0 :                                 php_stream_close(stream);
     682           0 :                                 RETURN_TRUE;
     683             :                         } else {
     684           0 :                                 RETURN_FALSE;
     685             :                         }
     686             :                 }
     687             :         }
     688             : 
     689             :         /* Check the basedir */
     690         263 :         if (php_check_open_basedir(filename)) {
     691           8 :                 RETURN_FALSE;
     692             :         }
     693             : 
     694             :         /* create the file if it doesn't exist already */
     695         255 :         if (VCWD_ACCESS(filename, F_OK) != 0) {
     696         160 :                 file = VCWD_FOPEN(filename, "w");
     697         160 :                 if (file == NULL) {
     698           8 :                         php_error_docref(NULL, E_WARNING, "Unable to create file %s because %s", filename, strerror(errno));
     699           8 :                         RETURN_FALSE;
     700             :                 }
     701         152 :                 fclose(file);
     702             :         }
     703             : 
     704         247 :         ret = VCWD_UTIME(filename, newtime);
     705         247 :         if (ret == -1) {
     706           0 :                 php_error_docref(NULL, E_WARNING, "Utime failed: %s", strerror(errno));
     707           0 :                 RETURN_FALSE;
     708             :         }
     709         247 :         RETURN_TRUE;
     710             : }
     711             : /* }}} */
     712             : #endif
     713             : 
     714             : /* {{{ php_clear_stat_cache()
     715             : */
     716       38480 : PHPAPI void php_clear_stat_cache(zend_bool clear_realpath_cache, const char *filename, int filename_len)
     717             : {
     718             :         /* always clear CurrentStatFile and CurrentLStatFile even if filename is not NULL
     719             :          * as it may contain outdated data (e.g. "nlink" for a directory when deleting a file
     720             :          * in this directory, as shown by lstat_stat_variation9.phpt) */
     721       38480 :         if (BG(CurrentStatFile)) {
     722       22712 :                 efree(BG(CurrentStatFile));
     723       22712 :                 BG(CurrentStatFile) = NULL;
     724             :         }
     725       38480 :         if (BG(CurrentLStatFile)) {
     726          45 :                 efree(BG(CurrentLStatFile));
     727          45 :                 BG(CurrentLStatFile) = NULL;
     728             :         }
     729       38480 :         if (clear_realpath_cache) {
     730       30194 :                 if (filename != NULL) {
     731           3 :                         realpath_cache_del(filename, filename_len);
     732             :                 } else {
     733       30191 :                         realpath_cache_clean();
     734             :                 }
     735             :         }
     736       38480 : }
     737             : /* }}} */
     738             : 
     739             : /* {{{ proto void clearstatcache([bool clear_realpath_cache[, string filename]])
     740             :    Clear file stat cache */
     741        8291 : PHP_FUNCTION(clearstatcache)
     742             : {
     743        8291 :         zend_bool  clear_realpath_cache = 0;
     744        8291 :         char      *filename             = NULL;
     745        8291 :         size_t     filename_len         = 0;
     746             : 
     747        8291 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "|bp", &clear_realpath_cache, &filename, &filename_len) == FAILURE) {
     748           1 :                 return;
     749             :         }
     750             : 
     751        8290 :         php_clear_stat_cache(clear_realpath_cache, filename, (int)filename_len);
     752             : }
     753             : /* }}} */
     754             : 
     755             : #define IS_LINK_OPERATION(__t) ((__t) == FS_TYPE || (__t) == FS_IS_LINK || (__t) == FS_LSTAT)
     756             : #define IS_EXISTS_CHECK(__t) ((__t) == FS_EXISTS  || (__t) == FS_IS_W || (__t) == FS_IS_R || (__t) == FS_IS_X || (__t) == FS_IS_FILE || (__t) == FS_IS_DIR || (__t) == FS_IS_LINK)
     757             : #define IS_ABLE_CHECK(__t) ((__t) == FS_IS_R || (__t) == FS_IS_W || (__t) == FS_IS_X)
     758             : #define IS_ACCESS_CHECK(__t) (IS_ABLE_CHECK(type) || (__t) == FS_EXISTS)
     759             : 
     760             : /* {{{ php_stat
     761             :  */
     762       71104 : PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int type, zval *return_value)
     763             : {
     764             :         zval stat_dev, stat_ino, stat_mode, stat_nlink, stat_uid, stat_gid, stat_rdev,
     765             :                  stat_size, stat_atime, stat_mtime, stat_ctime, stat_blksize, stat_blocks;
     766             :         zend_stat_t *stat_sb;
     767             :         php_stream_statbuf ssb;
     768       71104 :         int flags = 0, rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH; /* access rights defaults to other */
     769             :         char *stat_sb_names[13] = {
     770             :                 "dev", "ino", "mode", "nlink", "uid", "gid", "rdev",
     771             :                 "size", "atime", "mtime", "ctime", "blksize", "blocks"
     772       71104 :         };
     773             :         const char *local;
     774             :         php_stream_wrapper *wrapper;
     775             : 
     776       71104 :         if (!filename_length) {
     777          65 :                 RETURN_FALSE;
     778             :         }
     779             : 
     780       71039 :         if ((wrapper = php_stream_locate_url_wrapper(filename, &local, 0)) == &php_plain_files_wrapper && php_check_open_basedir(local)) {
     781         162 :                 RETURN_FALSE;
     782             :         }
     783             : 
     784       70877 :         if (IS_ACCESS_CHECK(type)) {
     785        6153 :                 if (wrapper == &php_plain_files_wrapper) {
     786             : 
     787        6069 :                         switch (type) {
     788             : #ifdef F_OK
     789             :                                 case FS_EXISTS:
     790        3695 :                                         RETURN_BOOL(VCWD_ACCESS(local, F_OK) == 0);
     791             :                                         break;
     792             : #endif
     793             : #ifdef W_OK
     794             :                                 case FS_IS_W:
     795        1088 :                                         RETURN_BOOL(VCWD_ACCESS(local, W_OK) == 0);
     796             :                                         break;
     797             : #endif
     798             : #ifdef R_OK
     799             :                                 case FS_IS_R:
     800         682 :                                         RETURN_BOOL(VCWD_ACCESS(local, R_OK) == 0);
     801             :                                         break;
     802             : #endif
     803             : #ifdef X_OK
     804             :                                 case FS_IS_X:
     805         604 :                                         RETURN_BOOL(VCWD_ACCESS(local, X_OK) == 0);
     806             :                                         break;
     807             : #endif
     808             :                         }
     809             :                 }
     810             :         }
     811             : 
     812       64808 :         if (IS_LINK_OPERATION(type)) {
     813        2797 :                 flags |= PHP_STREAM_URL_STAT_LINK;
     814             :         }
     815       64808 :         if (IS_EXISTS_CHECK(type)) {
     816       41755 :                 flags |= PHP_STREAM_URL_STAT_QUIET;
     817             :         }
     818             : 
     819       64808 :         if (php_stream_stat_path_ex((char *)filename, flags, &ssb, NULL)) {
     820             :                 /* Error Occurred */
     821        1045 :                 if (!IS_EXISTS_CHECK(type)) {
     822          91 :                         php_error_docref(NULL, E_WARNING, "%sstat failed for %s", IS_LINK_OPERATION(type) ? "L" : "", filename);
     823             :                 }
     824        1045 :                 RETURN_FALSE;
     825             :         }
     826             : 
     827       63763 :         stat_sb = &ssb.sb;
     828             : 
     829             : 
     830             : #ifndef NETWARE
     831       63763 :         if (type >= FS_IS_W && type <= FS_IS_X) {
     832          43 :                 if(ssb.sb.st_uid==getuid()) {
     833           0 :                         rmask=S_IRUSR;
     834           0 :                         wmask=S_IWUSR;
     835           0 :                         xmask=S_IXUSR;
     836          43 :                 } else if(ssb.sb.st_gid==getgid()) {
     837           0 :                         rmask=S_IRGRP;
     838           0 :                         wmask=S_IWGRP;
     839           0 :                         xmask=S_IXGRP;
     840             :                 } else {
     841             :                         int   groups, n, i;
     842             :                         gid_t *gids;
     843             : 
     844          43 :                         groups = getgroups(0, NULL);
     845          43 :                         if(groups > 0) {
     846          43 :                                 gids=(gid_t *)safe_emalloc(groups, sizeof(gid_t), 0);
     847          43 :                                 n=getgroups(groups, gids);
     848         129 :                                 for(i=0;i<n;i++){
     849          86 :                                         if(ssb.sb.st_gid==gids[i]) {
     850           0 :                                                 rmask=S_IRGRP;
     851           0 :                                                 wmask=S_IWGRP;
     852           0 :                                                 xmask=S_IXGRP;
     853           0 :                                                 break;
     854             :                                         }
     855             :                                 }
     856          43 :                                 efree(gids);
     857             :                         }
     858             :                 }
     859             :         }
     860             : #endif
     861             : 
     862             : #ifndef NETWARE
     863       63763 :         if (IS_ABLE_CHECK(type) && getuid() == 0) {
     864             :                 /* root has special perms on plain_wrapper
     865             :                    But we don't know about root under Netware */
     866           0 :                 if (wrapper == &php_plain_files_wrapper) {
     867           0 :                         if (type == FS_IS_X) {
     868           0 :                                 xmask = S_IXROOT;
     869             :                         } else {
     870           0 :                                 RETURN_TRUE;
     871             :                         }
     872             :                 }
     873             :         }
     874             : #endif
     875             : 
     876       63763 :         switch (type) {
     877             :         case FS_PERMS:
     878        6756 :                 RETURN_LONG((zend_long)ssb.sb.st_mode);
     879             :         case FS_INODE:
     880          43 :                 RETURN_LONG((zend_long)ssb.sb.st_ino);
     881             :         case FS_SIZE:
     882       15797 :                 RETURN_LONG((zend_long)ssb.sb.st_size);
     883             :         case FS_OWNER:
     884          55 :                 RETURN_LONG((zend_long)ssb.sb.st_uid);
     885             :         case FS_GROUP:
     886          26 :                 RETURN_LONG((zend_long)ssb.sb.st_gid);
     887             :         case FS_ATIME:
     888          37 :                 RETURN_LONG((zend_long)ssb.sb.st_atime);
     889             :         case FS_MTIME:
     890          64 :                 RETURN_LONG((zend_long)ssb.sb.st_mtime);
     891             :         case FS_CTIME:
     892          33 :                 RETURN_LONG((zend_long)ssb.sb.st_ctime);
     893             :         case FS_TYPE:
     894          25 :                 if (S_ISLNK(ssb.sb.st_mode)) {
     895           4 :                         RETURN_STRING("link");
     896             :                 }
     897          23 :                 switch(ssb.sb.st_mode & S_IFMT) {
     898           2 :                 case S_IFIFO: RETURN_STRING("fifo");
     899           2 :                 case S_IFCHR: RETURN_STRING("char");
     900          16 :                 case S_IFDIR: RETURN_STRING("dir");
     901           2 :                 case S_IFBLK: RETURN_STRING("block");
     902          24 :                 case S_IFREG: RETURN_STRING("file");
     903             : #if defined(S_IFSOCK) && !defined(ZEND_WIN32)&&!defined(__BEOS__)
     904           0 :                 case S_IFSOCK: RETURN_STRING("socket");
     905             : #endif
     906             :                 }
     907           0 :                 php_error_docref(NULL, E_NOTICE, "Unknown file type (%d)", ssb.sb.st_mode&S_IFMT);
     908           0 :                 RETURN_STRING("unknown");
     909             :         case FS_IS_W:
     910           9 :                 RETURN_BOOL((ssb.sb.st_mode & wmask) != 0);
     911             :         case FS_IS_R:
     912          18 :                 RETURN_BOOL((ssb.sb.st_mode&rmask)!=0);
     913             :         case FS_IS_X:
     914          16 :                 RETURN_BOOL((ssb.sb.st_mode&xmask)!=0 && !S_ISDIR(ssb.sb.st_mode));
     915             :         case FS_IS_FILE:
     916        4523 :                 RETURN_BOOL(S_ISREG(ssb.sb.st_mode));
     917             :         case FS_IS_DIR:
     918       33492 :                 RETURN_BOOL(S_ISDIR(ssb.sb.st_mode));
     919             :         case FS_IS_LINK:
     920        2724 :                 RETURN_BOOL(S_ISLNK(ssb.sb.st_mode));
     921             :         case FS_EXISTS:
     922          19 :                 RETURN_TRUE; /* the false case was done earlier */
     923             :         case FS_LSTAT:
     924             :                 /* FALLTHROUGH */
     925             :         case FS_STAT:
     926         126 :                 array_init(return_value);
     927             : 
     928         126 :                 ZVAL_LONG(&stat_dev, stat_sb->st_dev);
     929         126 :                 ZVAL_LONG(&stat_ino, stat_sb->st_ino);
     930         126 :                 ZVAL_LONG(&stat_mode, stat_sb->st_mode);
     931         126 :                 ZVAL_LONG(&stat_nlink, stat_sb->st_nlink);
     932         126 :                 ZVAL_LONG(&stat_uid, stat_sb->st_uid);
     933         126 :                 ZVAL_LONG(&stat_gid, stat_sb->st_gid);
     934             : #ifdef HAVE_ST_RDEV
     935             : # ifdef PHP_WIN32
     936             :         /* It is unsigned, so if a negative came from userspace, it'll
     937             :            convert to UINT_MAX, but we wan't to keep the userspace value.
     938             :            Almost the same as in php_if_fstat. */
     939             :         if ((int)stat_sb->st_rdev < 0) {
     940             :                 ZVAL_LONG(&stat_rdev, (int)stat_sb->st_rdev);
     941             :         } else {
     942             :                 ZVAL_LONG(&stat_rdev, stat_sb->st_rdev);
     943             :         }
     944             : # else
     945         126 :         ZVAL_LONG(&stat_rdev, stat_sb->st_rdev);
     946             : # endif
     947             : #else
     948             :                 ZVAL_LONG(&stat_rdev, -1);
     949             : #endif
     950         126 :                 ZVAL_LONG(&stat_size, stat_sb->st_size);
     951         126 :                 ZVAL_LONG(&stat_atime, stat_sb->st_atime);
     952         126 :                 ZVAL_LONG(&stat_mtime, stat_sb->st_mtime);
     953         126 :                 ZVAL_LONG(&stat_ctime, stat_sb->st_ctime);
     954             : #ifdef HAVE_ST_BLKSIZE
     955         126 :                 ZVAL_LONG(&stat_blksize, stat_sb->st_blksize);
     956             : #else
     957             :                 ZVAL_LONG(&stat_blksize,-1);
     958             : #endif
     959             : #ifdef HAVE_ST_BLOCKS
     960         126 :                 ZVAL_LONG(&stat_blocks, stat_sb->st_blocks);
     961             : #else
     962             :                 ZVAL_LONG(&stat_blocks,-1);
     963             : #endif
     964             :                 /* Store numeric indexes in proper order */
     965         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_dev);
     966         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_ino);
     967         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_mode);
     968         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_nlink);
     969         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_uid);
     970         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_gid);
     971             : 
     972         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_rdev);
     973         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_size);
     974         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_atime);
     975         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_mtime);
     976         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_ctime);
     977         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_blksize);
     978         126 :                 zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &stat_blocks);
     979             : 
     980             :                 /* Store string indexes referencing the same zval*/
     981         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[0], strlen(stat_sb_names[0]), &stat_dev);
     982         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[1], strlen(stat_sb_names[1]), &stat_ino);
     983         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[2], strlen(stat_sb_names[2]), &stat_mode);
     984         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[3], strlen(stat_sb_names[3]), &stat_nlink);
     985         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[4], strlen(stat_sb_names[4]), &stat_uid);
     986         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[5], strlen(stat_sb_names[5]), &stat_gid);
     987         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[6], strlen(stat_sb_names[6]), &stat_rdev);
     988         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[7], strlen(stat_sb_names[7]), &stat_size);
     989         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[8], strlen(stat_sb_names[8]), &stat_atime);
     990         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[9], strlen(stat_sb_names[9]), &stat_mtime);
     991         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[10], strlen(stat_sb_names[10]), &stat_ctime);
     992         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[11], strlen(stat_sb_names[11]), &stat_blksize);
     993         126 :                 zend_hash_str_update(Z_ARRVAL_P(return_value), stat_sb_names[12], strlen(stat_sb_names[12]), &stat_blocks);
     994             : 
     995         126 :                 return;
     996             :         }
     997           0 :         php_error_docref(NULL, E_WARNING, "Didn't understand stat call");
     998           0 :         RETURN_FALSE;
     999             : }
    1000             : /* }}} */
    1001             : 
    1002             : /* another quickie macro to make defining similar functions easier */
    1003             : /* {{{ FileFunction(name, funcnum) */
    1004             : #define FileFunction(name, funcnum) \
    1005             : void name(INTERNAL_FUNCTION_PARAMETERS) { \
    1006             :         char *filename; \
    1007             :         size_t filename_len; \
    1008             :         \
    1009             :         ZEND_PARSE_PARAMETERS_START(1, 1) \
    1010             :                 Z_PARAM_PATH(filename, filename_len) \
    1011             :         ZEND_PARSE_PARAMETERS_END(); \
    1012             :         \
    1013             :         php_stat(filename, (php_stat_len) filename_len, funcnum, return_value); \
    1014             : }
    1015             : /* }}} */
    1016             : 
    1017             : /* {{{ proto int fileperms(string filename)
    1018             :    Get file permissions */
    1019       20340 : FileFunction(PHP_FN(fileperms), FS_PERMS)
    1020             : /* }}} */
    1021             : 
    1022             : /* {{{ proto int fileinode(string filename)
    1023             :    Get file inode */
    1024         206 : FileFunction(PHP_FN(fileinode), FS_INODE)
    1025             : /* }}} */
    1026             : 
    1027             : /* {{{ proto int filesize(string filename)
    1028             :    Get file size */
    1029       47438 : FileFunction(PHP_FN(filesize), FS_SIZE)
    1030             : /* }}} */
    1031             : 
    1032             : /* {{{ proto int fileowner(string filename)
    1033             :    Get file owner */
    1034         242 : FileFunction(PHP_FN(fileowner), FS_OWNER)
    1035             : /* }}} */
    1036             : 
    1037             : /* {{{ proto int filegroup(string filename)
    1038             :    Get file group */
    1039         155 : FileFunction(PHP_FN(filegroup), FS_GROUP)
    1040             : /* }}} */
    1041             : 
    1042             : /* {{{ proto int fileatime(string filename)
    1043             :    Get last access time of file */
    1044         148 : FileFunction(PHP_FN(fileatime), FS_ATIME)
    1045             : /* }}} */
    1046             : 
    1047             : /* {{{ proto int filemtime(string filename)
    1048             :    Get last modification time of file */
    1049         226 : FileFunction(PHP_FN(filemtime), FS_MTIME)
    1050             : /* }}} */
    1051             : 
    1052             : /* {{{ proto int filectime(string filename)
    1053             :    Get inode modification time of file */
    1054         133 : FileFunction(PHP_FN(filectime), FS_CTIME)
    1055             : /* }}} */
    1056             : 
    1057             : /* {{{ proto string filetype(string filename)
    1058             :    Get file type */
    1059         104 : FileFunction(PHP_FN(filetype), FS_TYPE)
    1060             : /* }}} */
    1061             : 
    1062             : /* {{{ proto bool is_writable(string filename)
    1063             :    Returns true if file can be written */
    1064        3337 : FileFunction(PHP_FN(is_writable), FS_IS_W)
    1065             : /* }}} */
    1066             : 
    1067             : /* {{{ proto bool is_readable(string filename)
    1068             :    Returns true if file can be read */
    1069        2099 : FileFunction(PHP_FN(is_readable), FS_IS_R)
    1070             : /* }}} */
    1071             : 
    1072             : /* {{{ proto bool is_executable(string filename)
    1073             :    Returns true if file is executable */
    1074        1856 : FileFunction(PHP_FN(is_executable), FS_IS_X)
    1075             : /* }}} */
    1076             : 
    1077             : /* {{{ proto bool is_file(string filename)
    1078             :    Returns true if file is a regular file */
    1079       10260 : FileFunction(PHP_FN(is_file), FS_IS_FILE)
    1080             : /* }}} */
    1081             : 
    1082             : /* {{{ proto bool is_dir(string filename)
    1083             :    Returns true if file is directory */
    1084       92099 : FileFunction(PHP_FN(is_dir), FS_IS_DIR)
    1085             : /* }}} */
    1086             : 
    1087             : /* {{{ proto bool is_link(string filename)
    1088             :    Returns true if file is symbolic link */
    1089         172 : FileFunction(PHP_FN(is_link), FS_IS_LINK)
    1090             : /* }}} */
    1091             : 
    1092             : /* {{{ proto bool file_exists(string filename)
    1093             :    Returns true if filename exists */
    1094       11264 : FileFunction(PHP_FN(file_exists), FS_EXISTS)
    1095             : /* }}} */
    1096             : 
    1097             : /* {{{ proto array lstat(string filename)
    1098             :    Give information about a file or symbolic link */
    1099         131 : FileFunction(php_if_lstat, FS_LSTAT)
    1100             : /* }}} */
    1101             : 
    1102             : /* {{{ proto array stat(string filename)
    1103             :    Give information about a file */
    1104         372 : FileFunction(php_if_stat, FS_STAT)
    1105             : /* }}} */
    1106             : 
    1107             : /* {{{ proto bool realpath_cache_size()
    1108             :    Get current size of realpath cache */
    1109           1 : PHP_FUNCTION(realpath_cache_size)
    1110             : {
    1111           1 :         if (zend_parse_parameters_none() == FAILURE) {
    1112           0 :                 return;
    1113             :         }
    1114           1 :         RETURN_LONG(realpath_cache_size());
    1115             : }
    1116             : 
    1117             : /* {{{ proto bool realpath_cache_get()
    1118             :    Get current size of realpath cache */
    1119           1 : PHP_FUNCTION(realpath_cache_get)
    1120             : {
    1121           1 :         realpath_cache_bucket **buckets = realpath_cache_get_buckets(), **end = buckets + realpath_cache_max_buckets();
    1122             : 
    1123           1 :         if (zend_parse_parameters_none() == FAILURE) {
    1124           0 :                 return;
    1125             :         }
    1126             : 
    1127           1 :         array_init(return_value);
    1128        1026 :         while(buckets < end) {
    1129        1024 :                 realpath_cache_bucket *bucket = *buckets;
    1130        2056 :                 while(bucket) {
    1131             :                         zval entry;
    1132             : 
    1133           8 :                         array_init(&entry);
    1134             : 
    1135             :                         /* bucket->key is unsigned long */
    1136           8 :                         if (ZEND_LONG_MAX >= bucket->key) {
    1137           5 :                                 add_assoc_long_ex(&entry, "key", sizeof("key") - 1, bucket->key);
    1138             :                         } else {
    1139           3 :                                 add_assoc_double_ex(&entry, "key", sizeof("key") - 1, (double)bucket->key);
    1140             :                         }
    1141           8 :                         add_assoc_bool_ex(&entry, "is_dir", sizeof("is_dir") - 1, bucket->is_dir);
    1142           8 :                         add_assoc_stringl_ex(&entry, "realpath", sizeof("realpath") - 1, bucket->realpath, bucket->realpath_len);
    1143           8 :                         add_assoc_long_ex(&entry, "expires", sizeof("expires") - 1, bucket->expires);
    1144             : #ifdef PHP_WIN32
    1145             :                         add_assoc_bool_ex(&entry, "is_rvalid", sizeof("is_rvalid") - 1, bucket->is_rvalid);
    1146             :                         add_assoc_bool_ex(&entry, "is_wvalid", sizeof("is_wvalid") - 1, bucket->is_wvalid);
    1147             :                         add_assoc_bool_ex(&entry, "is_readable", sizeof("is_readable") - 1, bucket->is_readable);
    1148             :                         add_assoc_bool_ex(&entry, "is_writable", sizeof("is_writable") - 1, bucket->is_writable);
    1149             : #endif
    1150           8 :                         zend_hash_str_update(Z_ARRVAL_P(return_value), bucket->path, bucket->path_len, &entry);
    1151           8 :                         bucket = bucket->next;
    1152             :                 }
    1153        1024 :                 buckets++;
    1154             :         }
    1155             : }
    1156             : 
    1157             : /*
    1158             :  * Local variables:
    1159             :  * tab-width: 4
    1160             :  * c-basic-offset: 4
    1161             :  * End:
    1162             :  * vim600: sw=4 ts=4 fdm=marker
    1163             :  * vim<600: sw=4 ts=4
    1164             :  */

Generated by: LCOV version 1.10

Generated at Sun, 18 Sep 2016 08:20:17 +0000 (7 days ago)

Copyright © 2005-2016 The PHP Group
All rights reserved.