cvs: /php4 ChangeLog configure.in.in /php4/ext/standard filestat.c

From: Date: Tue, 17 Aug 1999 12:32:24 +0000
Subject: cvs: /php4 ChangeLog configure.in.in /php4/ext/standard filestat.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-3477@lists.php.net to get a copy of this message
thies Tue Aug 17 08:32:24 1999 EDT Modified files: /php4 ChangeLog configure.in.in /php4/ext/standard filestat.c Log: imported diskfreespace from 3.0 Index: php4/ChangeLog diff -u php4/ChangeLog:1.52 php4/ChangeLog:1.53 --- php4/ChangeLog:1.52 Mon Aug 16 10:19:48 1999 +++ php4/ChangeLog Tue Aug 17 08:32:22 1999 @@ -2,6 +2,7 @@ ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ?? 1999, Version 4.0 Beta 3 +- Imported PHP 3.0 diskfreespace() function (Thies) - Fixed thread-safety issues in the MySQL module (Zeev) - Fixed thread-safe support for dynamic modules (Zeev) - Fixed Sybase CT build process (Zeev) Index: php4/configure.in.in diff -u php4/configure.in.in:1.65 php4/configure.in.in:1.66 --- php4/configure.in.in:1.65 Mon Aug 9 14:29:40 1999 +++ php4/configure.in.in Tue Aug 17 08:32:23 1999 @@ -1,4 +1,4 @@ -dnl $Id: configure.in.in,v 1.65 1999/08/09 18:29:40 andi Exp $ -*- sh -*- +dnl $Id: configure.in.in,v 1.66 1999/08/17 12:32:23 thies Exp $ -*- sh -*- dnl Process this file with autoconf to produce a configure script. divert(0) @@ -251,7 +251,7 @@ fi AC_MISSING_FCLOSE_DECL dnl QNX requires unix.h to allow functions in libunix to work properly -AC_CHECK_HEADERS(fcntl.h unistd.h crypt.h sys/file.h memory.h pwd.h grp.h sys/socket.h sys/wait.h syslog.h string.h sys/varargs.h stdarg.h sys/time.h signal.h netinet/in.h dlfcn.h limits.h sys/types.h unix.h arpa/inet.h locale.h sys/select.h) +AC_CHECK_HEADERS(fcntl.h unistd.h crypt.h sys/file.h memory.h pwd.h grp.h sys/socket.h sys/wait.h syslog.h string.h sys/varargs.h stdarg.h sys/time.h signal.h netinet/in.h dlfcn.h limits.h sys/types.h unix.h arpa/inet.h locale.h sys/select.h sys/statvfs.h sys/statfs.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_STRUCT_TM @@ -309,7 +309,7 @@ dnl Checks for library functions. AC_FUNC_VPRINTF -AC_CHECK_FUNCS(memcpy memmove strdup strerror strcasecmp strstr flock lockf putenv tempnam usleep setlocale gettimeofday setvbuf srand48 lrand48 srandom random link symlink regcomp getlogin cuserid vsnprintf snprintf gcvt utime crypt rint unsetenv strftime setsockopt tzset shutdown inet_aton) +AC_CHECK_FUNCS(memcpy memmove strdup strerror strcasecmp strstr flock lockf putenv tempnam usleep setlocale gettimeofday setvbuf srand48 lrand48 srandom random link symlink regcomp getlogin cuserid vsnprintf snprintf gcvt utime crypt rint unsetenv strftime setsockopt tzset shutdown inet_aton statvfs statfs) AC_FUNC_UTIME_NULL AC_FUNC_ALLOCA dnl## OLDLIBS=$LIBS; LIBS="" Index: php4/ext/standard/filestat.c diff -u php4/ext/standard/filestat.c:1.12 php4/ext/standard/filestat.c:1.13 --- php4/ext/standard/filestat.c:1.12 Sun Aug 15 14:52:10 1999 +++ php4/ext/standard/filestat.c Tue Aug 17 08:32:23 1999 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: filestat.c,v 1.12 1999/08/15 18:52:10 thies Exp $ */ +/* $Id: filestat.c,v 1.13 1999/08/17 12:32:23 thies Exp $ */ #include "php.h" #include "safe_mode.h" @@ -34,6 +34,17 @@ # include <unistd.h> #endif +#ifdef OS2 +# define INCL_DOS +# include <os2.h> +#endif + +#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) +# include <sys/statvfs.h> +#elif defined(HAVE_SYS_STATFS_H) && defined(HAVE_STATFS) +# include <sys/statfs.h> +#endif + #if HAVE_PWD_H # if MSVC5 # include "win32/pwd.h" @@ -100,6 +111,104 @@ return SUCCESS; } +PHP_FUNCTION(diskfreespace) +{ +#ifdef WINDOWS + pval *path; + double bytesfree; + + HINSTANCE kernel32; + FARPROC gdfse; + typedef BOOL (WINAPI *gdfse_func)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER); + gdfse_func func; + + /* These are used by GetDiskFreeSpaceEx, if available. */ + ULARGE_INTEGER FreeBytesAvailableToCaller; + ULARGE_INTEGER TotalNumberOfBytes; + ULARGE_INTEGER TotalNumberOfFreeBytes; + + /* These are used by GetDiskFreeSpace otherwise. */ + DWORD SectorsPerCluster; + DWORD BytesPerSector; + DWORD NumberOfFreeClusters; + DWORD TotalNumberOfClusters; + +#else /* not - WINDOWS */ + pval *path; +#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) + struct statvfs buf; +#elif defined(HAVE_SYS_STATFS_H) && defined(HAVE_STATFS) + struct statfs buf; +#endif + double bytesfree = 0; +#endif /* WINDOWS */ + + if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&path)==FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_string(path); + + if (_php3_check_open_basedir(path->value.str.val)) RETURN_FALSE; + +#ifdef WINDOWS + /* GetDiskFreeSpaceEx is only available in NT and Win95 post-OSR2, + so we have to jump through some hoops to see if the function + exists. */ + kernel32 = LoadLibrary("kernel32.dll"); + if (kernel32) { + gdfse = GetProcAddress(kernel32, "GetDiskFreeSpaceExA"); + /* It's available, so we can call it. */ + if (gdfse) { + func = (gdfse_func)gdfse; + if (func(path->value.str.val, + &FreeBytesAvailableToCaller, + &TotalNumberOfBytes, + &TotalNumberOfFreeBytes) == 0) RETURN_FALSE; + + /* i know - this is ugly, but i works (thies@digicol.de) */ + bytesfree = FreeBytesAvailableToCaller.HighPart * + (double) (((unsigned long)1) << 31) * 2.0 + + FreeBytesAvailableToCaller.LowPart; + } + /* If it's not available, we just use GetDiskFreeSpace */ + else { + if (GetDiskFreeSpace(path->value.str.val, + &SectorsPerCluster, &BytesPerSector, + &NumberOfFreeClusters, &TotalNumberOfClusters) == 0) RETURN_FALSE; + bytesfree = (double)NumberOfFreeClusters * (double)SectorsPerCluster * (double)BytesPerSector; + } + } + else { + php3_error(E_WARNING, "Unable to load kernel32.dll"); + RETURN_FALSE; + } + +#elif defined(OS2) + { + FSALLOCATE fsinfo; + char drive = path->value.str.val[0] & 95; + + if (DosQueryFSInfo( drive ? drive - 64 : 0, FSIL_ALLOC, &fsinfo, sizeof( fsinfo ) ) == 0) + bytesfree = (double)fsinfo.cbSector * fsinfo.cSectorUnit * fsinfo.cUnitAvail; + } +#else /* WINDOWS, OS/2 */ +#if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS) + if (statvfs(path->value.str.val,&buf)) RETURN_FALSE; + if (buf.f_frsize) { + bytesfree = (((double)buf.f_bavail) * ((double)buf.f_frsize)); + } else { + bytesfree = (((double)buf.f_bavail) * ((double)buf.f_bsize)); + } +#elif defined(HAVE_SYS_STATFS_H) && defined(HAVE_STATFS) + if (statfs(path->value.str.val,&buf)) RETURN_FALSE; + bytesfree = (((double)buf.f_bsize) * ((double)buf.f_bavail)); +#endif +#endif /* WINDOWS */ + + RETURN_DOUBLE(bytesfree); +} + PHP_FUNCTION(chgrp) { #ifndef WINDOWS @@ -479,6 +588,7 @@ PHP_FE(chmod, NULL) PHP_FE(touch, NULL) PHP_FE(clearstatcache, NULL) + PHP_FE(diskfreespace, NULL) {NULL, NULL, NULL} };

« previous php.version4 (#3477) next »