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

LTP GCOV extension - code coverage report
Current view: directory - standard - filestat.c
Test: PHP Code Coverage
Date: 2009-11-19 Instrumented lines: 322
Code covered: 69.9 % Executed lines: 225
Legend: not executed executed

       1                 : /*
       2                 :    +----------------------------------------------------------------------+
       3                 :    | PHP Version 5                                                        |
       4                 :    +----------------------------------------------------------------------+
       5                 :    | Copyright (c) 1997-2009 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: filestat.c 290177 2009-11-03 17:50:10Z guenter $ */
      20                 : 
      21                 : #include "php.h"
      22                 : #include "safe_mode.h"
      23                 : #include "fopen_wrappers.h"
      24                 : #include "php_globals.h"
      25                 : 
      26                 : #include <stdlib.h>
      27                 : #include <sys/stat.h>
      28                 : #include <string.h>
      29                 : #include <errno.h>
      30                 : #include <ctype.h>
      31                 : #include <time.h>
      32                 : 
      33                 : #if HAVE_UNISTD_H
      34                 : # include <unistd.h>
      35                 : #endif
      36                 : 
      37                 : #if HAVE_SYS_PARAM_H
      38                 : # include <sys/param.h>
      39                 : #endif
      40                 : 
      41                 : #if HAVE_SYS_VFS_H
      42                 : # include <sys/vfs.h>
      43                 : #endif
      44                 : 
      45                 : #ifdef OS2
      46                 : #  define INCL_DOS
      47                 : #  include <os2.h>
      48                 : #endif
      49                 : 
      50                 : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
      51                 : # include <sys/statvfs.h>
      52                 : #elif defined(HAVE_SYS_STATFS_H) && defined(HAVE_STATFS)
      53                 : # include <sys/statfs.h>
      54                 : #elif defined(HAVE_SYS_MOUNT_H) && defined(HAVE_STATFS)
      55                 : # include <sys/mount.h>
      56                 : #endif
      57                 : 
      58                 : #if HAVE_PWD_H
      59                 : # ifdef PHP_WIN32
      60                 : #  include "win32/pwd.h"
      61                 : # else
      62                 : #  include <pwd.h>
      63                 : # endif
      64                 : #endif
      65                 : 
      66                 : #if HAVE_GRP_H
      67                 : # ifdef PHP_WIN32
      68                 : #  include "win32/grp.h"
      69                 : # else
      70                 : #  include <grp.h>
      71                 : # endif
      72                 : #endif
      73                 : 
      74                 : #if HAVE_UTIME
      75                 : # ifdef PHP_WIN32
      76                 : #  include <sys/utime.h>
      77                 : # else
      78                 : #  include <utime.h>
      79                 : # endif
      80                 : #endif
      81                 : 
      82                 : #ifdef PHP_WIN32
      83                 : #include "win32/winutil.h"
      84                 : #endif
      85                 : 
      86                 : #include "basic_functions.h"
      87                 : #include "php_filestat.h"
      88                 : 
      89                 : #ifndef S_ISDIR
      90                 : #define S_ISDIR(mode)   (((mode)&S_IFMT) == S_IFDIR)
      91                 : #endif
      92                 : #ifndef S_ISREG
      93                 : #define S_ISREG(mode)   (((mode)&S_IFMT) == S_IFREG)
      94                 : #endif
      95                 : #ifndef S_ISLNK
      96                 : #define S_ISLNK(mode)   (((mode)&S_IFMT) == S_IFLNK)
      97                 : #endif
      98                 : 
      99                 : #define S_IXROOT ( S_IXUSR | S_IXGRP | S_IXOTH )
     100                 : 
     101                 : PHP_RINIT_FUNCTION(filestat) /* {{{ */
     102           13551 : {
     103           13551 :         BG(CurrentStatFile)=NULL;
     104           13551 :         BG(CurrentLStatFile)=NULL;
     105           13551 :         return SUCCESS;
     106                 : }
     107                 : /* }}} */
     108                 : 
     109                 : PHP_RSHUTDOWN_FUNCTION(filestat) /* {{{ */ 
     110           13584 : {
     111           13584 :         if (BG(CurrentStatFile)) {
     112              75 :                 efree (BG(CurrentStatFile));
     113              75 :                 BG(CurrentStatFile) = NULL;
     114                 :         }
     115           13584 :         if (BG(CurrentLStatFile)) {
     116              12 :                 efree (BG(CurrentLStatFile));
     117              12 :                 BG(CurrentLStatFile) = NULL;
     118                 :         }
     119           13584 :         return SUCCESS;
     120                 : }
     121                 : /* }}} */
     122                 : 
     123                 : static int php_disk_total_space(char *path, double *space TSRMLS_DC) /* {{{ */
     124                 : #if defined(WINDOWS) /* {{{ */
     125                 : {
     126                 :         double bytestotal = 0;
     127                 :         HINSTANCE kernel32;
     128                 :         FARPROC gdfse;
     129                 :         typedef BOOL (WINAPI *gdfse_func)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
     130                 :         gdfse_func func;
     131                 : 
     132                 :         /* These are used by GetDiskFreeSpaceEx, if available. */
     133                 :         ULARGE_INTEGER FreeBytesAvailableToCaller;
     134                 :         ULARGE_INTEGER TotalNumberOfBytes;
     135                 :         ULARGE_INTEGER TotalNumberOfFreeBytes;
     136                 : 
     137                 :         /* These are used by GetDiskFreeSpace otherwise. */
     138                 :         DWORD SectorsPerCluster;
     139                 :         DWORD BytesPerSector;
     140                 :         DWORD NumberOfFreeClusters;
     141                 :         DWORD TotalNumberOfClusters;
     142                 : 
     143                 :         /* GetDiskFreeSpaceEx is only available in NT and Win95 post-OSR2,
     144                 :            so we have to jump through some hoops to see if the function
     145                 :            exists. */
     146                 :         kernel32 = LoadLibrary("kernel32.dll");
     147                 :         if (kernel32) {
     148                 :                 gdfse = GetProcAddress(kernel32, "GetDiskFreeSpaceExA");
     149                 :                 /* It's available, so we can call it. */
     150                 :                 if (gdfse) {
     151                 :                         func = (gdfse_func)gdfse;
     152                 :                         if (func(path,
     153                 :                                                 &FreeBytesAvailableToCaller,
     154                 :                                                 &TotalNumberOfBytes,
     155                 :                                                 &TotalNumberOfFreeBytes) == 0) {
     156                 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_win_err());
     157                 :                                 return FAILURE;
     158                 :                         }
     159                 : 
     160                 :                         /* i know - this is ugly, but i works <thies@thieso.net> */
     161                 :                         bytestotal  = TotalNumberOfBytes.HighPart *
     162                 :                                 (double) (((unsigned long)1) << 31) * 2.0 +
     163                 :                                 TotalNumberOfBytes.LowPart;
     164                 :                 } else { /* If it's not available, we just use GetDiskFreeSpace */
     165                 :                         if (GetDiskFreeSpace(path,
     166                 :                                                 &SectorsPerCluster, &BytesPerSector,
     167                 :                                                 &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) {
     168                 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_win_err());
     169                 :                                 return FAILURE;
     170                 :                         }
     171                 :                         bytestotal = (double)TotalNumberOfClusters * (double)SectorsPerCluster * (double)BytesPerSector;
     172                 :                 }
     173                 :         } else {
     174                 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to load kernel32.dll");
     175                 :                 return FAILURE;
     176                 :         }
     177                 :         
     178                 :         *space = bytestotal;
     179                 :         return SUCCESS; 
     180                 : }
     181                 : /* }}} */
     182                 : #elif defined(OS2) /* {{{ */
     183                 : {
     184                 :         double bytestotal = 0;
     185                 :         FSALLOCATE fsinfo;
     186                 :         char drive = path[0] & 95;
     187                 : 
     188                 :         if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) {
     189                 :                 bytestotal = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnit;
     190                 :                 *space = bytestotal;
     191                 :                 return SUCCESS;
     192                 :         }
     193                 :         return FAILURE;
     194                 : }
     195                 : /* }}} */
     196                 : #else /* {{{ if !defined(OS2) && !defined(WINDOWS) */
     197              22 : {
     198              22 :         double bytestotal = 0;
     199                 : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
     200                 :     struct statvfs buf;
     201                 : #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
     202                 :     struct statfs buf;
     203                 : #endif
     204                 : 
     205                 : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
     206              22 :         if (statvfs(path, &buf)) {
     207               3 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
     208               3 :                 return FAILURE;
     209                 :         }
     210              19 :         if (buf.f_frsize) {
     211              19 :                 bytestotal = (((double)buf.f_blocks) * ((double)buf.f_frsize));
     212                 :         } else {
     213               0 :                 bytestotal = (((double)buf.f_blocks) * ((double)buf.f_bsize));
     214                 :         }
     215                 : 
     216                 : #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
     217                 :         if (statfs(path, &buf)) {
     218                 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
     219                 :                 return FAILURE;
     220                 :         }
     221                 :         bytestotal = (((double)buf.f_bsize) * ((double)buf.f_blocks));
     222                 : #endif
     223                 : 
     224              19 :         *space = bytestotal;
     225              19 :         return SUCCESS;
     226                 : }
     227                 : #endif
     228                 : /* }}} */
     229                 : /* }}} */
     230                 : 
     231                 : /* {{{ proto float disk_total_space(string path)
     232                 :    Get total disk space for filesystem that path is on */
     233                 : PHP_FUNCTION(disk_total_space)
     234              25 : {
     235                 :         double bytestotal;
     236                 :         char *path;
     237                 :         int path_len;
     238                 : 
     239              25 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE) {
     240               3 :                 return;
     241                 :         }
     242                 : 
     243              22 :         if (php_check_open_basedir(path TSRMLS_CC)) {
     244               0 :                 RETURN_FALSE;
     245                 :         }
     246                 : 
     247              22 :         if (php_disk_total_space(path, &bytestotal TSRMLS_CC) == SUCCESS) {
     248              19 :                 RETURN_DOUBLE(bytestotal);
     249                 :         }
     250               3 :         RETURN_FALSE;
     251                 : }
     252                 : /* }}} */
     253                 : 
     254                 : static int php_disk_free_space(char *path, double *space TSRMLS_DC) /* {{{ */
     255                 : #if defined(WINDOWS) /* {{{ */ 
     256                 : {
     257                 :         double bytesfree = 0;
     258                 : 
     259                 :         HINSTANCE kernel32;
     260                 :         FARPROC gdfse;
     261                 :         typedef BOOL (WINAPI *gdfse_func)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
     262                 :         gdfse_func func;
     263                 : 
     264                 :         /* These are used by GetDiskFreeSpaceEx, if available. */
     265                 :         ULARGE_INTEGER FreeBytesAvailableToCaller;
     266                 :         ULARGE_INTEGER TotalNumberOfBytes;
     267                 :         ULARGE_INTEGER TotalNumberOfFreeBytes;
     268                 : 
     269                 :         /* These are used by GetDiskFreeSpace otherwise. */
     270                 :         DWORD SectorsPerCluster;
     271                 :         DWORD BytesPerSector;
     272                 :         DWORD NumberOfFreeClusters;
     273                 :         DWORD TotalNumberOfClusters;
     274                 : 
     275                 :         /* GetDiskFreeSpaceEx is only available in NT and Win95 post-OSR2,
     276                 :            so we have to jump through some hoops to see if the function
     277                 :            exists. */
     278                 :         kernel32 = LoadLibrary("kernel32.dll");
     279                 :         if (kernel32) {
     280                 :                 gdfse = GetProcAddress(kernel32, "GetDiskFreeSpaceExA");
     281                 :                 /* It's available, so we can call it. */
     282                 :                 if (gdfse) {
     283                 :                         func = (gdfse_func)gdfse;
     284                 :                         if (func(path,
     285                 :                                 &FreeBytesAvailableToCaller,
     286                 :                                 &TotalNumberOfBytes,
     287                 :                                 &TotalNumberOfFreeBytes) == 0) { 
     288                 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_win_err());
     289                 :                                 return FAILURE;
     290                 :                         }
     291                 : 
     292                 :                         /* i know - this is ugly, but i works <thies@thieso.net> */
     293                 :                         bytesfree  = FreeBytesAvailableToCaller.HighPart *
     294                 :                                 (double) (((unsigned long)1) << 31) * 2.0 +
     295                 :                                 FreeBytesAvailableToCaller.LowPart;
     296                 :                 } else { /* If it's not available, we just use GetDiskFreeSpace */
     297                 :                         if (GetDiskFreeSpace(path,
     298                 :                                 &SectorsPerCluster, &BytesPerSector,
     299                 :                                 &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) { 
     300                 :                                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", php_win_err());
     301                 :                                 return FAILURE;
     302                 :                         }
     303                 :                         bytesfree = (double)NumberOfFreeClusters * (double)SectorsPerCluster * (double)BytesPerSector;
     304                 :                 }
     305                 :         } else {
     306                 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to load kernel32.dll");
     307                 :                 return FAILURE;
     308                 :         }
     309                 : 
     310                 :         *space = bytesfree;
     311                 :         return SUCCESS;
     312                 : }
     313                 : /* }}} */
     314                 : #elif defined(OS2) /* {{{ */
     315                 : {
     316                 :         double bytesfree = 0;
     317                 :         FSALLOCATE fsinfo;
     318                 :         char drive = path[0] & 95;
     319                 : 
     320                 :         if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) {
     321                 :                 bytesfree = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnitAvail;
     322                 :                 *space = bytesfree;
     323                 :                 return SUCCESS;
     324                 :         } 
     325                 :         return FAILURE;
     326                 : }
     327                 : /* }}} */
     328                 : #else /* {{{ if !defined(OS2) && !defined(WINDOWS) */
     329              39 : {
     330              39 :         double bytesfree = 0;
     331                 : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
     332                 :         struct statvfs buf;
     333                 : #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
     334                 :         struct statfs buf;
     335                 : #endif
     336                 : 
     337                 : #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
     338              39 :         if (statvfs(path, &buf)) {
     339               4 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
     340               4 :                 return FAILURE;
     341                 :         }
     342              35 :         if (buf.f_frsize) {
     343              35 :                 bytesfree = (((double)buf.f_bavail) * ((double)buf.f_frsize));
     344                 :         } else {
     345               0 :                 bytesfree = (((double)buf.f_bavail) * ((double)buf.f_bsize));
     346                 :         }
     347                 : #elif (defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_MOUNT_H)) && defined(HAVE_STATFS)
     348                 :         if (statfs(path, &buf)) {
     349                 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
     350                 :                 return FAILURE;
     351                 :         }
     352                 : #ifdef NETWARE
     353                 :         bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bfree));
     354                 : #else
     355                 :         bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bavail));
     356                 : #endif
     357                 : #endif
     358                 :         
     359              35 :         *space = bytesfree;
     360              35 :         return SUCCESS;
     361                 : }
     362                 : #endif
     363                 : /* }}} */
     364                 : /* }}} */
     365                 : 
     366                 : /* {{{ proto float disk_free_space(string path)
     367                 :    Get free disk space for filesystem that path is on */
     368                 : PHP_FUNCTION(disk_free_space)
     369              52 : {
     370                 :         double bytesfree;
     371                 :         char *path;
     372                 :         int path_len;
     373                 : 
     374              52 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE) {
     375               5 :                 return;
     376                 :         }
     377                 : 
     378              47 :         if (php_check_open_basedir(path TSRMLS_CC)) {
     379               8 :                 RETURN_FALSE;
     380                 :         }
     381                 : 
     382              39 :         if (php_disk_free_space(path, &bytesfree TSRMLS_CC) == SUCCESS) {
     383              35 :                 RETURN_DOUBLE(bytesfree);
     384                 :         }
     385               4 :         RETURN_FALSE;
     386                 : }
     387                 : /* }}} */
     388                 : 
     389                 : #if !defined(WINDOWS) && !defined(NETWARE)
     390                 : static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */
     391               1 : {
     392                 :         zval **filename, **group;
     393                 :         gid_t gid;
     394                 :         int ret;
     395                 : 
     396               1 :         if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &group)==FAILURE) {
     397               0 :                 WRONG_PARAM_COUNT;
     398                 :         }
     399               1 :         convert_to_string_ex(filename);
     400               1 :         if (Z_TYPE_PP(group) == IS_STRING) {
     401                 : #if defined(ZTS) && defined(HAVE_GETGRNAM_R) && defined(_SC_GETGR_R_SIZE_MAX)
     402                 :                 struct group gr;
     403                 :                 struct group *retgrptr;
     404                 :                 long grbuflen = sysconf(_SC_GETGR_R_SIZE_MAX);
     405                 :                 char *grbuf;
     406                 : 
     407                 :                 if (grbuflen < 1) {
     408                 :                         RETURN_FALSE;
     409                 :                 }
     410                 : 
     411                 :                 grbuf = emalloc(grbuflen);
     412                 :                 if (getgrnam_r(Z_STRVAL_PP(group), &gr, grbuf, grbuflen, &retgrptr) != 0 || retgrptr == NULL) {
     413                 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find gid for %s", Z_STRVAL_PP(group));
     414                 :                         efree(grbuf);
     415                 :                         RETURN_FALSE;
     416                 :                 }
     417                 :                 efree(grbuf);
     418                 :                 gid = gr.gr_gid;
     419                 : #else
     420               0 :                 struct group *gr = getgrnam(Z_STRVAL_PP(group));
     421                 : 
     422               0 :                 if (!gr) {
     423               0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find gid for %s", Z_STRVAL_PP(group));
     424               0 :                         RETURN_FALSE;
     425                 :                 }
     426               0 :                 gid = gr->gr_gid;
     427                 : #endif
     428                 :         } else {
     429               1 :                 convert_to_long_ex(group);
     430               1 :                 gid = Z_LVAL_PP(group);
     431                 :         }
     432                 : 
     433               1 :         if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) {
     434               0 :                 RETURN_FALSE;
     435                 :         }
     436                 : 
     437                 :         /* Check the basedir */
     438               1 :         if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
     439               0 :                 RETURN_FALSE;
     440                 :         }
     441                 : 
     442               1 :         if (do_lchgrp) {
     443                 : #if HAVE_LCHOWN
     444               1 :                 ret = VCWD_LCHOWN(Z_STRVAL_PP(filename), -1, gid);
     445                 : #endif
     446                 :         } else {
     447               0 :                 ret = VCWD_CHOWN(Z_STRVAL_PP(filename), -1, gid);
     448                 :         }
     449               1 :         if (ret == -1) {
     450               0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
     451               0 :                 RETURN_FALSE;
     452                 :         }
     453               1 :         RETURN_TRUE;
     454                 : }
     455                 : /* }}} */
     456                 : #endif
     457                 : 
     458                 : #ifndef NETWARE
     459                 : /* {{{ proto bool chgrp(string filename, mixed group)
     460                 :    Change file group */
     461                 : PHP_FUNCTION(chgrp)
     462               0 : {
     463                 : #if !defined(WINDOWS)
     464               0 :         php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
     465                 : #else
     466                 :         RETURN_FALSE;
     467                 : #endif
     468               0 : }
     469                 : /* }}} */
     470                 : 
     471                 : /* {{{ proto bool lchgrp(string filename, mixed group)
     472                 :    Change symlink group */
     473                 : #if HAVE_LCHOWN
     474                 : PHP_FUNCTION(lchgrp)
     475               1 : {
     476                 : # if !defined(WINDOWS)
     477               1 :         php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
     478                 : # else
     479                 :         RETURN_FALSE;
     480                 : # endif
     481               1 : }
     482                 : #endif
     483                 : /* }}} */
     484                 : #endif
     485                 : 
     486                 : #if !defined(WINDOWS)
     487                 : static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */
     488               0 : {
     489                 :         zval **filename, **user;
     490                 :         int ret;
     491                 :         uid_t uid;
     492                 : 
     493               0 :         if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &user)==FAILURE) {
     494               0 :                 WRONG_PARAM_COUNT;
     495                 :         }
     496               0 :         convert_to_string_ex(filename);
     497               0 :         if (Z_TYPE_PP(user) == IS_STRING) {
     498                 : #if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R)
     499                 :                 struct passwd pw;
     500                 :                 struct passwd *retpwptr = NULL;
     501                 :                 long pwbuflen = sysconf(_SC_GETPW_R_SIZE_MAX);
     502                 :                 char *pwbuf;
     503                 : 
     504                 :                 if (pwbuflen < 1) {
     505                 :                         RETURN_FALSE;
     506                 :                 }
     507                 : 
     508                 :                 pwbuf = emalloc(pwbuflen);
     509                 :                 if (getpwnam_r(Z_STRVAL_PP(user), &pw, pwbuf, pwbuflen, &retpwptr) != 0 || retpwptr == NULL) {
     510                 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find uid for %s", Z_STRVAL_PP(user));
     511                 :                         efree(pwbuf);
     512                 :                         RETURN_FALSE;
     513                 :                 }
     514                 :                 efree(pwbuf);
     515                 :                 uid = pw.pw_uid;
     516                 : #else
     517               0 :                 struct passwd *pw = getpwnam(Z_STRVAL_PP(user));
     518                 : 
     519               0 :                 if (!pw) {
     520               0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find uid for %s", Z_STRVAL_PP(user));
     521               0 :                         RETURN_FALSE;
     522                 :                 }
     523               0 :                 uid = pw->pw_uid;
     524                 : #endif
     525                 :         } else {
     526               0 :                 convert_to_long_ex(user);
     527               0 :                 uid = Z_LVAL_PP(user);
     528                 :         }
     529                 : 
     530               0 :         if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) {
     531               0 :                 RETURN_FALSE;
     532                 :         }
     533                 : 
     534                 :         /* Check the basedir */
     535               0 :         if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
     536               0 :                 RETURN_FALSE;
     537                 :         }
     538                 : 
     539               0 :         if (do_lchown) {
     540                 : #if HAVE_LCHOWN
     541               0 :                 ret = VCWD_LCHOWN(Z_STRVAL_PP(filename), uid, -1);
     542                 : #endif
     543                 :         } else {
     544               0 :                 ret = VCWD_CHOWN(Z_STRVAL_PP(filename), uid, -1);
     545                 :         }
     546               0 :         if (ret == -1) {
     547               0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
     548               0 :                 RETURN_FALSE;
     549                 :         }
     550                 : }
     551                 : /* }}} */
     552                 : #endif
     553                 : 
     554                 : #ifndef NETWARE
     555                 : /* {{{ proto bool chown (string filename, mixed user)
     556                 :    Change file owner */
     557                 : PHP_FUNCTION(chown)
     558               0 : {
     559                 : #if !defined(WINDOWS)
     560               0 :         RETVAL_TRUE;
     561               0 :         php_do_chown(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
     562                 : #else
     563                 :         RETURN_FALSE;
     564                 : #endif
     565               0 : }
     566                 : /* }}} */
     567                 : 
     568                 : /* {{{ proto bool chown (string filename, mixed user)
     569                 :    Change file owner */
     570                 : #if HAVE_LCHOWN
     571                 : PHP_FUNCTION(lchown)
     572               0 : {
     573                 : # if !defined(WINDOWS)
     574               0 :         RETVAL_TRUE;
     575               0 :         php_do_chown(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
     576                 : # else
     577                 :         RETURN_FALSE;
     578                 : # endif
     579               0 : }
     580                 : #endif
     581                 : /* }}} */
     582                 : #endif
     583                 : 
     584                 : /* {{{ proto bool chmod(string filename, int mode)
     585                 :    Change file mode */
     586                 : PHP_FUNCTION(chmod)
     587           10334 : {
     588                 :         zval **filename, **mode;
     589                 :         int ret;
     590                 :         mode_t imode;
     591                 : 
     592           10334 :         if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &mode)==FAILURE) {
     593               6 :                 WRONG_PARAM_COUNT;
     594                 :         }
     595           10328 :         convert_to_string_ex(filename);
     596           10328 :         convert_to_long_ex(mode);
     597                 : 
     598           10328 :         if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) {
     599               0 :                 RETURN_FALSE;
     600                 :         }
     601                 : 
     602                 :         /* Check the basedir */
     603           10328 :         if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
     604               8 :                 RETURN_FALSE;
     605                 :         }
     606                 : 
     607           10320 :         imode = (mode_t) Z_LVAL_PP(mode);
     608                 :         /* in safe mode, do not allow to setuid files.
     609                 :            Setuiding files could allow users to gain privileges
     610                 :            that safe mode doesn't give them.
     611                 :         */
     612                 : 
     613           10320 :         if(PG(safe_mode)) {
     614                 :                 php_stream_statbuf ssb;
     615               5 :                 if (php_stream_stat_path_ex(Z_STRVAL_PP(filename), 0, &ssb, NULL)) {
     616               0 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "stat failed for %s", Z_STRVAL_PP(filename));
     617               0 :                         RETURN_FALSE;
     618                 :                 }
     619               5 :                 if ((imode & 04000) != 0 && (ssb.sb.st_mode & 04000) == 0) {
     620               0 :                         imode ^= 04000;
     621                 :                 }
     622               5 :                 if ((imode & 02000) != 0 && (ssb.sb.st_mode & 02000) == 0) {
     623               0 :                         imode ^= 02000;
     624                 :                 }
     625               5 :                 if ((imode & 01000) != 0 && (ssb.sb.st_mode & 01000) == 0) {
     626               0 :                         imode ^= 01000;
     627                 :                 }
     628                 :         }
     629                 : 
     630           10320 :         ret = VCWD_CHMOD(Z_STRVAL_PP(filename), imode);
     631           10320 :         if (ret == -1) {
     632              30 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
     633              30 :                 RETURN_FALSE;
     634                 :         }
     635           10290 :         RETURN_TRUE;
     636                 : }
     637                 : /* }}} */
     638                 : 
     639                 : #if HAVE_UTIME
     640                 : /* {{{ proto bool touch(string filename [, int time [, int atime]])
     641                 :    Set modification time of file */
     642                 : PHP_FUNCTION(touch)
     643             244 : {
     644                 :         zval **filename, **filetime, **fileatime;
     645                 :         int ret;
     646                 :         FILE *file;
     647                 :         struct utimbuf newtimebuf;
     648             244 :         struct utimbuf *newtime = NULL;
     649             244 :         int ac = ZEND_NUM_ARGS();
     650                 : 
     651                 : 
     652             244 :         if (ac == 1 && zend_get_parameters_ex(1, &filename) != FAILURE) {
     653                 : #ifndef HAVE_UTIME_NULL
     654                 :                 newtime = &newtimebuf;
     655                 :                 newtime->modtime = newtime->actime = time(NULL);
     656                 : #endif
     657              95 :         } else if (ac == 2 && zend_get_parameters_ex(2, &filename, &filetime) != FAILURE) {
     658               7 :                 convert_to_long_ex(filetime);
     659               7 :                 newtime = &newtimebuf;
     660               7 :                 newtime->modtime = newtime->actime = Z_LVAL_PP(filetime);
     661             155 :         } else if (ac == 3 && zend_get_parameters_ex(3, &filename, &filetime, &fileatime) != FAILURE) {
     662              74 :                 convert_to_long_ex(fileatime);
     663              74 :                 convert_to_long_ex(filetime);
     664              74 :                 newtime = &newtimebuf;
     665              74 :                 newtime->actime = Z_LVAL_PP(fileatime);
     666              74 :                 newtime->modtime = Z_LVAL_PP(filetime);
     667                 :         } else {
     668               7 :                 WRONG_PARAM_COUNT;
     669                 :         }
     670             237 :         convert_to_string_ex(filename);
     671                 : 
     672             237 :         if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
     673               0 :                 RETURN_FALSE;
     674                 :         }
     675                 : 
     676                 :         /* Check the basedir */
     677             237 :         if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
     678               8 :                 RETURN_FALSE;
     679                 :         }
     680                 : 
     681                 :         /* create the file if it doesn't exist already */
     682             229 :         if (VCWD_ACCESS(Z_STRVAL_PP(filename), F_OK) != 0) {
     683             118 :                 file = VCWD_FOPEN(Z_STRVAL_PP(filename), "w");
     684             118 :                 if (file == NULL) {
     685              11 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create file %s because %s", Z_STRVAL_PP(filename), strerror(errno));
     686              11 :                         RETURN_FALSE;
     687                 :                 }
     688             107 :                 fclose(file);
     689                 :         }
     690                 : 
     691             218 :         ret = VCWD_UTIME(Z_STRVAL_PP(filename), newtime);
     692             218 :         if (ret == -1) {
     693               0 :                 php_error_docref(NULL TSRMLS_CC, E_WARNING, "Utime failed: %s", strerror(errno));
     694               0 :                 RETURN_FALSE;
     695                 :         }
     696             218 :         RETURN_TRUE;
     697                 : }
     698                 : /* }}} */
     699                 : #endif
     700                 : 
     701                 : /* {{{ php_clear_stat_cache()
     702                 : */
     703                 : PHPAPI void php_clear_stat_cache(TSRMLS_D)
     704           26840 : {
     705           26840 :         if (BG(CurrentStatFile)) {
     706           16815 :                 efree(BG(CurrentStatFile));
     707           16815 :                 BG(CurrentStatFile) = NULL;
     708                 :         }
     709           26840 :         if (BG(CurrentLStatFile)) {
     710              46 :                 efree(BG(CurrentLStatFile));
     711              46 :                 BG(CurrentLStatFile) = NULL;
     712                 :         }
     713           26840 :         realpath_cache_clean(TSRMLS_C);
     714           26840 : }
     715                 : /* }}} */
     716                 : 
     717                 : /* {{{ proto void clearstatcache(void)
     718                 :    Clear file stat cache */
     719                 : PHP_FUNCTION(clearstatcache)
     720            8211 : {
     721            8211 :         if (ZEND_NUM_ARGS()) {
     722               1 :                 WRONG_PARAM_COUNT;
     723                 :         }
     724            8210 :         php_clear_stat_cache(TSRMLS_C);
     725                 : }
     726                 : /* }}} */
     727                 : 
     728                 : #define IS_LINK_OPERATION(__t) ((__t) == FS_TYPE || (__t) == FS_IS_LINK || (__t) == FS_LSTAT)
     729                 : #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)
     730                 : #define IS_ABLE_CHECK(__t) ((__t) == FS_IS_R || (__t) == FS_IS_W || (__t) == FS_IS_X)
     731                 : #define IS_ACCESS_CHECK(__t) (IS_ABLE_CHECK(type) || (__t) == FS_EXISTS)
     732                 : 
     733                 : /* {{{ php_stat
     734                 :  */
     735                 : PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int type, zval *return_value TSRMLS_DC)
     736           68553 : {
     737                 :         zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev,
     738                 :                 *stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks;
     739                 :         struct stat *stat_sb;
     740                 :         php_stream_statbuf ssb;
     741           68553 :         int flags = 0, rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH; /* access rights defaults to other */
     742                 :         char *stat_sb_names[13]={"dev", "ino", "mode", "nlink", "uid", "gid", "rdev",
     743           68553 :                               "size", "atime", "mtime", "ctime", "blksize", "blocks"};
     744                 :         char *local;
     745                 :         php_stream_wrapper *wrapper;
     746                 :         char safe_mode_buf[MAXPATHLEN];
     747                 : 
     748           68553 :         if (!filename_length) {
     749              64 :                 RETURN_FALSE;
     750                 :         }
     751                 : 
     752           68489 :         if ((wrapper = php_stream_locate_url_wrapper(filename, &local, 0 TSRMLS_CC)) == &php_plain_files_wrapper) {
     753           68476 :                 if (php_check_open_basedir(local TSRMLS_CC)) {
     754             161 :                         RETURN_FALSE;
     755           68315 :                 } else if (PG(safe_mode)) {
     756               0 :                         if (type == FS_IS_X) {
     757               0 :                                 if (strstr(local, "..")) {
     758               0 :                                         RETURN_FALSE;
     759                 :                                 } else {
     760               0 :                                         char *b = strrchr(local, PHP_DIR_SEPARATOR);
     761               0 :                                         snprintf(safe_mode_buf, MAXPATHLEN, "%s%s%s", PG(safe_mode_exec_dir), (b ? "" : "/"), (b ? b : local));
     762               0 :                                         local = (char *)&safe_mode_buf;
     763                 :                                 }
     764               0 :                         } else if (!php_checkuid_ex(local, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS, CHECKUID_NO_ERRORS)) {
     765               0 :                                 RETURN_FALSE;
     766                 :                         }
     767                 :                 }
     768                 :         }
     769                 : 
     770           68328 :         if (IS_ACCESS_CHECK(type)) {
     771            5178 :                 if (wrapper == &php_plain_files_wrapper) {
     772                 : 
     773            5176 :                         switch (type) {
     774                 : #ifdef F_OK
     775                 :                                 case FS_EXISTS:
     776            2812 :                                         RETURN_BOOL(VCWD_ACCESS(local, F_OK) == 0);
     777                 :                                         break;
     778                 : #endif
     779                 : #ifdef W_OK
     780                 :                                 case FS_IS_W:
     781            1093 :                                         RETURN_BOOL(VCWD_ACCESS(local, W_OK) == 0);
     782                 :                                         break;
     783                 : #endif
     784                 : #ifdef R_OK
     785                 :                                 case FS_IS_R:
     786             678 :                                         RETURN_BOOL(VCWD_ACCESS(local, R_OK) == 0);
     787                 :                                         break;
     788                 : #endif
     789                 : #ifdef X_OK
     790                 :                                 case FS_IS_X:
     791             593 :                                         RETURN_BOOL(VCWD_ACCESS(local, X_OK) == 0);
     792                 :                                         break;
     793                 : #endif
     794                 :                         }
     795                 :                 }
     796                 :         }
     797                 : 
     798           63152 :         if (IS_LINK_OPERATION(type)) {
     799             112 :                 flags |= PHP_STREAM_URL_STAT_LINK;
     800                 :         }
     801           63152 :         if (IS_EXISTS_CHECK(type)) {
     802           46058 :                 flags |= PHP_STREAM_URL_STAT_QUIET;
     803                 :         }
     804                 : 
     805           63152 :         if (php_stream_stat_path_ex((char *)filename, flags, &ssb, NULL)) {
     806                 :                 /* Error Occured */
     807             200 :                 if (!IS_EXISTS_CHECK(type)) {
     808              84 :                         php_error_docref(NULL TSRMLS_CC, E_WARNING, "%sstat failed for %s", IS_LINK_OPERATION(type) ? "L" : "", filename);
     809                 :                 }
     810             200 :                 RETURN_FALSE;
     811                 :         }
     812                 : 
     813           62952 :         stat_sb = &ssb.sb;
     814                 : 
     815                 : 
     816                 : #ifndef NETWARE
     817           62952 :         if (type >= FS_IS_W && type <= FS_IS_X) {
     818               0 :                 if(ssb.sb.st_uid==getuid()) {
     819               0 :                         rmask=S_IRUSR;
     820               0 :                         wmask=S_IWUSR;
     821               0 :                         xmask=S_IXUSR;
     822               0 :                 } else if(ssb.sb.st_gid==getgid()) {
     823               0 :                         rmask=S_IRGRP;
     824               0 :                         wmask=S_IWGRP;
     825               0 :                         xmask=S_IXGRP;
     826                 :                 } else {
     827                 :                         int   groups, n, i;
     828                 :                         gid_t *gids;
     829                 : 
     830               0 :                         groups = getgroups(0, NULL);
     831               0 :                         if(groups > 0) {
     832               0 :                                 gids=(gid_t *)safe_emalloc(groups, sizeof(gid_t), 0);
     833               0 :                                 n=getgroups(groups, gids);
     834               0 :                                 for(i=0;i<n;i++){
     835               0 :                                         if(ssb.sb.st_gid==gids[i]) {
     836               0 :                                                 rmask=S_IRGRP;
     837               0 :                                                 wmask=S_IWGRP;
     838               0 :                                                 xmask=S_IXGRP;
     839               0 :                                                 break;
     840                 :                                         }
     841                 :                                 }
     842               0 :                                 efree(gids);
     843                 :                         }
     844                 :                 }
     845                 :         }
     846                 : #endif
     847                 : 
     848                 : #ifndef NETWARE
     849           62952 :         if (IS_ABLE_CHECK(type) && getuid() == 0) {
     850                 :                 /* root has special perms on plain_wrapper 
     851                 :                    But we don't know about root under Netware */
     852               0 :                 if (wrapper == &php_plain_files_wrapper) {
     853               0 :                         if (type == FS_IS_X) {
     854               0 :                                 xmask = S_IXROOT;
     855                 :                         } else {
     856               0 :                                 RETURN_TRUE;
     857                 :                         }
     858                 :                 }
     859                 :         }
     860                 : #endif
     861                 : 
     862           62952 :         switch (type) {
     863                 :         case FS_PERMS:
     864            6758 :                 RETURN_LONG((long)ssb.sb.st_mode);
     865                 :         case FS_INODE:
     866              43 :                 RETURN_LONG((long)ssb.sb.st_ino);
     867                 :         case FS_SIZE:
     868            9892 :                 RETURN_LONG((long)ssb.sb.st_size);
     869                 :         case FS_OWNER:
     870              54 :                 RETURN_LONG((long)ssb.sb.st_uid);
     871                 :         case FS_GROUP:
     872              26 :                 RETURN_LONG((long)ssb.sb.st_gid);
     873                 :         case FS_ATIME:
     874              33 :                 RETURN_LONG((long)ssb.sb.st_atime);
     875                 :         case FS_MTIME:
     876              34 :                 RETURN_LONG((long)ssb.sb.st_mtime);
     877                 :         case FS_CTIME:
     878              29 :                 RETURN_LONG((long)ssb.sb.st_ctime);
     879                 :         case FS_TYPE:
     880              21 :                 if (S_ISLNK(ssb.sb.st_mode)) {
     881               2 :                         RETURN_STRING("link", 1);
     882                 :                 }
     883              19 :                 switch(ssb.sb.st_mode & S_IFMT) {
     884               1 :                 case S_IFIFO: RETURN_STRING("fifo", 1);
     885               1 :                 case S_IFCHR: RETURN_STRING("char", 1);
     886               8 :                 case S_IFDIR: RETURN_STRING("dir", 1);
     887               0 :                 case S_IFBLK: RETURN_STRING("block", 1);
     888               9 :                 case S_IFREG: RETURN_STRING("file", 1);
     889                 : #if defined(S_IFSOCK) && !defined(ZEND_WIN32)&&!defined(__BEOS__)
     890               0 :                 case S_IFSOCK: RETURN_STRING("socket", 1);
     891                 : #endif
     892                 :                 }
     893               0 :                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown file type (%d)", ssb.sb.st_mode&S_IFMT);
     894               0 :                 RETURN_STRING("unknown", 1);
     895                 :         case FS_IS_W:
     896               0 :                 RETURN_BOOL((ssb.sb.st_mode & wmask) != 0);
     897                 :         case FS_IS_R:
     898               0 :                 RETURN_BOOL((ssb.sb.st_mode&rmask)!=0);
     899                 :         case FS_IS_X:
     900               0 :                 RETURN_BOOL((ssb.sb.st_mode&xmask)!=0 && !S_ISDIR(ssb.sb.st_mode));
     901                 :         case FS_IS_FILE:
     902             892 :                 RETURN_BOOL(S_ISREG(ssb.sb.st_mode));
     903                 :         case FS_IS_DIR:
     904           45009 :                 RETURN_BOOL(S_ISDIR(ssb.sb.st_mode));
     905                 :         case FS_IS_LINK:
     906              41 :                 RETURN_BOOL(S_ISLNK(ssb.sb.st_mode));
     907                 :         case FS_EXISTS:
     908               0 :                 RETURN_TRUE; /* the false case was done earlier */
     909                 :         case FS_LSTAT:
     910                 :                 /* FALLTHROUGH */
     911                 :         case FS_STAT:
     912             120 :                 array_init(return_value);
     913                 : 
     914             120 :                 MAKE_LONG_ZVAL_INCREF(stat_dev, stat_sb->st_dev);
     915             120 :                 MAKE_LONG_ZVAL_INCREF(stat_ino, stat_sb->st_ino);
     916             120 :                 MAKE_LONG_ZVAL_INCREF(stat_mode, stat_sb->st_mode);
     917             120 :                 MAKE_LONG_ZVAL_INCREF(stat_nlink, stat_sb->st_nlink);
     918             120 :                 MAKE_LONG_ZVAL_INCREF(stat_uid, stat_sb->st_uid);
     919             120 :                 MAKE_LONG_ZVAL_INCREF(stat_gid, stat_sb->st_gid);
     920                 : #ifdef HAVE_ST_RDEV
     921             120 :                 MAKE_LONG_ZVAL_INCREF(stat_rdev, stat_sb->st_rdev); 
     922                 : #else
     923                 :                 MAKE_LONG_ZVAL_INCREF(stat_rdev, -1); 
     924                 : #endif
     925             120 :                 MAKE_LONG_ZVAL_INCREF(stat_size, stat_sb->st_size);
     926             120 :                 MAKE_LONG_ZVAL_INCREF(stat_atime, stat_sb->st_atime);
     927             120 :                 MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_sb->st_mtime);
     928             120 :                 MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_sb->st_ctime);
     929                 : #ifdef HAVE_ST_BLKSIZE
     930             120 :                 MAKE_LONG_ZVAL_INCREF(stat_blksize, stat_sb->st_blksize); 
     931                 : #else
     932                 :                 MAKE_LONG_ZVAL_INCREF(stat_blksize,-1);
     933                 : #endif
     934                 : #ifdef HAVE_ST_BLOCKS
     935             120 :                 MAKE_LONG_ZVAL_INCREF(stat_blocks, stat_sb->st_blocks);
     936                 : #else
     937                 :                 MAKE_LONG_ZVAL_INCREF(stat_blocks,-1);
     938                 : #endif
     939                 :                 /* Store numeric indexes in propper order */
     940             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_dev, sizeof(zval *), NULL);
     941             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ino, sizeof(zval *), NULL);
     942             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mode, sizeof(zval *), NULL);
     943             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_nlink, sizeof(zval *), NULL);
     944             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_uid, sizeof(zval *), NULL);
     945             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_gid, sizeof(zval *), NULL);
     946                 :         
     947             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_rdev, sizeof(zval *), NULL);
     948             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_size, sizeof(zval *), NULL);
     949             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_atime, sizeof(zval *), NULL);
     950             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mtime, sizeof(zval *), NULL);
     951             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ctime, sizeof(zval *), NULL);
     952             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blksize, sizeof(zval *), NULL);
     953             120 :                 zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blocks, sizeof(zval *), NULL);
     954                 : 
     955                 :                 /* Store string indexes referencing the same zval*/
     956             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[0], strlen(stat_sb_names[0])+1, (void *) &stat_dev, sizeof(zval *), NULL);
     957             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[1], strlen(stat_sb_names[1])+1, (void *) &stat_ino, sizeof(zval *), NULL);
     958             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[2], strlen(stat_sb_names[2])+1, (void *) &stat_mode, sizeof(zval *), NULL);
     959             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[3], strlen(stat_sb_names[3])+1, (void *) &stat_nlink, sizeof(zval *), NULL);
     960             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[4], strlen(stat_sb_names[4])+1, (void *) &stat_uid, sizeof(zval *), NULL);
     961             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[5], strlen(stat_sb_names[5])+1, (void *) &stat_gid, sizeof(zval *), NULL);
     962             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[6], strlen(stat_sb_names[6])+1, (void *) &stat_rdev, sizeof(zval *), NULL);
     963             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[7], strlen(stat_sb_names[7])+1, (void *) &stat_size, sizeof(zval *), NULL);
     964             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[8], strlen(stat_sb_names[8])+1, (void *) &stat_atime, sizeof(zval *), NULL);
     965             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[9], strlen(stat_sb_names[9])+1, (void *) &stat_mtime, sizeof(zval *), NULL);
     966             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[10], strlen(stat_sb_names[10])+1, (void *) &stat_ctime, sizeof(zval *), NULL);
     967             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[11], strlen(stat_sb_names[11])+1, (void *) &stat_blksize, sizeof(zval *), NULL);
     968             120 :                 zend_hash_update(HASH_OF(return_value), stat_sb_names[12], strlen(stat_sb_names[12])+1, (void *) &stat_blocks, sizeof(zval *), NULL);
     969                 : 
     970             120 :                 return;
     971                 :         }
     972               0 :         php_error_docref(NULL TSRMLS_CC, E_WARNING, "Didn't understand stat call");
     973               0 :         RETURN_FALSE;
     974                 : }
     975                 : /* }}} */
     976                 : 
     977                 : /* another quickie macro to make defining similar functions easier */
     978                 : #define FileFunction(name, funcnum) \
     979                 : void name(INTERNAL_FUNCTION_PARAMETERS) { \
     980                 :         zval **filename; \
     981                 :         if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { \
     982                 :                 WRONG_PARAM_COUNT; \
     983                 :         } \
     984                 :         convert_to_string_ex(filename); \
     985                 :         php_stat(Z_STRVAL_PP(filename), (php_stat_len) Z_STRLEN_PP(filename), funcnum, return_value TSRMLS_CC); \
     986                 : }
     987                 : 
     988                 : /* {{{ proto int fileperms(string filename)
     989                 :    Get file permissions */
     990            6782 : FileFunction(PHP_FN(fileperms), FS_PERMS)
     991                 : /* }}} */
     992                 : 
     993                 : /* {{{ proto int fileinode(string filename)
     994                 :    Get file inode */
     995              68 : FileFunction(PHP_FN(fileinode), FS_INODE)
     996                 : /* }}} */
     997                 : 
     998                 : /* {{{ proto int filesize(string filename)
     999                 :    Get file size */
    1000            9912 : FileFunction(PHP_FN(filesize), FS_SIZE)
    1001                 : /* }}} */
    1002                 : 
    1003                 : /* {{{ proto int fileowner(string filename)
    1004                 :    Get file owner */
    1005              79 : FileFunction(PHP_FN(fileowner), FS_OWNER)
    1006                 : /* }}} */
    1007                 : 
    1008                 : /* {{{ proto int filegroup(string filename)
    1009                 :    Get file group */
    1010              51 : FileFunction(PHP_FN(filegroup), FS_GROUP)
    1011                 : /* }}} */
    1012                 : 
    1013                 : /* {{{ proto int fileatime(string filename)
    1014                 :    Get last access time of file */
    1015              52 : FileFunction(PHP_FN(fileatime), FS_ATIME)
    1016                 : /* }}} */
    1017                 : 
    1018                 : /* {{{ proto int filemtime(string filename)
    1019                 :    Get last modification time of file */
    1020              51 : FileFunction(PHP_FN(filemtime), FS_MTIME)
    1021                 : /* }}} */
    1022                 : 
    1023                 : /* {{{ proto int filectime(string filename)
    1024                 :    Get inode modification time of file */
    1025              47 : FileFunction(PHP_FN(filectime), FS_CTIME)
    1026                 : /* }}} */
    1027                 : 
    1028                 : /* {{{ proto string filetype(string filename)
    1029                 :    Get file type */
    1030              37 : FileFunction(PHP_FN(filetype), FS_TYPE)
    1031                 : /* }}} */
    1032                 : 
    1033                 : /* {{{ proto bool is_writable(string filename)
    1034                 :    Returns true if file can be written */
    1035            1113 : FileFunction(PHP_FN(is_writable), FS_IS_W)
    1036                 : /* }}} */
    1037                 : 
    1038                 : /* {{{ proto bool is_readable(string filename)
    1039                 :    Returns true if file can be read */
    1040             694 : FileFunction(PHP_FN(is_readable), FS_IS_R)
    1041                 : /* }}} */
    1042                 : 
    1043                 : /* {{{ proto bool is_executable(string filename)
    1044                 :    Returns true if file is executable */
    1045             607 : FileFunction(PHP_FN(is_executable), FS_IS_X)
    1046                 : /* }}} */
    1047                 : 
    1048                 : /* {{{ proto bool is_file(string filename)
    1049                 :    Returns true if file is a regular file */
    1050             934 : FileFunction(PHP_FN(is_file), FS_IS_FILE)
    1051                 : /* }}} */
    1052                 : 
    1053                 : /* {{{ proto bool is_dir(string filename)
    1054                 :    Returns true if file is directory */
    1055           45092 : FileFunction(PHP_FN(is_dir), FS_IS_DIR)
    1056                 : /* }}} */
    1057                 : 
    1058                 : /* {{{ proto bool is_link(string filename)
    1059                 :    Returns true if file is symbolic link */
    1060              65 : FileFunction(PHP_FN(is_link), FS_IS_LINK)
    1061                 : /* }}} */
    1062                 : 
    1063                 : /* {{{ proto bool file_exists(string filename)
    1064                 :    Returns true if filename exists */
    1065            2834 : FileFunction(PHP_FN(file_exists), FS_EXISTS)
    1066                 : /* }}} */
    1067                 : 
    1068                 : /* {{{ proto array lstat(string filename)
    1069                 :    Give information about a file or symbolic link */
    1070              45 : FileFunction(php_if_lstat, FS_LSTAT)
    1071                 : /* }}} */
    1072                 : 
    1073                 : /* {{{ proto array stat(string filename)
    1074                 :    Give information about a file */
    1075             117 : FileFunction(php_if_stat, FS_STAT)
    1076                 : /* }}} */
    1077                 : 
    1078                 : /*
    1079                 :  * Local variables:
    1080                 :  * tab-width: 4
    1081                 :  * c-basic-offset: 4
    1082                 :  * End:
    1083                 :  * vim600: sw=4 ts=4 fdm=marker
    1084                 :  * vim<600: sw=4 ts=4
    1085                 :  */

Generated by: LTP GCOV extension version 1.5

Generated at Thu, 19 Nov 2009 08:20:23 +0000 (5 days ago)

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