From: Andi Gutmans Date: Wed, 25 Apr 2001 04:22:29 +0000 (+0000) Subject: - Fix problem with is_link(), there seem to be at least another couple of X-Git-Tag: php-4.0.6RC1~324 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=76860d4fc0bbfb3510c5b37fb70a506136b1dade;p=php - Fix problem with is_link(), there seem to be at least another couple of - bugs lurking around though. - Cleaned up code a bit and optimized it a bit too. --- diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 95ef0bcf17..b3443a7a8c 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -447,7 +447,7 @@ PHP_FUNCTION(clearstatcache) /* }}} */ -static void php_stat(const char *filename, int type, pval *return_value) +static void php_stat(const char *filename, int filename_length, int type, pval *return_value) { struct stat *stat_sb; int rmask=S_IROTH,wmask=S_IWOTH,xmask=S_IXOTH; /* access rights defaults to other */ @@ -455,25 +455,28 @@ static void php_stat(const char *filename, int type, pval *return_value) stat_sb = &BG(sb); - if (!BG(CurrentStatFile) || strcmp(filename,BG(CurrentStatFile))) { - if (!BG(CurrentStatFile) - || strlen(filename) > BG(CurrentStatLength)) { - if (BG(CurrentStatFile)) efree(BG(CurrentStatFile)); - BG(CurrentStatLength) = strlen(filename); - BG(CurrentStatFile) = estrndup(filename,BG(CurrentStatLength)); + if (!BG(CurrentStatFile) || strcmp(filename, BG(CurrentStatFile))) { + if (!BG(CurrentStatFile) || filename_length > BG(CurrentStatLength)) { + if (BG(CurrentStatFile)) { + efree(BG(CurrentStatFile)); + } + BG(CurrentStatLength) = filename_length; + BG(CurrentStatFile) = estrndup(filename, filename_length); } else { - strcpy(BG(CurrentStatFile),filename); + memcpy(BG(CurrentStatFile), filename, filename_length+1); } #if HAVE_SYMLINK BG(lsb).st_mode = 0; /* mark lstat buf invalid */ #endif - if (V_STAT(BG(CurrentStatFile),&BG(sb))==-1) { - if (type != 15 || errno != ENOENT) { /* fileexists() test must print no error */ - php_error(E_NOTICE,"stat failed for %s (errno=%d - %s)",BG(CurrentStatFile),errno,strerror(errno)); + if (V_STAT(BG(CurrentStatFile), &BG(sb)) == -1) { + if ((type != 14) && (type != 15 || errno != ENOENT)) { /* fileexists() test must print no error */ + php_error(E_NOTICE,"stat failed for %s (errno=%d - %s)", BG(CurrentStatFile), errno, strerror(errno)); } efree(BG(CurrentStatFile)); - BG(CurrentStatFile)=NULL; - RETURN_FALSE; + BG(CurrentStatFile) = NULL; + if (type != 14) { /* Don't require success for is link */ + RETURN_FALSE; + } } } @@ -485,8 +488,8 @@ static void php_stat(const char *filename, int type, pval *return_value) /* do lstat if the buffer is empty */ if (!BG(lsb).st_mode) { - if (V_LSTAT(BG(CurrentStatFile),&BG(lsb)) == -1) { - php_error(E_NOTICE,"lstat failed for %s (errno=%d - %s)",BG(CurrentStatFile),errno,strerror(errno)); + if (V_LSTAT(BG(CurrentStatFile), &BG(lsb)) == -1) { + php_error(E_NOTICE, "lstat failed for %s (errno=%d - %s)", BG(CurrentStatFile), errno, strerror(errno)); RETURN_FALSE; } } @@ -494,35 +497,37 @@ static void php_stat(const char *filename, int type, pval *return_value) #endif - if(BG(sb).st_uid==getuid()) { - rmask=S_IRUSR; - wmask=S_IWUSR; - xmask=S_IXUSR; - } else if(BG(sb).st_gid==getgid()) { - rmask=S_IRGRP; - wmask=S_IWGRP; - xmask=S_IXGRP; - } else { - int groups,n,i; - gid_t *gids; - - groups = getgroups(0,NULL); - if(groups) { - gids=(gid_t *)emalloc(groups*sizeof(gid_t)); - n=getgroups(groups,gids); - for(i=0;i= 9 && type <= 11) { + if(BG(sb).st_uid==getuid()) { + rmask=S_IRUSR; + wmask=S_IWUSR; + xmask=S_IXUSR; + } else if(BG(sb).st_gid==getgid()) { + rmask=S_IRGRP; + wmask=S_IWGRP; + xmask=S_IXGRP; + } else { + int groups,n,i; + gid_t *gids; + + groups = getgroups(0,NULL); + if(groups) { + gids=(gid_t *)emalloc(groups*sizeof(gid_t)); + n=getgroups(groups,gids); + for(i=0;ivalue.str.len) \ - php_stat((*filename)->value.str.val, funcnum, return_value); \ + php_stat(Z_STRVAL_PP(filename), Z_STRLEN_PP(filename), funcnum, return_value); \ } /* {{{ proto int fileperms(string filename) @@ -712,7 +722,7 @@ FileFunction(PHP_FN(file_exists),15) /* {{{ proto array lstat(string filename) Give information about a file or symbolic link */ -FileFunction(php_if_lstat,16) +FileFunction(php_if_lstat, 16) /* }}} */ /* {{{ proto array stat(string filename)