Fix compilation on Visual C++ 1.0.

This commit is contained in:
2020-05-03 04:49:50 +01:00
parent b3a4f619de
commit e1d22ce8b6
2 changed files with 183 additions and 103 deletions

View File

@@ -46,17 +46,53 @@ Copyright (C) 2011-2020 Natalia Portillo
#include "consts.h" #include "consts.h"
#include "defs.h" #include "defs.h"
static DWORD dwMaxNameSize = MAX_PATH + 1; static DWORD dwMaxNameSize = MAX_PATH + 1;
static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE;
static DWORD oldVersion;
static HINSTANCE kernel32;
;
void GetOsInfo() void GetOsInfo()
{ {
OSVERSIONINFO verInfo; WIN_OSVERSIONINFO verInfo;
BOOL ret; BOOL ret;
DWORD error; DWORD error;
void * func;
kernel32 = LoadLibraryA("KERNEL32.DLL");
verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if(!kernel32)
ret = GetVersionExA(&verInfo); {
oldVersion = GetVersion();
if(oldVersion == 0)
printf("\tRunning under Windows %lu.%lu using Win32s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion);
else
printf("\tRunning under Windows NT %lu.%lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion);
return;
}
func = GetProcAddress(kernel32, "GetVersionExA");
if(!func)
{
oldVersion = GetVersion();
verInfo.dwMajorVersion = (oldVersion & 0xFF00) >> 8;
verInfo.dwMinorVersion = oldVersion & 0xFF;
oldVersion &= 0x80000000;
if(oldVersion == 0)
printf("\tRunning under Windows %lu.%lu using Win32s.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion);
else
printf("\tRunning under Windows NT %lu.%lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion);
return;
}
WinGetVersionExA = func;
verInfo.dwOSVersionInfoSize = sizeof(WIN_OSVERSIONINFO);
ret = WinGetVersionExA(&verInfo);
if(!ret) if(!ret)
{ {
@@ -160,22 +196,23 @@ void GetOsInfo()
void GetVolumeInfo(const char *path, size_t *clusterSize) void GetVolumeInfo(const char *path, size_t *clusterSize)
{ {
BOOL ret; BOOL ret;
DWORD error; DWORD error;
LPSTR lpVolumeNameBuffer; LPSTR lpVolumeNameBuffer;
DWORD dwMaximumComponentLength; DWORD dwMaximumComponentLength;
DWORD dwFileSystemFlags; DWORD dwFileSystemFlags;
LPSTR lpFileSystemNameBuffer; LPSTR lpFileSystemNameBuffer;
LPSTR lpRootPathName; LPSTR lpRootPathName;
const size_t pathSize = strlen(path); const size_t pathSize = strlen(path);
DWORD dwSectorsPerCluster; DWORD dwSectorsPerCluster;
DWORD dwBytesPerSector; DWORD dwBytesPerSector;
DWORD dwNumberOfFreeClusters; DWORD dwNumberOfFreeClusters;
DWORD dwTotalNumberOfClusters; DWORD dwTotalNumberOfClusters;
OSVERSIONINFO verInfo; WIN_OSVERSIONINFO verInfo;
ULARGE_INTEGER qwFreeBytesAvailableToCaller; ULARGE_INTEGER qwFreeBytesAvailableToCaller;
ULARGE_INTEGER qwTotalNumberOfBytes; ULARGE_INTEGER qwTotalNumberOfBytes;
ULARGE_INTEGER qwTotalNumberOfFreeBytes; ULARGE_INTEGER qwTotalNumberOfFreeBytes;
void * func;
*clusterSize = 0; *clusterSize = 0;
@@ -394,21 +431,32 @@ void GetVolumeInfo(const char *path, size_t *clusterSize)
printf("\tBytes per sector: %lu\n", dwBytesPerSector); printf("\tBytes per sector: %lu\n", dwBytesPerSector);
printf("\tSectors per cluster: %lu (%u bytes)\n", dwSectorsPerCluster, *clusterSize); printf("\tSectors per cluster: %lu (%u bytes)\n", dwSectorsPerCluster, *clusterSize);
verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if(WinGetVersionExA)
ret = GetVersionExA(&verInfo);
if(!ret)
{ {
error = GetLastError(); verInfo.dwOSVersionInfoSize = sizeof(WIN_OSVERSIONINFO);
printf("Error %lu querying Windows version.\n", error); ret = WinGetVersionExA(&verInfo);
free(lpRootPathName);
return; if(!ret)
{
error = GetLastError();
printf("Error %lu querying Windows version.\n", error);
free(lpRootPathName);
return;
}
} }
else if(oldVersion == 0)
verInfo.dwPlatformId = VER_PLATFORM_WIN32_NT;
if(verInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && verInfo.dwBuildNumber >= 1000 || if(verInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && verInfo.dwBuildNumber >= 1000 ||
verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT && kernel32)
{ {
ret = GetDiskFreeSpaceExA( func = GetProcAddress(kernel32, "GetDiskFreeSpaceExA");
if(func) WinGetDiskFreeSpaceExA = func;
}
if(WinGetDiskFreeSpaceExA)
{
ret = WinGetDiskFreeSpaceExA(
lpRootPathName, &qwFreeBytesAvailableToCaller, &qwTotalNumberOfBytes, &qwTotalNumberOfFreeBytes); lpRootPathName, &qwFreeBytesAvailableToCaller, &qwTotalNumberOfBytes, &qwTotalNumberOfFreeBytes);
if(!ret) if(!ret)
@@ -438,17 +486,17 @@ void GetVolumeInfo(const char *path, size_t *clusterSize)
void FileAttributes(const char *path) void FileAttributes(const char *path)
{ {
BOOL ret; BOOL ret;
DWORD error; DWORD error;
LPSTR lpRootPathName; LPSTR lpRootPathName;
size_t pathSize = strlen(path); size_t pathSize = strlen(path);
HANDLE h; HANDLE h;
DWORD dwNumberOfBytesWritten; DWORD dwNumberOfBytesWritten;
DWORD rc, wRc, cRc, aRc, eRc; DWORD rc, wRc, cRc, aRc, eRc;
OSVERSIONINFO verInfo; WIN_OSVERSIONINFO verInfo;
DWORD defaultCompression = COMPRESSION_FORMAT_DEFAULT; DWORD defaultCompression = COMPRESSION_FORMAT_DEFAULT;
void * func; void * func;
HMODULE advapi32; HMODULE advapi32;
lpRootPathName = malloc(dwMaxNameSize); lpRootPathName = malloc(dwMaxNameSize);
@@ -490,17 +538,6 @@ void FileAttributes(const char *path)
return; return;
} }
verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
ret = GetVersionExA(&verInfo);
if(!ret)
{
error = GetLastError();
printf("Error %lu querying Windows version.\n", error);
free(lpRootPathName);
return;
}
printf("Creating attributes files.\n"); printf("Creating attributes files.\n");
h = CreateFileA("NONE", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); h = CreateFileA("NONE", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
@@ -1337,6 +1374,22 @@ void FileAttributes(const char *path)
} }
printf("\tFile with all attributes: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", "AHORST", rc, wRc, cRc); printf("\tFile with all attributes: name = \"%s\", rc = %lu, wRc = %lu, cRc = %lu\n", "AHORST", rc, wRc, cRc);
if(WinGetVersionExA)
{
verInfo.dwOSVersionInfoSize = sizeof(WIN_OSVERSIONINFO);
ret = WinGetVersionExA(&verInfo);
if(!ret)
{
error = GetLastError();
printf("Error %lu querying Windows version.\n", error);
free(lpRootPathName);
return;
}
}
else if(oldVersion == 0)
verInfo.dwPlatformId = VER_PLATFORM_WIN32_NT;
if(verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) if(verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
{ {
h = CreateFileA("COMPRESS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); h = CreateFileA("COMPRESS", dwFilePermissions, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
@@ -2146,7 +2199,7 @@ void ExtendedAttributes(const char *path)
{ {
BOOL ret; BOOL ret;
DWORD error; DWORD error;
OSVERSIONINFO verInfo; WIN_OSVERSIONINFO verInfo;
HMODULE ntdll; HMODULE ntdll;
void * func; void * func;
DWORD dwNumberOfBytesWritten; DWORD dwNumberOfBytesWritten;
@@ -2160,15 +2213,20 @@ void ExtendedAttributes(const char *path)
int i; int i;
BOOL cmp; BOOL cmp;
verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if(WinGetVersionExA)
ret = GetVersionExA(&verInfo);
if(!ret)
{ {
error = GetLastError(); verInfo.dwOSVersionInfoSize = sizeof(WIN_OSVERSIONINFO);
printf("Error %lu querying Windows version.\n", error); ret = WinGetVersionExA(&verInfo);
return;
if(!ret)
{
error = GetLastError();
printf("Error %lu querying Windows version.\n", error);
return;
}
} }
else if(oldVersion == 0)
verInfo.dwPlatformId = VER_PLATFORM_WIN32_NT;
if(verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT) if(verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
{ {
@@ -2452,26 +2510,30 @@ void ExtendedAttributes(const char *path)
void ResourceFork(const char *path) void ResourceFork(const char *path)
{ {
BOOL ret; BOOL ret;
DWORD error; DWORD error;
LPSTR lpRootPathName; LPSTR lpRootPathName;
size_t pathSize = strlen(path); size_t pathSize = strlen(path);
HANDLE h; HANDLE h;
DWORD dwNumberOfBytesWritten; DWORD dwNumberOfBytesWritten;
DWORD rc, wRc, cRc; DWORD rc, wRc, cRc;
OSVERSIONINFO verInfo; WIN_OSVERSIONINFO verInfo;
unsigned int maxLoop; unsigned int maxLoop, i;
int i;
verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if(WinGetVersionExA)
ret = GetVersionExA(&verInfo);
if(!ret)
{ {
error = GetLastError(); verInfo.dwOSVersionInfoSize = sizeof(WIN_OSVERSIONINFO);
printf("Error %lu querying Windows version.\n", error); ret = WinGetVersionExA(&verInfo);
return;
if(!ret)
{
error = GetLastError();
printf("Error %lu querying Windows version.\n", error);
return;
}
} }
else if(oldVersion == 0)
verInfo.dwPlatformId = VER_PLATFORM_WIN32_NT;
if(verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT) if(verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
{ {
@@ -3243,7 +3305,7 @@ void DirectoryDepth(const char *path)
while(ret) while(ret)
{ {
memset(filename, 0, 9); memset(filename, 0, 9);
sprintf(filename, "%08d", pos); sprintf(filename, "%08ld", pos);
ret = CreateDirectoryA(filename, NULL); ret = CreateDirectoryA(filename, NULL);
if(ret) ret = SetCurrentDirectoryA(filename); if(ret) ret = SetCurrentDirectoryA(filename);
@@ -3262,7 +3324,7 @@ void Fragmentation(const char *path, size_t clusterSize)
size_t threeQuartersCluster = halfCluster + quarterCluster; size_t threeQuartersCluster = halfCluster + quarterCluster;
size_t twoAndThreeQuartCluster = threeQuartersCluster + twoCluster; size_t twoAndThreeQuartCluster = threeQuartersCluster + twoCluster;
unsigned char *buffer; unsigned char *buffer;
long i; size_t i;
BOOL ret; BOOL ret;
DWORD error; DWORD error;
LPSTR lpRootPathName; LPSTR lpRootPathName;
@@ -3847,27 +3909,31 @@ void Sparse(const char *path)
void Links(const char *path) void Links(const char *path)
{ {
BOOL ret; BOOL ret;
DWORD error; DWORD error;
OSVERSIONINFO verInfo; WIN_OSVERSIONINFO verInfo;
HINSTANCE kernel32; void * func;
void * func; DWORD dwNumberOfBytesWritten;
DWORD dwNumberOfBytesWritten; DWORD rc, wRc, cRc, lRc;
DWORD rc, wRc, cRc, lRc; char message[300];
char message[300]; HANDLE h;
HANDLE h; LPSTR lpRootPathName;
LPSTR lpRootPathName; size_t pathSize = strlen(path);
size_t pathSize = strlen(path);
verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if(WinGetVersionExA)
ret = GetVersionExA(&verInfo);
if(!ret)
{ {
error = GetLastError(); verInfo.dwOSVersionInfoSize = sizeof(WIN_OSVERSIONINFO);
printf("Error %lu querying Windows version.\n", error); ret = WinGetVersionExA(&verInfo);
return;
if(!ret)
{
error = GetLastError();
printf("Error %lu querying Windows version.\n", error);
return;
}
} }
else if(oldVersion == 0)
verInfo.dwPlatformId = VER_PLATFORM_WIN32_NT;
if(verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT) if(verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)
{ {
@@ -4007,8 +4073,6 @@ void Links(const char *path)
printf("\tHard link, rc = 0x%08lx, wRc = %lu, cRc = %lu, lRc = %lu\n", rc, wRc, cRc, lRc); printf("\tHard link, rc = 0x%08lx, wRc = %lu, cRc = %lu, lRc = %lu\n", rc, wRc, cRc, lRc);
} }
FreeLibrary(kernel32);
} }
void MillionFiles(const char *path) void MillionFiles(const char *path)

View File

@@ -455,9 +455,25 @@ unsigned char IconEA[3516] = {
#define Y2KTIMESTAMP_LO 0x256D4000 #define Y2KTIMESTAMP_LO 0x256D4000
#define Y1KTIMESTAMP_LO 0x24D4A980 #define Y1KTIMESTAMP_LO 0x24D4A980
typedef struct _WIN_OSVERSIONINFOA
{
DWORD dwOSVersionInfoSize;
DWORD dwMajorVersion;
DWORD dwMinorVersion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
CHAR szCSDVersion[128]; // Maintenance string for PSS usage
} WIN_OSVERSIONINFOA, *WIN_POSVERSIONINFOA, *WIN_LPOSVERSIONINFOA;
typedef WIN_OSVERSIONINFOA WIN_OSVERSIONINFO;
typedef WIN_POSVERSIONINFOA WIN_POSVERSIONINFO;
typedef WIN_LPOSVERSIONINFOA WIN_LPOSVERSIONINFO;
BOOL(WINAPI *WinNtCreateHardLinkA)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); BOOL(WINAPI *WinNtCreateHardLinkA)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES);
BOOL(WINAPI *WinNtCreateSymbolicLinkA)(LPCSTR, LPCSTR, DWORD); BOOL(WINAPI *WinNtCreateSymbolicLinkA)(LPCSTR, LPCSTR, DWORD);
BOOL(WINAPI *WinNtEncryptFileA)(LPCSTR); BOOL(WINAPI *WinNtEncryptFileA)(LPCSTR);
BOOL(WINAPI *WinGetVersionExA)(WIN_LPOSVERSIONINFOA);
BOOL(WINAPI *WinGetDiskFreeSpaceExA)(LPCSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER);
#endif #endif