summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThies C. Arntzen <thies@php.net>1999-08-17 12:32:23 +0000
committerThies C. Arntzen <thies@php.net>1999-08-17 12:32:23 +0000
commite30a2740cf170ae536bec2081c6e2119d08f2242 (patch)
tree6d9e9f6836473ceb0f1914b5d8682caddaf81a4a
parenta5a5902fbce2e6c58501ced5b99309ead5f82b6d (diff)
downloadphp-git-e30a2740cf170ae536bec2081c6e2119d08f2242.tar.gz
imported diskfreespace from 3.0
-rw-r--r--ChangeLog1
-rw-r--r--configure.in.in4
-rw-r--r--ext/standard/filestat.c110
3 files changed, 113 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 915995ae72..c63391a44e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@ PHP 4.0 CHANGE LOG ChangeLog
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ?? 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)
diff --git a/configure.in.in b/configure.in.in
index fed45111d0..cd5f36c744 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -251,7 +251,7 @@ else
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 @@ AC_CHECK_TYPE( ulong, unsigned long )
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=""
diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c
index bafee0852e..61685741a2 100644
--- a/ext/standard/filestat.c
+++ b/ext/standard/filestat.c
@@ -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 @@ PHP_RSHUTDOWN_FUNCTION(filestat)
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 @@ function_entry php3_filestat_functions[] = {
PHP_FE(chmod, NULL)
PHP_FE(touch, NULL)
PHP_FE(clearstatcache, NULL)
+ PHP_FE(diskfreespace, NULL)
{NULL, NULL, NULL}
};