CVS update: php3/functions
| From: | jaakko | Date: | Sun, 06 Sep 1998 06:50:23 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-824@lists.php.net to get a copy of this message | ||
Date: Sunday September 6, 1998 @ 2:50
Author: jaakko
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv14788/functions
Modified Files:
filestat.c php3_filestat.h
Log Message:
Added function lstat() and cleaned up the status functions. There was
something inside #if APACHE conditions - I do not understand why, it
was not affecting anything.
Added tests for file status functions. This may break on some plattforms
that do not have symbolic links, so this has to be trimmed down or modified
otherwise..
Index: php3/functions/filestat.c
diff -c php3/functions/filestat.c:1.75 php3/functions/filestat.c:1.76
*** php3/functions/filestat.c:1.75 Fri Aug 14 19:47:15 1998
--- php3/functions/filestat.c Sun Sep 6 02:50:22 1998
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: filestat.c,v 1.75 1998/08/14 23:47:15 steffann Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: filestat.c,v 1.76 1998/09/06 06:50:22 jaakko Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 80,86 ****
# else
static int CurrentStatLength=0;
# endif
! static struct stat sb;
#endif
#ifndef S_ISDIR
--- 80,86 ----
# else
static int CurrentStatLength=0;
# endif
! static struct stat sb, lsb;
#endif
#ifndef S_ISDIR
***************
*** 310,416 ****
}
}
- void php3_stat(INTERNAL_FUNCTION_PARAMETERS) {
- pval *filename;
- TLS_VARS;
-
- if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&filename) == FAILURE) {
- WRONG_PARAM_COUNT;
- }
- convert_to_string(filename);
-
- #if APACHE
- if (!GLOBAL(CurrentStatFile)) {
- GLOBAL(CurrentStatLength) = strlen(GLOBAL(php3_rqst)->filename);
- GLOBAL(CurrentStatFile) = estrndup(GLOBAL(php3_rqst)->filename,GLOBAL(CurrentStatLength));
- if (stat(GLOBAL(CurrentStatFile),&GLOBAL(sb))==-1) {
- GLOBAL(CurrentStatFile)=NULL;
- return;
- }
- }
- #endif
-
- if (!GLOBAL(CurrentStatFile) || strcmp(filename->value.str.val,GLOBAL(CurrentStatFile))) {
- if (strlen(filename->value.str.val) >GLOBAL(CurrentStatLength)) {
- if (GLOBAL(CurrentStatFile)) efree(GLOBAL(CurrentStatFile));
- GLOBAL(CurrentStatFile) = estrndup(filename->value.str.val,filename->value.str.len);
- GLOBAL(CurrentStatLength) = strlen(filename->value.str.val);
- } else {
- strcpy(GLOBAL(CurrentStatFile),filename->value.str.val);
- }
- if (stat(GLOBAL(CurrentStatFile),&GLOBAL(sb))==-1) {
- efree(GLOBAL(CurrentStatFile));
- GLOBAL(CurrentStatFile)=NULL;
- GLOBAL(CurrentStatLength)=0;
- RETURN_FALSE;
- }
- }
-
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
- add_next_index_long(return_value, GLOBAL(sb).st_dev);
- add_next_index_long(return_value, GLOBAL(sb).st_ino);
- add_next_index_long(return_value, GLOBAL(sb).st_mode);
- add_next_index_long(return_value, GLOBAL(sb).st_nlink);
- add_next_index_long(return_value, GLOBAL(sb).st_uid);
- add_next_index_long(return_value, GLOBAL(sb).st_gid);
- #ifdef HAVE_ST_BLKSIZE
- add_next_index_long(return_value, GLOBAL(sb).st_rdev);
- #else
- add_next_index_long(return_value, -1);
- #endif
- add_next_index_long(return_value, GLOBAL(sb).st_size);
- add_next_index_long(return_value, GLOBAL(sb).st_atime);
- add_next_index_long(return_value, GLOBAL(sb).st_mtime);
- add_next_index_long(return_value, GLOBAL(sb).st_ctime);
- #if HAVE_ST_BLKSIZE
- add_next_index_long(return_value, GLOBAL(sb).st_blksize);
- #else
- add_next_index_long(return_value, -1);
- #endif
- #if HAVE_ST_BLOCKS
- add_next_index_long(return_value, GLOBAL(sb).st_blocks);
- #else
- add_next_index_long(return_value, -1);
- #endif
- return;
- }
-
static void _php3_stat(const char *filename, int type, pval *return_value)
{
TLS_VARS;
- #if APACHE
- if (!GLOBAL(CurrentStatFile)) {
- GLOBAL(CurrentStatLength) = strlen(GLOBAL(php3_rqst)->filename);
- GLOBAL(CurrentStatFile) = estrndup(GLOBAL(php3_rqst)->filename,GLOBAL(CurrentStatLength));
- if (stat(GLOBAL(CurrentStatFile),&GLOBAL(sb))==-1) {
- efree(GLOBAL(CurrentStatFile));
- GLOBAL(CurrentStatFile)=NULL;
- RETURN_FALSE;
- }
- }
- #endif
if (!GLOBAL(CurrentStatFile) || strcmp(filename,GLOBAL(CurrentStatFile))) {
! if (strlen(filename) > GLOBAL(CurrentStatLength)) {
if (GLOBAL(CurrentStatFile)) efree(GLOBAL(CurrentStatFile));
GLOBAL(CurrentStatLength) = strlen(filename);
GLOBAL(CurrentStatFile) = estrndup(filename,GLOBAL(CurrentStatLength));
- } else if (!GLOBAL(CurrentStatFile)){
- GLOBAL(CurrentStatLength) = strlen(filename);
- GLOBAL(CurrentStatFile) = estrndup(filename,GLOBAL(CurrentStatLength));
} else {
strcpy(GLOBAL(CurrentStatFile),filename);
}
if (stat(GLOBAL(CurrentStatFile),&GLOBAL(sb))==-1) {
! if (type == 15 && errno == ENOENT) {
! memset(&GLOBAL(sb),0,sizeof(GLOBAL(sb)));
! } else {
php3_error(E_NOTICE,"stat failed for %s (errno=%d -
%s)",GLOBAL(CurrentStatFile),errno,strerror(errno));
! efree(GLOBAL(CurrentStatFile));
! GLOBAL(CurrentStatFile)=NULL;
! GLOBAL(CurrentStatLength)=0;
RETURN_FALSE;
}
}
--- 310,349 ----
}
}
static void _php3_stat(const char *filename, int type, pval *return_value)
{
+ struct stat *stat_sb = &GLOBAL(sb);
TLS_VARS;
if (!GLOBAL(CurrentStatFile) || strcmp(filename,GLOBAL(CurrentStatFile))) {
! if (!GLOBAL(CurrentStatFile)
! || strlen(filename) > GLOBAL(CurrentStatLength)) {
if (GLOBAL(CurrentStatFile)) efree(GLOBAL(CurrentStatFile));
GLOBAL(CurrentStatLength) = strlen(filename);
GLOBAL(CurrentStatFile) = estrndup(filename,GLOBAL(CurrentStatLength));
} else {
strcpy(GLOBAL(CurrentStatFile),filename);
}
+ GLOBAL(lsb).st_mode = 0; /* mark lstat buf invalid */
if (stat(GLOBAL(CurrentStatFile),&GLOBAL(sb))==-1) {
! if (type != 15 || errno != ENOENT) { /* fileexists() test must print no error */
php3_error(E_NOTICE,"stat failed for %s (errno=%d -
%s)",GLOBAL(CurrentStatFile),errno,strerror(errno));
! }
! efree(GLOBAL(CurrentStatFile));
! GLOBAL(CurrentStatFile)=NULL;
! RETURN_FALSE;
! }
! }
!
! if (8 == type /* filetype */
! || 14 == type /* is link */
! || 16 == type) { /* lstat */
!
! /* do lstat if the buffer is empty */
!
! if (!GLOBAL(lsb).st_mode) {
! if (lstat(GLOBAL(CurrentStatFile),&GLOBAL(lsb)) == -1) {
! php3_error(E_NOTICE,"lstat failed for %s (errno=%d -
%s)",GLOBAL(CurrentStatFile),errno,strerror(errno));
RETURN_FALSE;
}
}
***************
*** 419,502 ****
switch(type) {
case 0: /* fileperms */
RETURN_LONG((long)GLOBAL(sb).st_mode);
- break;
case 1: /* fileinode */
RETURN_LONG((long)GLOBAL(sb).st_ino);
- break;
case 2: /* filesize */
RETURN_LONG((long)GLOBAL(sb).st_size);
- break;
case 3: /* fileowner */
RETURN_LONG((long)GLOBAL(sb).st_uid);
- break;
case 4: /* filegroup */
RETURN_LONG((long)GLOBAL(sb).st_gid);
- break;
case 5: /* fileatime */
RETURN_LONG((long)GLOBAL(sb).st_atime);
- break;
case 6: /* filemtime */
RETURN_LONG((long)GLOBAL(sb).st_mtime);
- break;
case 7: /* filectime */
RETURN_LONG((long)GLOBAL(sb).st_ctime);
- break;
case 8: /* filetype */
! {
! struct stat lsb;
! lstat(GLOBAL(CurrentStatFile),&lsb);
! if ((lsb.st_mode&S_IFMT) == S_IFLNK) {
! RETURN_STRING("link",1);
! }
switch(GLOBAL(sb).st_mode&S_IFMT) {
! case S_IFIFO:
! RETURN_STRING("fifo",1);
! break;
! case S_IFCHR:
! RETURN_STRING("char",1);
! break;
! case S_IFDIR:
! RETURN_STRING("dir",1);
! break;
! case S_IFBLK:
! RETURN_STRING("block",1);
! break;
! case S_IFREG:
! RETURN_STRING("file",1);
! break;
! default:
! php3_error(E_WARNING,"Unknown file type (%d)",GLOBAL(sb).st_mode&S_IFMT);
! RETURN_STRING("unknown",1);
! break;
! }
}
! break;
case 9: /*is writable*/
RETURN_LONG((GLOBAL(sb).st_mode&S_IWRITE)!=0);
- break;
case 10: /*is readable*/
RETURN_LONG((GLOBAL(sb).st_mode&S_IREAD)!=0);
- break;
case 11: /*is executable*/
RETURN_LONG((GLOBAL(sb).st_mode&S_IEXEC)!=0 && !S_ISDIR(GLOBAL(sb).st_mode));
- break;
case 12: /*is file*/
RETURN_LONG(S_ISREG(GLOBAL(sb).st_mode));
- break;
case 13: /*is dir*/
RETURN_LONG(S_ISDIR(GLOBAL(sb).st_mode));
- break;
case 14: /*is link*/
! RETURN_LONG(S_ISLNK(GLOBAL(sb).st_mode));
! break;
case 15: /*file exists*/
! RETURN_LONG(GLOBAL(sb).st_mode >0);
! break;
! default:
! php3_error(E_WARNING, "didn't understand stat call");
! RETURN_FALSE;
! break;
}
}
/* another quickie macro to make defining similar functions easier */
--- 352,434 ----
switch(type) {
case 0: /* fileperms */
RETURN_LONG((long)GLOBAL(sb).st_mode);
case 1: /* fileinode */
RETURN_LONG((long)GLOBAL(sb).st_ino);
case 2: /* filesize */
RETURN_LONG((long)GLOBAL(sb).st_size);
case 3: /* fileowner */
RETURN_LONG((long)GLOBAL(sb).st_uid);
case 4: /* filegroup */
RETURN_LONG((long)GLOBAL(sb).st_gid);
case 5: /* fileatime */
RETURN_LONG((long)GLOBAL(sb).st_atime);
case 6: /* filemtime */
RETURN_LONG((long)GLOBAL(sb).st_mtime);
case 7: /* filectime */
RETURN_LONG((long)GLOBAL(sb).st_ctime);
case 8: /* filetype */
! if (S_ISLNK(GLOBAL(lsb).st_mode)) {
! RETURN_STRING("link",1);
! }
switch(GLOBAL(sb).st_mode&S_IFMT) {
! 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);
}
! php3_error(E_WARNING,"Unknown file type (%d)",GLOBAL(sb).st_mode&S_IFMT);
! RETURN_STRING("unknown",1);
case 9: /*is writable*/
RETURN_LONG((GLOBAL(sb).st_mode&S_IWRITE)!=0);
case 10: /*is readable*/
RETURN_LONG((GLOBAL(sb).st_mode&S_IREAD)!=0);
case 11: /*is executable*/
RETURN_LONG((GLOBAL(sb).st_mode&S_IEXEC)!=0 && !S_ISDIR(GLOBAL(sb).st_mode));
case 12: /*is file*/
RETURN_LONG(S_ISREG(GLOBAL(sb).st_mode));
case 13: /*is dir*/
RETURN_LONG(S_ISDIR(GLOBAL(sb).st_mode));
case 14: /*is link*/
! RETURN_LONG(S_ISLNK(GLOBAL(lsb).st_mode));
case 15: /*file exists*/
! RETURN_TRUE; /* the false case was done earlier */
! case 16: /* lstat */
! stat_sb = &GLOBAL(lsb);
! /* 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);
! #if HAVE_ST_BLKSIZE
! add_next_index_long(return_value, stat_sb->st_blksize);
! #else
! add_next_index_long(return_value, -1);
! #endif
! #if HAVE_ST_BLOCKS
! add_next_index_long(return_value, stat_sb->st_blocks);
! #else
! add_next_index_long(return_value, -1);
! #endif
! return;
}
+ php3_error(E_WARNING, "didn't understand stat call");
+ RETURN_FALSE;
}
/* another quickie macro to make defining similar functions easier */
***************
*** 526,531 ****
--- 458,465 ----
FileFunction(php3_isdir,13)
FileFunction(php3_islink,14)
FileFunction(php3_fileexists,15)
+ FileFunction(php3_lstat,16)
+ FileFunction(php3_stat,17)
function_entry php3_filestat_functions[] = {
{"fileatime", php3_fileatime, NULL},
***************
*** 545,550 ****
--- 479,485 ----
{"is_dir", php3_isdir, NULL},
{"is_link", php3_islink, NULL},
{"stat", php3_stat, NULL},
+ {"lstat", php3_lstat, NULL},
{"chown", php3_chown, NULL},
{"chgrp", php3_chgrp, NULL},
{"chmod", php3_chmod, NULL},
Index: php3/functions/php3_filestat.h
diff -c php3/functions/php3_filestat.h:1.10 php3/functions/php3_filestat.h:1.11
*** php3/functions/php3_filestat.h:1.10 Fri May 15 06:57:33 1998
--- php3/functions/php3_filestat.h Sun Sep 6 02:50:22 1998
***************
*** 27,33 ****
+----------------------------------------------------------------------+
*/
! /* $Id: php3_filestat.h,v 1.10 1998/05/15 10:57:33 zeev Exp $ */
#ifndef _FILESTAT_H
#define _FILESTAT_H
--- 27,33 ----
+----------------------------------------------------------------------+
*/
! /* $Id: php3_filestat.h,v 1.11 1998/09/06 06:50:22 jaakko Exp $ */
#ifndef _FILESTAT_H
#define _FILESTAT_H
***************
*** 52,57 ****
--- 52,58 ----
extern void php3_islink(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_fileexists(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_stat(INTERNAL_FUNCTION_PARAMETERS);
+ extern void php3_lstat(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chown(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chgrp(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_chmod(INTERNAL_FUNCTION_PARAMETERS);
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net