mirror of
https://github.com/reactos/reactos.git
synced 2025-05-25 12:14:32 +00:00
[CABMAN] Remove _WIN32 ifdef's
This commit is contained in:
parent
5b8975211d
commit
ae391dd609
5 changed files with 244 additions and 709 deletions
File diff suppressed because it is too large
Load diff
|
@ -8,16 +8,17 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <typedefs.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <typedefs.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
@ -34,20 +35,23 @@
|
|||
|
||||
#define strcasecmp _stricmp
|
||||
#define strdup _strdup
|
||||
|
||||
#define AllocateMemory(size) HeapAlloc(GetProcessHeap(), 0, size)
|
||||
#define FreeMemory(buffer) HeapFree(GetProcessHeap(), 0, buffer)
|
||||
#define FILEHANDLE HANDLE
|
||||
#define CloseFile(handle) CloseHandle(handle)
|
||||
#else
|
||||
#define DIR_SEPARATOR_CHAR '/'
|
||||
#define DIR_SEPARATOR_STRING "/"
|
||||
#endif // _WIN32
|
||||
|
||||
#define AllocateMemory(size) malloc(size)
|
||||
#define FreeMemory(buffer) free(buffer)
|
||||
#define CloseFile(handle) fclose(handle)
|
||||
#define FILEHANDLE FILE*
|
||||
#endif
|
||||
inline LONG GetSizeOfFile(FILE* handle)
|
||||
{
|
||||
LONG size;
|
||||
LONG currentPos = ftell(handle);
|
||||
|
||||
if (fseek(handle, 0, SEEK_END) != 0)
|
||||
return (LONG)-1;
|
||||
|
||||
size = ftell(handle);
|
||||
fseek(handle, 0, SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
|
||||
/* Debugging */
|
||||
|
||||
|
@ -309,8 +313,7 @@ public:
|
|||
ULONG WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten);
|
||||
private:
|
||||
char FullName[PATH_MAX];
|
||||
bool FileCreated;
|
||||
FILEHANDLE FileHandle;
|
||||
FILE* FileHandle;
|
||||
};
|
||||
|
||||
#endif /* CAB_READ_ONLY */
|
||||
|
@ -437,7 +440,7 @@ private:
|
|||
ULONG WriteDataBlock();
|
||||
ULONG GetAttributesOnFile(PCFFILE_NODE File);
|
||||
ULONG SetAttributesOnFile(char* FileName, USHORT FileAttributes);
|
||||
ULONG GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
|
||||
ULONG GetFileTimes(FILE* FileHandle, PCFFILE_NODE File);
|
||||
#if !defined(_WIN32)
|
||||
void ConvertDateAndTime(time_t* Time, PUSHORT DosDate, PUSHORT DosTime);
|
||||
#endif
|
||||
|
@ -459,7 +462,7 @@ private:
|
|||
char CabinetReservedFile[PATH_MAX];
|
||||
void* CabinetReservedFileBuffer;
|
||||
ULONG CabinetReservedFileSize;
|
||||
FILEHANDLE FileHandle;
|
||||
FILE* FileHandle;
|
||||
bool FileOpen;
|
||||
CFHEADER CABHeader;
|
||||
ULONG CabinetReserved;
|
||||
|
@ -495,7 +498,7 @@ private:
|
|||
bool CreateNewFolder;
|
||||
|
||||
CCFDATAStorage *ScratchFile;
|
||||
FILEHANDLE SourceFile;
|
||||
FILE* SourceFile;
|
||||
bool ContinueFile;
|
||||
ULONG TotalBytesLeft;
|
||||
bool BlockIsSplit; // true if current data block is split
|
||||
|
|
|
@ -17,40 +17,6 @@
|
|||
#include "cabman.h"
|
||||
#include "dfp.h"
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define GetSizeOfFile(handle) _GetSizeOfFile(handle)
|
||||
static LONG _GetSizeOfFile(FILEHANDLE handle)
|
||||
{
|
||||
ULONG size = GetFileSize(handle, NULL);
|
||||
if (size == INVALID_FILE_SIZE)
|
||||
return -1;
|
||||
|
||||
return size;
|
||||
}
|
||||
#define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread)
|
||||
static BOOL _ReadFileData(FILEHANDLE handle, void* buffer, ULONG size, PULONG bytesread)
|
||||
{
|
||||
return ReadFile(handle, buffer, size, (LPDWORD)bytesread, NULL);
|
||||
}
|
||||
#else
|
||||
#define GetSizeOfFile(handle) _GetSizeOfFile(handle)
|
||||
static LONG _GetSizeOfFile(FILEHANDLE handle)
|
||||
{
|
||||
LONG size;
|
||||
fseek(handle, 0, SEEK_END);
|
||||
size = ftell(handle);
|
||||
fseek(handle, 0, SEEK_SET);
|
||||
return size;
|
||||
}
|
||||
#define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread)
|
||||
static bool _ReadFileData(FILEHANDLE handle, void* buffer, ULONG size, PULONG bytesread)
|
||||
{
|
||||
*bytesread = fread(buffer, 1, size, handle);
|
||||
return *bytesread == size;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* CDFParser */
|
||||
|
||||
CDFParser::CDFParser()
|
||||
|
@ -94,31 +60,31 @@ CDFParser::~CDFParser()
|
|||
PDISK_NUMBER DNNext;
|
||||
|
||||
if (FileBuffer)
|
||||
FreeMemory(FileBuffer);
|
||||
free(FileBuffer);
|
||||
CNNext = CabinetName;
|
||||
while (CNNext != NULL)
|
||||
{
|
||||
CNPrev = CNNext->Next;
|
||||
FreeMemory(CNNext);
|
||||
free(CNNext);
|
||||
CNNext = CNPrev;
|
||||
}
|
||||
CNNext = DiskLabel;
|
||||
while (CNNext != NULL)
|
||||
{
|
||||
CNPrev = CNNext->Next;
|
||||
FreeMemory(CNNext);
|
||||
free(CNNext);
|
||||
CNNext = CNPrev;
|
||||
}
|
||||
DNNext = MaxDiskSize;
|
||||
while (DNNext != NULL)
|
||||
{
|
||||
DNPrev = DNNext->Next;
|
||||
FreeMemory(DNNext);
|
||||
free(DNNext);
|
||||
DNNext = DNPrev;
|
||||
}
|
||||
|
||||
if (InfFileHandle != NULL)
|
||||
CloseFile(InfFileHandle);
|
||||
fclose(InfFileHandle);
|
||||
}
|
||||
|
||||
void CDFParser::WriteInfLine(char* InfLine)
|
||||
|
@ -126,9 +92,6 @@ void CDFParser::WriteInfLine(char* InfLine)
|
|||
char buf[PATH_MAX];
|
||||
char eolbuf[2];
|
||||
char* destpath;
|
||||
#if defined(_WIN32)
|
||||
ULONG BytesWritten;
|
||||
#endif
|
||||
|
||||
if (DontGenerateInf)
|
||||
return;
|
||||
|
@ -149,53 +112,28 @@ void CDFParser::WriteInfLine(char* InfLine)
|
|||
strcpy(buf, InfFileName);
|
||||
|
||||
/* Create .inf file, overwrite if it already exists */
|
||||
#if defined(_WIN32)
|
||||
InfFileHandle = CreateFile(buf, // Create this file
|
||||
GENERIC_WRITE, // Open for writing
|
||||
0, // No sharing
|
||||
NULL, // No security
|
||||
CREATE_ALWAYS, // Create or overwrite
|
||||
FILE_ATTRIBUTE_NORMAL, // Normal file
|
||||
NULL); // No attribute template
|
||||
if (InfFileHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
DPRINT(MID_TRACE, ("Error creating '%u'.\n", (UINT)GetLastError()));
|
||||
return;
|
||||
}
|
||||
#else /* !_WIN32 */
|
||||
InfFileHandle = fopen(buf, "wb");
|
||||
if (InfFileHandle == NULL)
|
||||
{
|
||||
DPRINT(MID_TRACE, ("Error creating '%i'.\n", errno));
|
||||
DPRINT(MID_TRACE, ("Error creating INF file.\n"));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
if (!WriteFile(InfFileHandle, InfLine, (DWORD)strlen(InfLine), (LPDWORD)&BytesWritten, NULL))
|
||||
if (fwrite(InfLine, strlen(InfLine), 1, InfFileHandle) < 1)
|
||||
{
|
||||
DPRINT(MID_TRACE, ("ERROR WRITING '%u'.\n", (UINT)GetLastError()));
|
||||
DPRINT(MID_TRACE, ("Error writing INF file.\n"));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (fwrite(InfLine, strlen(InfLine), 1, InfFileHandle) < 1)
|
||||
return;
|
||||
#endif
|
||||
|
||||
eolbuf[0] = 0x0d;
|
||||
eolbuf[1] = 0x0a;
|
||||
|
||||
#if defined(_WIN32)
|
||||
if (!WriteFile(InfFileHandle, eolbuf, sizeof(eolbuf), (LPDWORD)&BytesWritten, NULL))
|
||||
if (fwrite(eolbuf, sizeof(eolbuf), 1, InfFileHandle) < 1)
|
||||
{
|
||||
DPRINT(MID_TRACE, ("ERROR WRITING '%u'.\n", (UINT)GetLastError()));
|
||||
DPRINT(MID_TRACE, ("Error writing INF file.\n"));
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (fwrite(eolbuf, 1, sizeof(eolbuf), InfFileHandle) < 1)
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -208,54 +146,43 @@ ULONG CDFParser::Load(char* FileName)
|
|||
* Status of operation
|
||||
*/
|
||||
{
|
||||
ULONG BytesRead;
|
||||
LONG FileSize;
|
||||
|
||||
if (FileLoaded)
|
||||
return CAB_STATUS_SUCCESS;
|
||||
|
||||
/* Create cabinet file, overwrite if it already exists */
|
||||
#if defined(_WIN32)
|
||||
FileHandle = CreateFile(FileName, // Create this file
|
||||
GENERIC_READ, // Open for reading
|
||||
0, // No sharing
|
||||
NULL, // No security
|
||||
OPEN_EXISTING, // Open the file
|
||||
FILE_ATTRIBUTE_NORMAL, // Normal file
|
||||
NULL); // No attribute template
|
||||
if (FileHandle == INVALID_HANDLE_VALUE)
|
||||
return CAB_STATUS_CANNOT_OPEN;
|
||||
#else /* !_WIN32 */
|
||||
/* Open the directive file */
|
||||
FileHandle = fopen(FileName, "rb");
|
||||
if (FileHandle == NULL)
|
||||
{
|
||||
return CAB_STATUS_CANNOT_OPEN;
|
||||
#endif
|
||||
}
|
||||
|
||||
FileSize = GetSizeOfFile(FileHandle);
|
||||
if (FileSize == -1)
|
||||
{
|
||||
CloseFile(FileHandle);
|
||||
fclose(FileHandle);
|
||||
return CAB_STATUS_CANNOT_OPEN;
|
||||
}
|
||||
|
||||
FileBufferSize = (ULONG)FileSize;
|
||||
|
||||
FileBuffer = (char*)AllocateMemory(FileBufferSize);
|
||||
FileBuffer = (char*)malloc(FileBufferSize);
|
||||
if (!FileBuffer)
|
||||
{
|
||||
CloseFile(FileHandle);
|
||||
fclose(FileHandle);
|
||||
return CAB_STATUS_NOMEMORY;
|
||||
}
|
||||
|
||||
if (!ReadFileData(FileHandle, FileBuffer, FileBufferSize, &BytesRead))
|
||||
if ( fread(FileBuffer, FileBufferSize, 1, FileHandle) < 1 )
|
||||
{
|
||||
CloseFile(FileHandle);
|
||||
FreeMemory(FileBuffer);
|
||||
fclose(FileHandle);
|
||||
free(FileBuffer);
|
||||
FileBuffer = NULL;
|
||||
return CAB_STATUS_CANNOT_READ;
|
||||
}
|
||||
|
||||
CloseFile(FileHandle);
|
||||
fclose(FileHandle);
|
||||
|
||||
FileLoaded = true;
|
||||
|
||||
|
@ -571,7 +498,7 @@ bool CDFParser::SetDiskName(PCABINET_NAME *List, ULONG Number, char* String)
|
|||
CN = CN->Next;
|
||||
}
|
||||
|
||||
CN = (PCABINET_NAME)AllocateMemory(sizeof(CABINET_NAME));
|
||||
CN = (PCABINET_NAME)malloc(sizeof(CABINET_NAME));
|
||||
if (!CN)
|
||||
return false;
|
||||
|
||||
|
@ -637,7 +564,7 @@ bool CDFParser::SetDiskNumber(PDISK_NUMBER *List, ULONG Number, ULONG Value)
|
|||
DN = DN->Next;
|
||||
}
|
||||
|
||||
DN = (PDISK_NUMBER)AllocateMemory(sizeof(DISK_NUMBER));
|
||||
DN = (PDISK_NUMBER)malloc(sizeof(DISK_NUMBER));
|
||||
if (!DN)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ private:
|
|||
void NextToken();
|
||||
/* Parsing */
|
||||
bool FileLoaded;
|
||||
FILEHANDLE FileHandle;
|
||||
FILE* FileHandle;
|
||||
char* FileBuffer;
|
||||
ULONG FileBufferSize;
|
||||
ULONG CurrentOffset;
|
||||
|
@ -140,7 +140,7 @@ private:
|
|||
ULONG ReservePerDataBlockSize;
|
||||
ULONG ReservePerFolderSize;
|
||||
char SourceDir[256];
|
||||
FILEHANDLE InfFileHandle;
|
||||
FILE* InfFileHandle;
|
||||
bool InfModeEnabled;
|
||||
};
|
||||
|
||||
|
|
|
@ -21,13 +21,13 @@
|
|||
voidpf MSZipAlloc(voidpf opaque, uInt items, uInt size)
|
||||
{
|
||||
DPRINT(DEBUG_MEMORY, ("items = (%d) size = (%d)\n", items, size));
|
||||
return AllocateMemory(items * size);
|
||||
return malloc(items * size);
|
||||
}
|
||||
|
||||
void MSZipFree (voidpf opaque, voidpf address)
|
||||
{
|
||||
DPRINT(DEBUG_MEMORY, ("\n"));
|
||||
FreeMemory(address);
|
||||
free(address);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue