Browse Source

imported diskfreespace from 3.0

experimetnal/RETURN_REF_PATCH
Thies C. Arntzen 27 years ago
parent
commit
e30a2740cf
  1. 1
      ChangeLog
  2. 4
      configure.in.in
  3. 110
      ext/standard/filestat.c

1
ChangeLog

@ -2,6 +2,7 @@ PHP 4.0 CHANGE LOG ChangeLog
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ?? 1999, Version 4.0 Beta 3 ?? ?? 1999, Version 4.0 Beta 3
- Imported PHP 3.0 diskfreespace() function (Thies)
- Fixed thread-safety issues in the MySQL module (Zeev) - Fixed thread-safety issues in the MySQL module (Zeev)
- Fixed thread-safe support for dynamic modules (Zeev) - Fixed thread-safe support for dynamic modules (Zeev)
- Fixed Sybase CT build process (Zeev) - Fixed Sybase CT build process (Zeev)

4
configure.in.in

@ -251,7 +251,7 @@ else
fi fi
AC_MISSING_FCLOSE_DECL AC_MISSING_FCLOSE_DECL
dnl QNX requires unix.h to allow functions in libunix to work properly 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. dnl Checks for typedefs, structures, and compiler characteristics.
AC_STRUCT_TM AC_STRUCT_TM
@ -309,7 +309,7 @@ AC_CHECK_TYPE( ulong, unsigned long )
dnl Checks for library functions. dnl Checks for library functions.
AC_FUNC_VPRINTF 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_UTIME_NULL
AC_FUNC_ALLOCA AC_FUNC_ALLOCA
dnl## OLDLIBS=$LIBS; LIBS="" dnl## OLDLIBS=$LIBS; LIBS=""

110
ext/standard/filestat.c

@ -34,6 +34,17 @@
# include <unistd.h> # include <unistd.h>
#endif #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 HAVE_PWD_H
# if MSVC5 # if MSVC5
# include "win32/pwd.h" # include "win32/pwd.h"
@ -100,6 +111,104 @@ PHP_RSHUTDOWN_FUNCTION(filestat)
return SUCCESS; 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) PHP_FUNCTION(chgrp)
{ {
#ifndef WINDOWS #ifndef WINDOWS
@ -479,6 +588,7 @@ function_entry php3_filestat_functions[] = {
PHP_FE(chmod, NULL) PHP_FE(chmod, NULL)
PHP_FE(touch, NULL) PHP_FE(touch, NULL)
PHP_FE(clearstatcache, NULL) PHP_FE(clearstatcache, NULL)
PHP_FE(diskfreespace, NULL)
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };

Loading…
Cancel
Save