Re: CVS update: php3/functions
| From: | Thies C. Arntzen | Date: | Sat, 26 Jun 1999 19:37:59 +0000 |
| Subject: | Re: CVS update: php3/functions | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-7602@lists.php.net to get a copy of this message | ||
oh my god,
you're mr. windows (hope that's not an insault to u;-)
tc
On 26 Jun 1999, jim wrote:
> Date: Saturday June 26, 1999 @ 14:15
> Author: jim
>
> Update of /repository/php3/functions
> In directory php:/tmp/cvs-serv16413/functions
>
> Modified Files:
> filestat.c
> Log Message:
> Fix diskspacefree() function on Windows 95 pre-OSR2. Yeah, it's not pretty.
>
> Index: php3/functions/filestat.c
> diff -u php3/functions/filestat.c:1.88 php3/functions/filestat.c:1.89
> --- php3/functions/filestat.c:1.88 Wed Jun 16 07:34:19 1999
> +++ php3/functions/filestat.c Sat Jun 26 14:15:42 1999
> @@ -27,7 +27,7 @@
> +----------------------------------------------------------------------+
> */
>
> -/* $Id: filestat.c,v 1.88 1999/06/16 11:34:19 ssb Exp $ */
> +/* $Id: filestat.c,v 1.89 1999/06/26 18:15:42 jim Exp $ */
> #ifdef THREAD_SAFE
> #include "tls.h"
> #endif
> @@ -128,10 +128,23 @@
> #ifdef WINDOWS
> pval *path;
> double bytesfree;
> -
> - ULARGE_INTEGER FreeBytesAvailableToCaller;
> +
> + HINSTANCE kernel32;
> + FARPROC gdfse;
> + typedef BOOL (*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)
> @@ -152,15 +165,39 @@
> if (_php3_check_open_basedir(path->value.str.val)) RETURN_FALSE;
>
> #ifdef WINDOWS
> - if (GetDiskFreeSpaceEx(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;
> + /* 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;
> + }
> +
> +
> #else /* WINDOWS */
> #if defined(HAVE_SYS_STATVFS_H) && defined(HAVE_STATVFS)
> if (statvfs(path->value.str.val,&buf)) RETURN_FALSE;
>
> --
> PHP Development Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
> For additional commands, e-mail: php-dev-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>
Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!"
Digital Collections Phone +49 40 235350 Fax +49 40 23535180
Hammerbrookstr. 93 20097 Hamburg / Germany