Skip to content
Snippets Groups Projects
Commit dfef8a98 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Remove pre-WinXP support from getdiskspace()

No need to use LoadLibrary and GetProcessAddress here any more either
parent bc44e1cb
Branches
Tags
No related merge requests found
......@@ -921,24 +921,11 @@ typedef BOOL (WINAPI * GetDiskFreeSpaceEx_t)
static uint64_t getdiskspace(const char* path, uint64_t unit, bool freespace)
{
#if defined(_WIN32)
char root[16];
DWORD TotalNumberOfClusters;
DWORD NumberOfFreeClusters;
DWORD BytesPerSector;
DWORD SectorsPerCluster;
uint64_t total;
ULARGE_INTEGER avail;
ULARGE_INTEGER size;
static HINSTANCE hK32 = NULL;
GetDiskFreeSpaceEx_t GDFSE = NULL;
if (hK32 == NULL)
hK32 = LoadLibraryA("KERNEL32");
if (hK32 != NULL)
GDFSE = (GetDiskFreeSpaceEx_t)GetProcAddress(hK32, "GetDiskFreeSpaceExA");
if (GDFSE != NULL) { /* Windows 95-OSR2 or later */
if (!GDFSE(
if (!GetDiskFreeSpaceExA(
path, /* pointer to the directory name */
&avail, /* receives the number of bytes on disk avail to the caller */
&size, /* receives the number of bytes on disk */
......@@ -949,25 +936,6 @@ static uint64_t getdiskspace(const char* path, uint64_t unit, bool freespace)
if (unit > 1)
total /= unit;
return total;
}
/* Windows 95 (old way), limited to 2GB */
sprintf(root, "%.3s", path);
if (!GetDiskFreeSpaceA(
root, /* pointer to root path */
(PDWORD)&SectorsPerCluster, /* pointer to sectors per cluster */
(PDWORD)&BytesPerSector, /* pointer to bytes per sector */
(PDWORD)&NumberOfFreeClusters, /* pointer to number of free clusters */
(PDWORD)&TotalNumberOfClusters /* pointer to total number of clusters */
))
return 0;
if (freespace)
TotalNumberOfClusters = NumberOfFreeClusters;
if (unit > 1)
TotalNumberOfClusters /= (DWORD)unit;
return TotalNumberOfClusters * SectorsPerCluster * BytesPerSector;
#elif defined(__solaris__) || (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 300000000 /* NetBSD 3.0 */))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment