diff -Naur genpat3posix.orig/Checksums.cpp genpat3posix/Checksums.cpp --- genpat3posix.orig/Checksums.cpp 2005-08-20 20:58:50.000000000 +0800 +++ genpat3posix/Checksums.cpp 2005-09-08 12:21:27.000000000 +0800 @@ -23,6 +23,7 @@ // misrepresented as being the original software. // 3. This notice may not be removed or altered from any source distribution. +#include #include "Checksums.h" /* ------------------------ CRC32 checksum calculation ----------------- */ @@ -42,7 +43,7 @@ bInitCRC = TRUE; } -BOOL FileCRC(HANDLE hFile, DWORD *crc) { +BOOL FileCRC(FILE* hFile, DWORD *crc) { if (bInitCRC == FALSE) InitCRC(); @@ -54,9 +55,11 @@ UINT c = 0xFFFFFFFF; - SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + rewind(hFile); + // same as fseek(hFile, 0L, SEEK_SET); do { - if (ReadFile(hFile, block, CRCBLOCKSIZE, &read, NULL) == FALSE) + read = fread( block, 1, CRCBLOCKSIZE, hFile ); + if ( ferror(hFile) ) return FALSE; for (p = block; p < block + read; p++) c = CRCTable[(c & 0xFF) ^ *p] ^ (c >> 8); @@ -68,15 +71,14 @@ } DWORD fileCRC(std::string fileName) { - HANDLE hPatch = CreateFile(fileName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + FILE* hPatch = fopen(fileName.c_str(), "rb"); - if (hPatch == INVALID_HANDLE_VALUE) { + if (hPatch == NULL) { throw "Unable to open file for CRC"; } DWORD res; FileCRC(hPatch,&res); - CloseHandle(hPatch); + fclose(hPatch); return res; } @@ -84,7 +86,7 @@ #define MD5BLOCKSIZE 16384 -BOOL FileMD5(HANDLE hFile, md5_byte_t digest[16]) { +BOOL FileMD5(FILE* hFile, md5_byte_t digest[16]) { static BYTE md5block[MD5BLOCKSIZE]; DWORD read; @@ -92,9 +94,11 @@ md5_init(&state); - SetFilePointer(hFile, 0, NULL, FILE_BEGIN); + rewind(hFile); + // same as fseek(hFile, 0L, SEEK_SET); do { - if (ReadFile(hFile, md5block, MD5BLOCKSIZE, &read, NULL) == FALSE) + read = fread( md5block, 1, MD5BLOCKSIZE, hFile ); + if ( ferror(hFile) ) return FALSE; md5_append(&state, md5block, read); } while (read); @@ -104,14 +108,13 @@ } void fileMD5(std::string fileName, md5_byte_t digest[16]) { - HANDLE hPatch = CreateFile(fileName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + FILE* hPatch = fopen(fileName.c_str(), "rb"); - if (hPatch == INVALID_HANDLE_VALUE) { + if (hPatch == NULL) { throw "Unable to open file for MD5"; } FileMD5(hPatch,digest); - CloseHandle(hPatch); + fclose(hPatch); } void TChecksum::loadMD5(md5_byte_t newdigest[16]) { diff -Naur genpat3posix.orig/Checksums.h genpat3posix/Checksums.h --- genpat3posix.orig/Checksums.h 2005-08-20 20:58:58.000000000 +0800 +++ genpat3posix/Checksums.h 2005-09-08 11:53:27.000000000 +0800 @@ -27,9 +27,10 @@ #define Checksums_H #include - #define WIN32_LEAN_AND_MEAN - #include + //#define WIN32_LEAN_AND_MEAN + //#include #include "md5.h" + #include "POSIXUtil.h" DWORD fileCRC(std::string fileName); void fileMD5(std::string fileName, md5_byte_t digest[16]); diff -Naur genpat3posix.orig/main.cpp genpat3posix/main.cpp --- genpat3posix.orig/main.cpp 2005-09-08 01:24:16.000000000 +0800 +++ genpat3posix/main.cpp 2005-09-08 11:51:50.000000000 +0800 @@ -35,7 +35,7 @@ #include #include -/* // This is a POSIX version of the function, together with #include + // This is a POSIX version of the function, together with #include // but I will not add it in a final release version. string getTempFile() { char filebuf [L_tmpnam]; @@ -48,7 +48,7 @@ return string(fname); } -*/ +/* string getTempFile() { char buffer[MAX_PATH]; if(GetTempFileName(".","vpatch",0,buffer) == 0) { @@ -56,7 +56,7 @@ } return string(buffer); } - +*/ int main( int argc, char * argv[] ) { cout << "GenPat v3.0 POSIX\n"; cout << "===========\n\n(c) 2001-2005 Van de Sande Productions\n"; @@ -224,7 +224,7 @@ } catch(char* s) { cerr << "ERROR: " << s << "\n"; patch.close(); - DeleteFile(tempFileName.c_str()); + unlink(tempFileName.c_str()); return 3; } @@ -321,6 +321,6 @@ cerr << "WARNING: source and target file have equal CRCs!"; delete sourceCRC; delete targetCRC; - DeleteFile(tempFileName.c_str()); + unlink(tempFileName.c_str()); return 0; } diff -Naur genpat3posix.orig/Makefile genpat3posix/Makefile --- genpat3posix.orig/Makefile 1970-01-01 08:00:00.000000000 +0800 +++ genpat3posix/Makefile 2005-09-08 12:26:13.000000000 +0800 @@ -0,0 +1,9 @@ +# GNU/Linux Makefile + +CXXFLAGS=-Wall + +genpat: Checksums.o adler32.o ChunkedFile.o GlobalTypes.o FileFormat1.o main.o md5.o POSIXUtil.o + g++ -o $@ $^ + +clean: + rm genpat *.o diff -Naur genpat3posix.orig/POSIXUtil.cpp genpat3posix/POSIXUtil.cpp --- genpat3posix.orig/POSIXUtil.cpp 2005-09-08 01:26:40.000000000 +0800 +++ genpat3posix/POSIXUtil.cpp 2005-09-08 11:52:18.000000000 +0800 @@ -25,14 +25,14 @@ #include "POSIXUtil.h" -#include +//#include #include #include #include #include #include -//#include +#include int stat(const char *file_name, struct stat *buf); int lstat(const char *file_name, struct stat *buf); diff -Naur genpat3posix.orig/POSIXUtil.h genpat3posix/POSIXUtil.h --- genpat3posix.orig/POSIXUtil.h 2005-09-07 19:08:32.000000000 +0800 +++ genpat3posix/POSIXUtil.h 2005-09-08 11:54:36.000000000 +0800 @@ -37,4 +37,12 @@ uint32_t getFileSize(const char* sFileName); } + typedef uint32_t DWORD; + typedef uint8_t BYTE; + typedef unsigned int UINT; + typedef bool BOOL; + #define FALSE false + #define TRUE true + typedef void* HANDLE; + #endif // POSIXUtil_H