1999-04-17 08:37:12 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| PHP version 4.0 |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| Copyright (c) 1997, 1998, 1999 The PHP Group |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| This source file is subject to version 2.0 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
| http://www.php.net/license/2_0.txt. |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Jim Winstead <jimw@php.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* $Id$ */
|
1999-04-24 04:06:01 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
#include "php.h"
|
|
|
|
#include "safe_mode.h"
|
|
|
|
#include "fopen-wrappers.h"
|
|
|
|
#include "php_globals.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_PWD_H
|
|
|
|
# if MSVC5
|
|
|
|
# include "win32/pwd.h"
|
|
|
|
# else
|
|
|
|
# include <pwd.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_GRP_H
|
|
|
|
# if MSVC5
|
|
|
|
# include "win32/grp.h"
|
|
|
|
# else
|
|
|
|
# include <grp.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_UTIME
|
|
|
|
# if MSVC5
|
|
|
|
# include <sys/utime.h>
|
|
|
|
# else
|
|
|
|
# include <utime.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "php3_filestat.h"
|
|
|
|
|
|
|
|
#ifndef THREAD_SAFE
|
|
|
|
static char *CurrentStatFile=NULL;
|
|
|
|
# if MSVC5
|
|
|
|
static unsigned int CurrentStatLength=0;
|
|
|
|
# else
|
|
|
|
static int CurrentStatLength=0;
|
|
|
|
# endif
|
|
|
|
static struct stat sb;
|
|
|
|
#if HAVE_SYMLINK
|
|
|
|
static struct stat lsb;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef S_ISDIR
|
|
|
|
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISREG
|
|
|
|
#define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
|
|
|
|
#endif
|
|
|
|
#ifndef S_ISLNK
|
|
|
|
#define S_ISLNK(mode) (((mode)&S_IFMT) == S_IFLNK)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
1999-07-27 04:09:08 +08:00
|
|
|
PHP_RINIT_FUNCTION(filestat)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-04-24 08:12:00 +08:00
|
|
|
CurrentStatFile=NULL;
|
|
|
|
CurrentStatLength=0;
|
1999-04-17 08:37:12 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-27 04:09:08 +08:00
|
|
|
PHP_RSHUTDOWN_FUNCTION(filestat)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-04-24 08:12:00 +08:00
|
|
|
if (CurrentStatFile) {
|
|
|
|
efree (CurrentStatFile);
|
1999-04-21 12:02:11 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(chgrp)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
|
|
|
#ifndef WINDOWS
|
|
|
|
pval *filename, *group;
|
|
|
|
gid_t gid;
|
|
|
|
struct group *gr=NULL;
|
|
|
|
int ret;
|
1999-08-16 02:52:10 +08:00
|
|
|
PLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&group)==FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_string(filename);
|
|
|
|
if (group->type == IS_STRING) {
|
|
|
|
gr = getgrnam(group->value.str.val);
|
|
|
|
if (!gr) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "unable to find gid for %s",
|
1999-04-17 08:37:12 +08:00
|
|
|
group->value.str.val);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
gid = gr->gr_gid;
|
|
|
|
} else {
|
|
|
|
convert_to_long(group);
|
|
|
|
gid = group->value.lval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the basedir */
|
|
|
|
if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE;
|
|
|
|
|
|
|
|
ret = chown(filename->value.str.val, -1, gid);
|
|
|
|
if (ret == -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "chgrp failed: %s", strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
1999-04-21 12:02:11 +08:00
|
|
|
#else
|
|
|
|
RETURN_FALSE;
|
|
|
|
#endif
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
1999-04-21 12:02:11 +08:00
|
|
|
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(chown)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
|
|
|
#ifndef WINDOWS
|
|
|
|
pval *filename, *user;
|
|
|
|
int ret;
|
|
|
|
uid_t uid;
|
|
|
|
struct passwd *pw = NULL;
|
1999-08-16 02:52:10 +08:00
|
|
|
PLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&user)==FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_string(filename);
|
|
|
|
if (user->type == IS_STRING) {
|
|
|
|
pw = getpwnam(user->value.str.val);
|
|
|
|
if (!pw) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "unable to find uid for %s",
|
1999-04-17 08:37:12 +08:00
|
|
|
user->value.str.val);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
uid = pw->pw_uid;
|
|
|
|
} else {
|
|
|
|
convert_to_long(user);
|
|
|
|
uid = user->value.lval;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the basedir */
|
|
|
|
if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE;
|
|
|
|
|
|
|
|
ret = chown(filename->value.str.val, uid, -1);
|
|
|
|
if (ret == -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "chown failed: %s", strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-04-21 12:02:11 +08:00
|
|
|
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(chmod)
|
1999-04-21 12:02:11 +08:00
|
|
|
{
|
1999-04-17 08:37:12 +08:00
|
|
|
pval *filename, *mode;
|
|
|
|
int ret;
|
1999-04-21 12:02:11 +08:00
|
|
|
PLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&filename,&mode)==FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_string(filename);
|
|
|
|
convert_to_long(mode);
|
|
|
|
|
|
|
|
if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the basedir */
|
|
|
|
if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE;
|
|
|
|
|
|
|
|
ret = chmod(filename->value.str.val, mode->value.lval);
|
|
|
|
if (ret == -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "chmod failed: %s", strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-04-21 12:02:11 +08:00
|
|
|
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(touch)
|
1999-04-21 12:02:11 +08:00
|
|
|
{
|
1999-04-17 08:37:12 +08:00
|
|
|
#if HAVE_UTIME
|
|
|
|
pval *filename, *filetime;
|
|
|
|
int ret;
|
|
|
|
struct stat sb;
|
|
|
|
FILE *file;
|
|
|
|
struct utimbuf *newtime = NULL;
|
|
|
|
int ac = ARG_COUNT(ht);
|
1999-04-21 12:02:11 +08:00
|
|
|
PLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
if (ac == 1 && getParameters(ht,1,&filename) != FAILURE) {
|
|
|
|
#ifndef HAVE_UTIME_NULL
|
|
|
|
newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf));
|
|
|
|
if (!newtime) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "unable to emalloc memory for changing time");
|
1999-04-17 08:37:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
newtime->actime = time(NULL);
|
|
|
|
newtime->modtime = newtime->actime;
|
|
|
|
#endif
|
|
|
|
} else if (ac == 2 && getParameters(ht,2,&filename,&filetime) != FAILURE) {
|
|
|
|
newtime = (struct utimbuf *)emalloc(sizeof(struct utimbuf));
|
|
|
|
if (!newtime) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "unable to emalloc memory for changing time");
|
1999-04-17 08:37:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
convert_to_long(filetime);
|
|
|
|
newtime->actime = filetime->value.lval;
|
|
|
|
newtime->modtime = filetime->value.lval;
|
|
|
|
} else {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_string(filename);
|
|
|
|
|
|
|
|
if (PG(safe_mode) &&(!_php3_checkuid(filename->value.str.val, 1))) {
|
|
|
|
if (newtime) efree(newtime);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the basedir */
|
|
|
|
if (_php3_check_open_basedir(filename->value.str.val)) RETURN_FALSE;
|
|
|
|
|
|
|
|
/* create the file if it doesn't exist already */
|
|
|
|
ret = stat(filename->value.str.val, &sb);
|
|
|
|
if (ret == -1) {
|
|
|
|
file = fopen(filename->value.str.val, "w");
|
|
|
|
if (file == NULL) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "unable to create file %s because %s", filename->value.str.val, strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
if (newtime) efree(newtime);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = utime(filename->value.str.val, newtime);
|
|
|
|
if (newtime) efree(newtime);
|
|
|
|
if (ret == -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "utime failed: %s", strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-04-21 12:02:11 +08:00
|
|
|
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(clearstatcache)
|
1999-04-21 12:02:11 +08:00
|
|
|
{
|
1999-04-24 08:12:00 +08:00
|
|
|
if (CurrentStatFile) {
|
|
|
|
efree(CurrentStatFile);
|
|
|
|
CurrentStatFile = NULL;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-04-21 12:02:11 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
static void _php3_stat(const char *filename, int type, pval *return_value)
|
|
|
|
{
|
1999-04-24 08:12:00 +08:00
|
|
|
struct stat *stat_sb = &sb;
|
|
|
|
|
|
|
|
if (!CurrentStatFile || strcmp(filename,CurrentStatFile)) {
|
|
|
|
if (!CurrentStatFile
|
|
|
|
|| strlen(filename) > CurrentStatLength) {
|
|
|
|
if (CurrentStatFile) efree(CurrentStatFile);
|
|
|
|
CurrentStatLength = strlen(filename);
|
|
|
|
CurrentStatFile = estrndup(filename,CurrentStatLength);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
1999-04-24 08:12:00 +08:00
|
|
|
strcpy(CurrentStatFile,filename);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
#if HAVE_SYMLINK
|
1999-04-24 08:12:00 +08:00
|
|
|
lsb.st_mode = 0; /* mark lstat buf invalid */
|
1999-04-17 08:37:12 +08:00
|
|
|
#endif
|
1999-04-24 08:12:00 +08:00
|
|
|
if (stat(CurrentStatFile,&sb)==-1) {
|
1999-04-17 08:37:12 +08:00
|
|
|
if (type != 15 || errno != ENOENT) { /* fileexists() test must print no error */
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_NOTICE,"stat failed for %s (errno=%d - %s)",CurrentStatFile,errno,strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-04-24 08:12:00 +08:00
|
|
|
efree(CurrentStatFile);
|
|
|
|
CurrentStatFile=NULL;
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_SYMLINK
|
|
|
|
if (8 == type /* filetype */
|
|
|
|
|| 14 == type /* is link */
|
|
|
|
|| 16 == type) { /* lstat */
|
|
|
|
|
|
|
|
/* do lstat if the buffer is empty */
|
|
|
|
|
1999-04-24 08:12:00 +08:00
|
|
|
if (!lsb.st_mode) {
|
|
|
|
if (lstat(CurrentStatFile,&lsb) == -1) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_NOTICE,"lstat failed for %s (errno=%d - %s)",CurrentStatFile,errno,strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case 0: /* fileperms */
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((long)sb.st_mode);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 1: /* fileinode */
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((long)sb.st_ino);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 2: /* filesize */
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((long)sb.st_size);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 3: /* fileowner */
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((long)sb.st_uid);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 4: /* filegroup */
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((long)sb.st_gid);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 5: /* fileatime */
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((long)sb.st_atime);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 6: /* filemtime */
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((long)sb.st_mtime);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 7: /* filectime */
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((long)sb.st_ctime);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 8: /* filetype */
|
|
|
|
#if HAVE_SYMLINK
|
1999-04-24 08:12:00 +08:00
|
|
|
if (S_ISLNK(lsb.st_mode)) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_STRING("link",1);
|
|
|
|
}
|
|
|
|
#endif
|
1999-04-24 08:12:00 +08:00
|
|
|
switch(sb.st_mode&S_IFMT) {
|
1999-04-17 08:37:12 +08:00
|
|
|
case S_IFIFO: RETURN_STRING("fifo",1);
|
|
|
|
case S_IFCHR: RETURN_STRING("char",1);
|
|
|
|
case S_IFDIR: RETURN_STRING("dir",1);
|
|
|
|
case S_IFBLK: RETURN_STRING("block",1);
|
|
|
|
case S_IFREG: RETURN_STRING("file",1);
|
|
|
|
}
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"Unknown file type (%d)",sb.st_mode&S_IFMT);
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_STRING("unknown",1);
|
|
|
|
case 9: /*is writable*/
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((sb.st_mode&S_IWRITE)!=0);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 10: /*is readable*/
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((sb.st_mode&S_IREAD)!=0);
|
1999-04-17 08:37:12 +08:00
|
|
|
case 11: /*is executable*/
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG((sb.st_mode&S_IEXEC)!=0 && !S_ISDIR(sb.st_mode));
|
1999-04-17 08:37:12 +08:00
|
|
|
case 12: /*is file*/
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG(S_ISREG(sb.st_mode));
|
1999-04-17 08:37:12 +08:00
|
|
|
case 13: /*is dir*/
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG(S_ISDIR(sb.st_mode));
|
1999-04-17 08:37:12 +08:00
|
|
|
case 14: /*is link*/
|
|
|
|
#if HAVE_SYMLINK
|
1999-04-24 08:12:00 +08:00
|
|
|
RETURN_LONG(S_ISLNK(lsb.st_mode));
|
1999-04-17 08:37:12 +08:00
|
|
|
#else
|
|
|
|
RETURN_FALSE;
|
|
|
|
#endif
|
|
|
|
case 15: /*file exists*/
|
|
|
|
RETURN_TRUE; /* the false case was done earlier */
|
|
|
|
case 16: /* lstat */
|
|
|
|
#if HAVE_SYMLINK
|
1999-04-24 08:12:00 +08:00
|
|
|
stat_sb = &lsb;
|
1999-04-17 08:37:12 +08:00
|
|
|
#endif
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 17: /* stat */
|
|
|
|
if (array_init(return_value) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
add_next_index_long(return_value, stat_sb->st_dev);
|
|
|
|
add_next_index_long(return_value, stat_sb->st_ino);
|
|
|
|
add_next_index_long(return_value, stat_sb->st_mode);
|
|
|
|
add_next_index_long(return_value, stat_sb->st_nlink);
|
|
|
|
add_next_index_long(return_value, stat_sb->st_uid);
|
|
|
|
add_next_index_long(return_value, stat_sb->st_gid);
|
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
|
|
|
add_next_index_long(return_value, stat_sb->st_rdev);
|
|
|
|
#else
|
|
|
|
add_next_index_long(return_value, -1);
|
|
|
|
#endif
|
|
|
|
add_next_index_long(return_value, stat_sb->st_size);
|
|
|
|
add_next_index_long(return_value, stat_sb->st_atime);
|
|
|
|
add_next_index_long(return_value, stat_sb->st_mtime);
|
|
|
|
add_next_index_long(return_value, stat_sb->st_ctime);
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
1999-04-17 08:37:12 +08:00
|
|
|
add_next_index_long(return_value, stat_sb->st_blksize);
|
|
|
|
#else
|
|
|
|
add_next_index_long(return_value, -1);
|
|
|
|
#endif
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
#ifdef HAVE_ST_BLOCKS
|
1999-04-17 08:37:12 +08:00
|
|
|
add_next_index_long(return_value, stat_sb->st_blocks);
|
|
|
|
#else
|
|
|
|
add_next_index_long(return_value, -1);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "didn't understand stat call");
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* another quickie macro to make defining similar functions easier */
|
|
|
|
#define FileFunction(name, funcnum) \
|
|
|
|
void name(INTERNAL_FUNCTION_PARAMETERS) { \
|
|
|
|
pval *filename; \
|
|
|
|
if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&filename) == FAILURE) { \
|
|
|
|
WRONG_PARAM_COUNT; \
|
|
|
|
} \
|
|
|
|
convert_to_string(filename); \
|
|
|
|
_php3_stat(filename->value.str.val, funcnum, return_value); \
|
|
|
|
}
|
|
|
|
|
1999-07-27 04:09:08 +08:00
|
|
|
FileFunction(PHP_FN(fileperms),0)
|
|
|
|
FileFunction(PHP_FN(fileinode),1)
|
|
|
|
FileFunction(PHP_FN(filesize), 2)
|
|
|
|
FileFunction(PHP_FN(fileowner),3)
|
|
|
|
FileFunction(PHP_FN(filegroup),4)
|
|
|
|
FileFunction(PHP_FN(fileatime),5)
|
|
|
|
FileFunction(PHP_FN(filemtime),6)
|
|
|
|
FileFunction(PHP_FN(filectime),7)
|
|
|
|
FileFunction(PHP_FN(filetype), 8)
|
|
|
|
FileFunction(PHP_FN(is_writable), 9)
|
|
|
|
FileFunction(PHP_FN(is_readable),10)
|
|
|
|
FileFunction(PHP_FN(is_executable),11)
|
|
|
|
FileFunction(PHP_FN(is_file),12)
|
|
|
|
FileFunction(PHP_FN(is_dir),13)
|
|
|
|
FileFunction(PHP_FN(is_link),14)
|
|
|
|
FileFunction(PHP_FN(file_exists),15)
|
|
|
|
FileFunction(PHP_FN(lstat),16)
|
|
|
|
FileFunction(PHP_FN(stat),17)
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
function_entry php3_filestat_functions[] = {
|
1999-07-25 06:16:54 +08:00
|
|
|
PHP_FE(fileatime, NULL)
|
|
|
|
PHP_FE(filectime, NULL)
|
|
|
|
PHP_FE(filegroup, NULL)
|
|
|
|
PHP_FE(fileinode, NULL)
|
|
|
|
PHP_FE(filemtime, NULL)
|
|
|
|
PHP_FE(fileowner, NULL)
|
|
|
|
PHP_FE(fileperms, NULL)
|
|
|
|
PHP_FE(filesize, NULL)
|
|
|
|
PHP_FE(filetype, NULL)
|
|
|
|
PHP_FE(file_exists, NULL)
|
|
|
|
PHP_FE(is_writable, NULL)
|
1999-08-14 04:28:27 +08:00
|
|
|
PHP_FALIAS(is_writeable, is_writable, NULL)
|
1999-07-25 06:16:54 +08:00
|
|
|
PHP_FE(is_readable, NULL)
|
|
|
|
PHP_FE(is_executable, NULL)
|
|
|
|
PHP_FE(is_file, NULL)
|
|
|
|
PHP_FE(is_dir, NULL)
|
|
|
|
PHP_FE(is_link, NULL)
|
|
|
|
PHP_FE(stat, NULL)
|
|
|
|
PHP_FE(lstat, NULL)
|
|
|
|
PHP_FE(chown, NULL)
|
|
|
|
PHP_FE(chgrp, NULL)
|
|
|
|
PHP_FE(chmod, NULL)
|
|
|
|
PHP_FE(touch, NULL)
|
|
|
|
PHP_FE(clearstatcache, NULL)
|
1999-04-17 08:37:12 +08:00
|
|
|
{NULL, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
php3_module_entry php3_filestat_module_entry = {
|
1999-07-27 04:09:08 +08:00
|
|
|
"PHP_filestat", php3_filestat_functions, NULL, NULL, PHP_RINIT(filestat),
|
|
|
|
PHP_RSHUTDOWN(filestat), NULL, STANDARD_MODULE_PROPERTIES
|
1999-04-17 08:37:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|