1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2007 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,v 1.136.2.8.2.12 2007/04/06 22:10:56 tony2001 Exp $ */
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 219 : {
103 219 : BG(CurrentStatFile)=NULL;
104 219 : BG(CurrentLStatFile)=NULL;
105 219 : return SUCCESS;
106 : }
107 : /* }}} */
108 :
109 : PHP_RSHUTDOWN_FUNCTION(filestat) /* {{{ */
110 219 : {
111 219 : if (BG(CurrentStatFile)) {
112 3 : efree (BG(CurrentStatFile));
113 3 : BG(CurrentStatFile) = NULL;
114 : }
115 219 : if (BG(CurrentLStatFile)) {
116 0 : efree (BG(CurrentLStatFile));
117 0 : BG(CurrentLStatFile) = NULL;
118 : }
119 219 : 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 0 : {
198 0 : 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 0 : if (statvfs(path, &buf)) {
207 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
208 0 : return FAILURE;
209 : }
210 0 : if (buf.f_frsize) {
211 0 : 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 0 : *space = bytestotal;
225 0 : 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 0 : {
235 : double bytestotal;
236 : char *path;
237 : int path_len;
238 :
239 0 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE) {
240 0 : return;
241 : }
242 :
243 0 : if (php_check_open_basedir(path TSRMLS_CC)) {
244 0 : RETURN_FALSE;
245 : }
246 :
247 0 : if (php_disk_total_space(path, &bytestotal TSRMLS_CC) == SUCCESS) {
248 0 : RETURN_DOUBLE(bytestotal);
249 : }
250 0 : 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 0 : {
330 0 : 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 0 : if (statvfs(path, &buf)) {
339 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
340 0 : return FAILURE;
341 : }
342 0 : if (buf.f_frsize) {
343 0 : 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 0 : *space = bytesfree;
360 0 : 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 0 : {
370 : double bytesfree;
371 : char *path;
372 : int path_len;
373 :
374 0 : if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &path_len) == FAILURE) {
375 0 : return;
376 : }
377 :
378 0 : if (php_check_open_basedir(path TSRMLS_CC)) {
379 0 : RETURN_FALSE;
380 : }
381 :
382 0 : if (php_disk_free_space(path, &bytesfree TSRMLS_CC) == SUCCESS) {
383 0 : RETURN_DOUBLE(bytesfree);
384 : }
385 0 : RETURN_FALSE;
386 : }
387 : /* }}} */
388 :
389 : #if !defined(WINDOWS)
390 : static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */
391 0 : {
392 : zval **filename, **group;
393 : gid_t gid;
394 : int ret;
395 :
396 0 : if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &group)==FAILURE) {
397 0 : WRONG_PARAM_COUNT;
398 : }
399 0 : convert_to_string_ex(filename);
400 0 : 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 0 : convert_to_long_ex(group);
430 0 : gid = Z_LVAL_PP(group);
431 : }
432 :
433 0 : 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 0 : if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
439 0 : RETURN_FALSE;
440 : }
441 :
442 0 : if (do_lchgrp) {
443 : #if HAVE_LCHOWN
444 0 : 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 0 : if (ret == -1) {
450 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
451 0 : RETURN_FALSE;
452 : }
453 0 : 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 0 : {
476 : # if !defined(WINDOWS)
477 0 : php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
478 : # else
479 : RETURN_FALSE;
480 : # endif
481 0 : }
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 0 : {
588 : zval **filename, **mode;
589 : int ret;
590 : mode_t imode;
591 :
592 0 : if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, &mode)==FAILURE) {
593 0 : WRONG_PARAM_COUNT;
594 : }
595 0 : convert_to_string_ex(filename);
596 0 : convert_to_long_ex(mode);
597 :
598 0 : 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 0 : if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
604 0 : RETURN_FALSE;
605 : }
606 :
607 0 : 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 0 : if(PG(safe_mode)) {
614 : php_stream_statbuf ssb;
615 0 : 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 0 : if ((imode & 04000) != 0 && (ssb.sb.st_mode & 04000) == 0) {
620 0 : imode ^= 04000;
621 : }
622 0 : if ((imode & 02000) != 0 && (ssb.sb.st_mode & 02000) == 0) {
623 0 : imode ^= 02000;
624 : }
625 0 : if ((imode & 01000) != 0 && (ssb.sb.st_mode & 01000) == 0) {
626 0 : imode ^= 01000;
627 : }
628 : }
629 :
630 0 : ret = VCWD_CHMOD(Z_STRVAL_PP(filename), imode);
631 0 : if (ret == -1) {
632 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
633 0 : RETURN_FALSE;
634 : }
635 0 : 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 0 : {
644 : zval **filename, **filetime, **fileatime;
645 : int ret;
646 : FILE *file;
647 : struct utimbuf newtimebuf;
648 0 : struct utimbuf *newtime = NULL;
649 0 : int ac = ZEND_NUM_ARGS();
650 :
651 :
652 0 : 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 0 : } else if (ac == 2 && zend_get_parameters_ex(2, &filename, &filetime) != FAILURE) {
658 0 : convert_to_long_ex(filetime);
659 0 : newtime = &newtimebuf;
660 0 : newtime->modtime = newtime->actime = Z_LVAL_PP(filetime);
661 0 : } else if (ac == 3 && zend_get_parameters_ex(3, &filename, &filetime, &fileatime) != FAILURE) {
662 0 : convert_to_long_ex(fileatime);
663 0 : convert_to_long_ex(filetime);
664 0 : newtime = &newtimebuf;
665 0 : newtime->actime = Z_LVAL_PP(fileatime);
666 0 : newtime->modtime = Z_LVAL_PP(filetime);
667 : } else {
668 0 : WRONG_PARAM_COUNT;
669 : }
670 0 : convert_to_string_ex(filename);
671 :
672 0 : 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 0 : if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
678 0 : RETURN_FALSE;
679 : }
680 :
681 : /* create the file if it doesn't exist already */
682 0 : if (VCWD_ACCESS(Z_STRVAL_PP(filename), F_OK) != 0) {
683 0 : file = VCWD_FOPEN(Z_STRVAL_PP(filename), "w");
684 0 : if (file == NULL) {
685 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create file %s because %s", Z_STRVAL_PP(filename), strerror(errno));
686 0 : RETURN_FALSE;
687 : }
688 0 : fclose(file);
689 : }
690 :
691 0 : ret = VCWD_UTIME(Z_STRVAL_PP(filename), newtime);
692 0 : if (ret == -1) {
693 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Utime failed: %s", strerror(errno));
694 0 : RETURN_FALSE;
695 : }
696 0 : RETURN_TRUE;
697 : }
698 : /* }}} */
699 : #endif
700 :
701 : /* {{{ proto void clearstatcache(void)
702 : Clear file stat cache */
703 : PHP_FUNCTION(clearstatcache)
704 255 : {
705 255 : if (BG(CurrentStatFile)) {
706 1 : efree(BG(CurrentStatFile));
707 1 : BG(CurrentStatFile) = NULL;
708 : }
709 255 : if (BG(CurrentLStatFile)) {
710 0 : efree(BG(CurrentLStatFile));
711 0 : BG(CurrentLStatFile) = NULL;
712 : }
713 255 : realpath_cache_clean(TSRMLS_C);
714 255 : }
715 : /* }}} */
716 :
717 : #define IS_LINK_OPERATION(__t) ((__t) == FS_TYPE || (__t) == FS_IS_LINK || (__t) == FS_LSTAT)
718 : #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)
719 : #define IS_ABLE_CHECK(__t) ((__t) == FS_IS_R || (__t) == FS_IS_W || (__t) == FS_IS_X)
720 : #define IS_ACCESS_CHECK(__t) (IS_ABLE_CHECK(type) || (__t) == FS_EXISTS)
721 :
722 : /* {{{ php_stat
723 : */
724 : PHPAPI void php_stat(const char *filename, php_stat_len filename_length, int type, zval *return_value TSRMLS_DC)
725 823 : {
726 : zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev,
727 : *stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks;
728 : struct stat *stat_sb;
729 : php_stream_statbuf ssb;
730 823 : int flags = 0, rmask=S_IROTH, wmask=S_IWOTH, xmask=S_IXOTH; /* access rights defaults to other */
731 : char *stat_sb_names[13]={"dev", "ino", "mode", "nlink", "uid", "gid", "rdev",
732 823 : "size", "atime", "mtime", "ctime", "blksize", "blocks"};
733 : char *local;
734 : php_stream_wrapper *wrapper;
735 : char safe_mode_buf[MAXPATHLEN];
736 :
737 823 : if (!filename_length) {
738 0 : RETURN_FALSE;
739 : }
740 :
741 823 : if ((wrapper = php_stream_locate_url_wrapper(filename, &local, 0 TSRMLS_CC)) == &php_plain_files_wrapper) {
742 823 : if (php_check_open_basedir(local TSRMLS_CC)) {
743 0 : RETURN_FALSE;
744 823 : } else if (PG(safe_mode)) {
745 0 : if (type == FS_IS_X) {
746 0 : if (strstr(local, "..")) {
747 0 : RETURN_FALSE;
748 : } else {
749 0 : char *b = strrchr(local, PHP_DIR_SEPARATOR);
750 0 : snprintf(safe_mode_buf, MAXPATHLEN, "%s%s%s", PG(safe_mode_exec_dir), (b ? "" : "/"), (b ? b : local));
751 0 : local = (char *)&safe_mode_buf;
752 : }
753 0 : } else if (!php_checkuid_ex(local, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS, CHECKUID_NO_ERRORS)) {
754 0 : RETURN_FALSE;
755 : }
756 : }
757 : }
758 :
759 823 : if (IS_ACCESS_CHECK(type)) {
760 3 : if (wrapper == &php_plain_files_wrapper) {
761 :
762 3 : switch (type) {
763 : #ifdef F_OK
764 : case FS_EXISTS:
765 2 : RETURN_BOOL(VCWD_ACCESS(local, F_OK) == 0);
766 : break;
767 : #endif
768 : #ifdef W_OK
769 : case FS_IS_W:
770 0 : RETURN_BOOL(VCWD_ACCESS(local, W_OK) == 0);
771 : break;
772 : #endif
773 : #ifdef R_OK
774 : case FS_IS_R:
775 0 : RETURN_BOOL(VCWD_ACCESS(local, R_OK) == 0);
776 : break;
777 : #endif
778 : #ifdef X_OK
779 : case FS_IS_X:
780 1 : RETURN_BOOL(VCWD_ACCESS(local, X_OK) == 0);
781 : break;
782 : #endif
783 : }
784 : }
785 : }
786 :
787 820 : if (IS_LINK_OPERATION(type)) {
788 0 : flags |= PHP_STREAM_URL_STAT_LINK;
789 : }
790 820 : if (IS_EXISTS_CHECK(type)) {
791 771 : flags |= PHP_STREAM_URL_STAT_QUIET;
792 : }
793 :
794 820 : if (php_stream_stat_path_ex((char *)filename, flags, &ssb, NULL)) {
795 : /* Error Occured */
796 4 : if (!IS_EXISTS_CHECK(type)) {
797 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "%sstat failed for %s", IS_LINK_OPERATION(type) ? "L" : "", filename);
798 : }
799 4 : RETURN_FALSE;
800 : }
801 :
802 816 : stat_sb = &ssb.sb;
803 :
804 :
805 : #ifndef NETWARE
806 816 : if (type >= FS_IS_W && type <= FS_IS_X) {
807 0 : if(ssb.sb.st_uid==getuid()) {
808 0 : rmask=S_IRUSR;
809 0 : wmask=S_IWUSR;
810 0 : xmask=S_IXUSR;
811 0 : } else if(ssb.sb.st_gid==getgid()) {
812 0 : rmask=S_IRGRP;
813 0 : wmask=S_IWGRP;
814 0 : xmask=S_IXGRP;
815 : } else {
816 : int groups, n, i;
817 : gid_t *gids;
818 :
819 0 : groups = getgroups(0, NULL);
820 0 : if(groups) {
821 0 : gids=(gid_t *)safe_emalloc(groups, sizeof(gid_t), 0);
822 0 : n=getgroups(groups, gids);
823 0 : for(i=0;i<n;i++){
824 0 : if(ssb.sb.st_gid==gids[i]) {
825 0 : rmask=S_IRGRP;
826 0 : wmask=S_IWGRP;
827 0 : xmask=S_IXGRP;
828 0 : break;
829 : }
830 : }
831 0 : efree(gids);
832 : }
833 : }
834 : }
835 : #endif
836 :
837 : #ifndef NETWARE
838 816 : if (IS_ABLE_CHECK(type) && getuid() == 0) {
839 : /* root has special perms on plain_wrapper
840 : But we don't know about root under Netware */
841 0 : if (wrapper == &php_plain_files_wrapper) {
842 0 : if (type == FS_IS_X) {
843 0 : xmask = S_IXROOT;
844 : } else {
845 0 : RETURN_TRUE;
846 : }
847 : }
848 : }
849 : #endif
850 :
851 816 : switch (type) {
852 : case FS_PERMS:
853 0 : RETURN_LONG((long)ssb.sb.st_mode);
854 : case FS_INODE:
855 0 : RETURN_LONG((long)ssb.sb.st_ino);
856 : case FS_SIZE:
857 0 : RETURN_LONG((long)ssb.sb.st_size);
858 : case FS_OWNER:
859 0 : RETURN_LONG((long)ssb.sb.st_uid);
860 : case FS_GROUP:
861 0 : RETURN_LONG((long)ssb.sb.st_gid);
862 : case FS_ATIME:
863 : #ifdef NETWARE
864 : RETURN_LONG((long)ssb.sb.st_atime.tv_sec);
865 : #else
866 0 : RETURN_LONG((long)ssb.sb.st_atime);
867 : #endif
868 : case FS_MTIME:
869 : #ifdef NETWARE
870 : RETURN_LONG((long)ssb.sb.st_mtime.tv_sec);
871 : #else
872 49 : RETURN_LONG((long)ssb.sb.st_mtime);
873 : #endif
874 : case FS_CTIME:
875 : #ifdef NETWARE
876 : RETURN_LONG((long)ssb.sb.st_ctime.tv_sec);
877 : #else
878 0 : RETURN_LONG((long)ssb.sb.st_ctime);
879 : #endif
880 : case FS_TYPE:
881 0 : if (S_ISLNK(ssb.sb.st_mode)) {
882 0 : RETURN_STRING("link", 1);
883 : }
884 0 : switch(ssb.sb.st_mode & S_IFMT) {
885 0 : case S_IFIFO: RETURN_STRING("fifo", 1);
886 0 : case S_IFCHR: RETURN_STRING("char", 1);
887 0 : case S_IFDIR: RETURN_STRING("dir", 1);
888 0 : case S_IFBLK: RETURN_STRING("block", 1);
889 0 : case S_IFREG: RETURN_STRING("file", 1);
890 : #if defined(S_IFSOCK) && !defined(ZEND_WIN32)&&!defined(__BEOS__)
891 0 : case S_IFSOCK: RETURN_STRING("socket", 1);
892 : #endif
893 : }
894 0 : php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown file type (%d)", ssb.sb.st_mode&S_IFMT);
895 0 : RETURN_STRING("unknown", 1);
896 : case FS_IS_W:
897 0 : RETURN_BOOL((ssb.sb.st_mode & wmask) != 0);
898 : case FS_IS_R:
899 0 : RETURN_BOOL((ssb.sb.st_mode&rmask)!=0);
900 : case FS_IS_X:
901 0 : RETURN_BOOL((ssb.sb.st_mode&xmask)!=0 && !S_ISDIR(ssb.sb.st_mode));
902 : case FS_IS_FILE:
903 49 : RETURN_BOOL(S_ISREG(ssb.sb.st_mode));
904 : case FS_IS_DIR:
905 718 : RETURN_BOOL(S_ISDIR(ssb.sb.st_mode));
906 : case FS_IS_LINK:
907 0 : RETURN_BOOL(S_ISLNK(ssb.sb.st_mode));
908 : case FS_EXISTS:
909 0 : RETURN_TRUE; /* the false case was done earlier */
910 : case FS_LSTAT:
911 : /* FALLTHROUGH */
912 : case FS_STAT:
913 0 : array_init(return_value);
914 :
915 0 : MAKE_LONG_ZVAL_INCREF(stat_dev, stat_sb->st_dev);
916 0 : MAKE_LONG_ZVAL_INCREF(stat_ino, stat_sb->st_ino);
917 0 : MAKE_LONG_ZVAL_INCREF(stat_mode, stat_sb->st_mode);
918 0 : MAKE_LONG_ZVAL_INCREF(stat_nlink, stat_sb->st_nlink);
919 0 : MAKE_LONG_ZVAL_INCREF(stat_uid, stat_sb->st_uid);
920 0 : MAKE_LONG_ZVAL_INCREF(stat_gid, stat_sb->st_gid);
921 : #ifdef HAVE_ST_RDEV
922 0 : MAKE_LONG_ZVAL_INCREF(stat_rdev, stat_sb->st_rdev);
923 : #else
924 : MAKE_LONG_ZVAL_INCREF(stat_rdev, -1);
925 : #endif
926 0 : MAKE_LONG_ZVAL_INCREF(stat_size, stat_sb->st_size);
927 : #ifdef NETWARE
928 : MAKE_LONG_ZVAL_INCREF(stat_atime, (stat_sb->st_atime).tv_sec);
929 : MAKE_LONG_ZVAL_INCREF(stat_mtime, (stat_sb->st_mtime).tv_sec);
930 : MAKE_LONG_ZVAL_INCREF(stat_ctime, (stat_sb->st_ctime).tv_sec);
931 : #else
932 0 : MAKE_LONG_ZVAL_INCREF(stat_atime, stat_sb->st_atime);
933 0 : MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_sb->st_mtime);
934 0 : MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_sb->st_ctime);
935 : #endif
936 : #ifdef HAVE_ST_BLKSIZE
937 0 : MAKE_LONG_ZVAL_INCREF(stat_blksize, stat_sb->st_blksize);
938 : #else
939 : MAKE_LONG_ZVAL_INCREF(stat_blksize,-1);
940 : #endif
941 : #ifdef HAVE_ST_BLOCKS
942 0 : MAKE_LONG_ZVAL_INCREF(stat_blocks, stat_sb->st_blocks);
943 : #else
944 : MAKE_LONG_ZVAL_INCREF(stat_blocks,-1);
945 : #endif
946 : /* Store numeric indexes in propper order */
947 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_dev, sizeof(zval *), NULL);
948 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ino, sizeof(zval *), NULL);
949 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mode, sizeof(zval *), NULL);
950 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_nlink, sizeof(zval *), NULL);
951 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_uid, sizeof(zval *), NULL);
952 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_gid, sizeof(zval *), NULL);
953 :
954 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_rdev, sizeof(zval *), NULL);
955 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_size, sizeof(zval *), NULL);
956 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_atime, sizeof(zval *), NULL);
957 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mtime, sizeof(zval *), NULL);
958 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ctime, sizeof(zval *), NULL);
959 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blksize, sizeof(zval *), NULL);
960 0 : zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blocks, sizeof(zval *), NULL);
961 :
962 : /* Store string indexes referencing the same zval*/
963 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[0], strlen(stat_sb_names[0])+1, (void *) &stat_dev, sizeof(zval *), NULL);
964 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[1], strlen(stat_sb_names[1])+1, (void *) &stat_ino, sizeof(zval *), NULL);
965 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[2], strlen(stat_sb_names[2])+1, (void *) &stat_mode, sizeof(zval *), NULL);
966 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[3], strlen(stat_sb_names[3])+1, (void *) &stat_nlink, sizeof(zval *), NULL);
967 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[4], strlen(stat_sb_names[4])+1, (void *) &stat_uid, sizeof(zval *), NULL);
968 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[5], strlen(stat_sb_names[5])+1, (void *) &stat_gid, sizeof(zval *), NULL);
969 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[6], strlen(stat_sb_names[6])+1, (void *) &stat_rdev, sizeof(zval *), NULL);
970 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[7], strlen(stat_sb_names[7])+1, (void *) &stat_size, sizeof(zval *), NULL);
971 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[8], strlen(stat_sb_names[8])+1, (void *) &stat_atime, sizeof(zval *), NULL);
972 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[9], strlen(stat_sb_names[9])+1, (void *) &stat_mtime, sizeof(zval *), NULL);
973 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[10], strlen(stat_sb_names[10])+1, (void *) &stat_ctime, sizeof(zval *), NULL);
974 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[11], strlen(stat_sb_names[11])+1, (void *) &stat_blksize, sizeof(zval *), NULL);
975 0 : zend_hash_update(HASH_OF(return_value), stat_sb_names[12], strlen(stat_sb_names[12])+1, (void *) &stat_blocks, sizeof(zval *), NULL);
976 :
977 0 : return;
978 : }
979 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Didn't understand stat call");
980 0 : RETURN_FALSE;
981 : }
982 : /* }}} */
983 :
984 : /* another quickie macro to make defining similar functions easier */
985 : #define FileFunction(name, funcnum) \
986 : void name(INTERNAL_FUNCTION_PARAMETERS) { \
987 : zval **filename; \
988 : if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) { \
989 : WRONG_PARAM_COUNT; \
990 : } \
991 : convert_to_string_ex(filename); \
992 : php_stat(Z_STRVAL_PP(filename), (php_stat_len) Z_STRLEN_PP(filename), funcnum, return_value TSRMLS_CC); \
993 : }
994 :
995 : /* {{{ proto int fileperms(string filename)
996 : Get file permissions */
997 0 : FileFunction(PHP_FN(fileperms), FS_PERMS)
998 : /* }}} */
999 :
1000 : /* {{{ proto int fileinode(string filename)
1001 : Get file inode */
1002 0 : FileFunction(PHP_FN(fileinode), FS_INODE)
1003 : /* }}} */
1004 :
1005 : /* {{{ proto int filesize(string filename)
1006 : Get file size */
1007 0 : FileFunction(PHP_FN(filesize), FS_SIZE)
1008 : /* }}} */
1009 :
1010 : /* {{{ proto int fileowner(string filename)
1011 : Get file owner */
1012 0 : FileFunction(PHP_FN(fileowner), FS_OWNER)
1013 : /* }}} */
1014 :
1015 : /* {{{ proto int filegroup(string filename)
1016 : Get file group */
1017 0 : FileFunction(PHP_FN(filegroup), FS_GROUP)
1018 : /* }}} */
1019 :
1020 : /* {{{ proto int fileatime(string filename)
1021 : Get last access time of file */
1022 0 : FileFunction(PHP_FN(fileatime), FS_ATIME)
1023 : /* }}} */
1024 :
1025 : /* {{{ proto int filemtime(string filename)
1026 : Get last modification time of file */
1027 49 : FileFunction(PHP_FN(filemtime), FS_MTIME)
1028 : /* }}} */
1029 :
1030 : /* {{{ proto int filectime(string filename)
1031 : Get inode modification time of file */
1032 0 : FileFunction(PHP_FN(filectime), FS_CTIME)
1033 : /* }}} */
1034 :
1035 : /* {{{ proto string filetype(string filename)
1036 : Get file type */
1037 0 : FileFunction(PHP_FN(filetype), FS_TYPE)
1038 : /* }}} */
1039 :
1040 : /* {{{ proto bool is_writable(string filename)
1041 : Returns true if file can be written */
1042 0 : FileFunction(PHP_FN(is_writable), FS_IS_W)
1043 : /* }}} */
1044 :
1045 : /* {{{ proto bool is_readable(string filename)
1046 : Returns true if file can be read */
1047 0 : FileFunction(PHP_FN(is_readable), FS_IS_R)
1048 : /* }}} */
1049 :
1050 : /* {{{ proto bool is_executable(string filename)
1051 : Returns true if file is executable */
1052 1 : FileFunction(PHP_FN(is_executable), FS_IS_X)
1053 : /* }}} */
1054 :
1055 : /* {{{ proto bool is_file(string filename)
1056 : Returns true if file is a regular file */
1057 53 : FileFunction(PHP_FN(is_file), FS_IS_FILE)
1058 : /* }}} */
1059 :
1060 : /* {{{ proto bool is_dir(string filename)
1061 : Returns true if file is directory */
1062 718 : FileFunction(PHP_FN(is_dir), FS_IS_DIR)
1063 : /* }}} */
1064 :
1065 : /* {{{ proto bool is_link(string filename)
1066 : Returns true if file is symbolic link */
1067 0 : FileFunction(PHP_FN(is_link), FS_IS_LINK)
1068 : /* }}} */
1069 :
1070 : /* {{{ proto bool file_exists(string filename)
1071 : Returns true if filename exists */
1072 2 : FileFunction(PHP_FN(file_exists), FS_EXISTS)
1073 : /* }}} */
1074 :
1075 : /* {{{ proto array lstat(string filename)
1076 : Give information about a file or symbolic link */
1077 0 : FileFunction(php_if_lstat, FS_LSTAT)
1078 : /* }}} */
1079 :
1080 : /* {{{ proto array stat(string filename)
1081 : Give information about a file */
1082 0 : FileFunction(php_if_stat, FS_STAT)
1083 : /* }}} */
1084 :
1085 : /*
1086 : * Local variables:
1087 : * tab-width: 4
1088 : * c-basic-offset: 4
1089 : * End:
1090 : * vim600: sw=4 ts=4 fdm=marker
1091 : * vim<600: sw=4 ts=4
1092 : */
|