mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-14 22:03:27 +01:00
move crc32 function
This commit is contained in:
parent
107897a29f
commit
a7b8e2e80f
@ -6,5 +6,6 @@
|
||||
|
||||
|
||||
unsigned long Crc32_ComputeBuf(unsigned long inCrc32, const void* buf, size_t bufLen);
|
||||
unsigned long Crc32_FromFile(char* filename);
|
||||
|
||||
#endif
|
||||
|
25
src/crc32.c
25
src/crc32.c
@ -77,6 +77,31 @@ unsigned long Crc32_ComputeBuf( unsigned long inCrc32, const void *buf,
|
||||
return( crc32 ^ 0xFFFFFFFF );
|
||||
}
|
||||
|
||||
unsigned long Crc32_FromFile(char* filename)
|
||||
{
|
||||
if (!filename)
|
||||
return 0;
|
||||
|
||||
unsigned long crc32 = 0;
|
||||
|
||||
FILE* fp = fopen(filename, "rb");
|
||||
if (fp)
|
||||
{
|
||||
char buf[1024];
|
||||
for (size_t s = 0; (s = fread(buf, 1, sizeof(buf), fp)) && !ferror(fp);)
|
||||
{
|
||||
crc32 = Crc32_ComputeBuf(crc32, buf, s);
|
||||
}
|
||||
|
||||
if (ferror(fp))
|
||||
crc32 = 0;
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return crc32;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*\
|
||||
* END OF MODULE: crc32.c
|
||||
\*----------------------------------------------------------------------------*/
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "git.h"
|
||||
#include "versionhelpers.h"
|
||||
#include "utils.h"
|
||||
#include "crc32.h"
|
||||
#include "dllmain.h"
|
||||
#include "config.h"
|
||||
|
||||
@ -268,7 +269,7 @@ void dbg_init()
|
||||
TRACE("Wine sysname = %s, release = %s\n", sysname, release);
|
||||
}
|
||||
|
||||
TRACE("crc32 = %08X\n", util_get_crc32(exe_path));
|
||||
TRACE("crc32 = %08X\n", Crc32_FromFile(exe_path));
|
||||
|
||||
DWORD timestamp = util_get_timestamp(GetModuleHandleA(NULL));
|
||||
if (timestamp)
|
||||
|
26
src/utils.c
26
src/utils.c
@ -12,7 +12,6 @@
|
||||
#include "utils.h"
|
||||
#include "config.h"
|
||||
#include "versionhelpers.h"
|
||||
#include "crc32.h"
|
||||
|
||||
|
||||
/*
|
||||
@ -107,31 +106,6 @@ DWORD util_get_timestamp(HMODULE mod)
|
||||
return nt_headers->FileHeader.TimeDateStamp;
|
||||
}
|
||||
|
||||
unsigned long util_get_crc32(char* filename)
|
||||
{
|
||||
if (!filename)
|
||||
return 0;
|
||||
|
||||
unsigned long crc32 = 0;
|
||||
|
||||
FILE* fp = fopen(filename, "rb");
|
||||
if (fp)
|
||||
{
|
||||
char buf[1024];
|
||||
for (size_t s = 0; (s = fread(buf, 1, sizeof(buf), fp)) && !ferror(fp);)
|
||||
{
|
||||
crc32 = Crc32_ComputeBuf(crc32, buf, s);
|
||||
}
|
||||
|
||||
if (ferror(fp))
|
||||
crc32 = 0;
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return crc32;
|
||||
}
|
||||
|
||||
FARPROC util_get_iat_proc(HMODULE mod, char* module_name, char* function_name)
|
||||
{
|
||||
if (!mod || mod == INVALID_HANDLE_VALUE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user