From 2951ae5b61b16c1f4e03ceee88d6db7e1e45362b Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Wed, 26 May 2021 04:17:09 +0200 Subject: Prefix symbols to prevent potential conflicts when linking to the library --- FileSystem.c | 14 +++++++------- FileSystem.h | 14 +++++++------- Hamcore.c | 54 +++++++++++++++++++++++++++--------------------------- Memory.c | 6 ++---- Memory.h | 8 ++++---- 5 files changed, 47 insertions(+), 49 deletions(-) diff --git a/FileSystem.c b/FileSystem.c index b0eda22..3968562 100755 --- a/FileSystem.c +++ b/FileSystem.c @@ -4,7 +4,7 @@ #include -FILE *FileOpen(const char *path, const bool write) +FILE *Ham_FileOpen(const char *path, const bool write) { if (!path) { @@ -14,7 +14,7 @@ FILE *FileOpen(const char *path, const bool write) return fopen(path, write ? "wb" : "rb"); } -bool FileClose(FILE *file) +bool Ham_FileClose(FILE *file) { if (!file) { @@ -24,7 +24,7 @@ bool FileClose(FILE *file) return fclose(file) == 0; } -bool FileRead(FILE *file, void *dst, const size_t size) +bool Ham_FileRead(FILE *file, void *dst, const size_t size) { if (!file || !dst || size == 0) { @@ -34,7 +34,7 @@ bool FileRead(FILE *file, void *dst, const size_t size) return fread(dst, 1, size, file) == size; } -bool FileWrite(FILE *file, const void *src, const size_t size) +bool Ham_FileWrite(FILE *file, const void *src, const size_t size) { if (!file || !src || size == 0) { @@ -44,7 +44,7 @@ bool FileWrite(FILE *file, const void *src, const size_t size) return fwrite(src, 1, size, file) == size; } -bool FileSeek(FILE *file, const size_t offset) +bool Ham_FileSeek(FILE *file, const size_t offset) { if (!file) { @@ -54,7 +54,7 @@ bool FileSeek(FILE *file, const size_t offset) return fseek(file, (long)offset, SEEK_SET) == 0; } -size_t FileSize(const char *path) +size_t Ham_FileSize(const char *path) { if (!path) { @@ -70,7 +70,7 @@ size_t FileSize(const char *path) return st.st_size; } -const char *PathRelativeToBase(const char *full, const char *base) +const char *Ham_PathRelativeToBase(const char *full, const char *base) { if (!full || !base) { diff --git a/FileSystem.h b/FileSystem.h index b4092c7..a7877c2 100755 --- a/FileSystem.h +++ b/FileSystem.h @@ -4,16 +4,16 @@ #include #include -FILE *FileOpen(const char *path, const bool write); -bool FileClose(FILE *file); +FILE *Ham_FileOpen(const char *path, const bool write); +bool Ham_FileClose(FILE *file); -bool FileRead(FILE *file, void *dst, const size_t size); -bool FileWrite(FILE *file, const void *src, const size_t size); +bool Ham_FileRead(FILE *file, void *dst, const size_t size); +bool Ham_FileWrite(FILE *file, const void *src, const size_t size); -bool FileSeek(FILE *file, const size_t offset); +bool Ham_FileSeek(FILE *file, const size_t offset); -size_t FileSize(const char *path); +size_t Ham_FileSize(const char *path); -const char *PathRelativeToBase(const char *full, const char *base); +const char *Ham_PathRelativeToBase(const char *full, const char *base); #endif diff --git a/Hamcore.c b/Hamcore.c index 83a1ade..9689a2d 100644 --- a/Hamcore.c +++ b/Hamcore.c @@ -28,7 +28,7 @@ HAMCORE *HamcoreOpen(const char *path) } memset(hamcore, 0, sizeof(HAMCORE)); - hamcore->File = FileOpen(path, false); + hamcore->File = Ham_FileOpen(path, false); if (!hamcore->File) { free(hamcore); @@ -38,7 +38,7 @@ HAMCORE *HamcoreOpen(const char *path) bool ok = false; uint8_t header[HAMCORE_HEADER_SIZE]; - if (!FileRead(hamcore->File, header, sizeof(header))) + if (!Ham_FileRead(hamcore->File, header, sizeof(header))) { goto FINAL; } @@ -49,7 +49,7 @@ HAMCORE *HamcoreOpen(const char *path) } uint32_t tmp; - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } @@ -66,7 +66,7 @@ HAMCORE *HamcoreOpen(const char *path) for (size_t i = 0; i < files->Num; ++i) { - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } @@ -81,26 +81,26 @@ HAMCORE *HamcoreOpen(const char *path) --tmp; } - if (!FileRead(hamcore->File, file->Path, tmp)) + if (!Ham_FileRead(hamcore->File, file->Path, tmp)) { goto FINAL; } - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } file->OriginalSize = BigEndian32(tmp); - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } file->Size = BigEndian32(tmp); - if (!FileRead(hamcore->File, &tmp, sizeof(tmp))) + if (!Ham_FileRead(hamcore->File, &tmp, sizeof(tmp))) { goto FINAL; } @@ -126,7 +126,7 @@ void HamcoreClose(HAMCORE *hamcore) return; } - FileClose(hamcore->File); + Ham_FileClose(hamcore->File); HAMCORE_FILES *files = &hamcore->Files; if (!files->List) @@ -175,7 +175,7 @@ bool HamcoreRead(HAMCORE *hamcore, void *dst, const HAMCORE_FILE *hamcore_file) return false; } - if (!FileSeek(hamcore->File, hamcore_file->Offset)) + if (!Ham_FileSeek(hamcore->File, hamcore_file->Offset)) { return false; } @@ -183,7 +183,7 @@ bool HamcoreRead(HAMCORE *hamcore, void *dst, const HAMCORE_FILE *hamcore_file) bool ok = false; void *buf = malloc(hamcore_file->Size); - if (!FileRead(hamcore->File, buf, hamcore_file->Size)) + if (!Ham_FileRead(hamcore->File, buf, hamcore_file->Size)) { goto FINAL; } @@ -229,7 +229,7 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ continue; } - FILE *handle = FileOpen(path, false); + FILE *handle = Ham_FileOpen(path, false); if (!handle) { fprintf(stderr, "HamcoreBuild(): Failed to open \"%s\", skipping...\n", path); @@ -239,10 +239,10 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ COMPRESSED_FILE *compressed_file = &compressed_files[i]; HAMCORE_FILE *file = &compressed_file->File; - file->OriginalSize = FileSize(path); + file->OriginalSize = Ham_FileSize(path); void *content = malloc(file->OriginalSize); - int ret = FileRead(handle, content, file->OriginalSize); - FileClose(handle); + int ret = Ham_FileRead(handle, content, file->OriginalSize); + Ham_FileClose(handle); if (!ret) { @@ -271,7 +271,7 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ continue; } - const char *relative_path = base_path ? PathRelativeToBase(path, base_path) : path; + const char *relative_path = base_path ? Ham_PathRelativeToBase(path, base_path) : path; if (!relative_path) { fprintf(stderr, "HamcoreBuild(): Failed to get relative path for \"%s\", skipping...\n", path); @@ -343,9 +343,9 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ } void *ptr = buffer; - WriteAndSeek(&ptr, HAMCORE_HEADER_DATA, HAMCORE_HEADER_SIZE); + Ham_WriteAndSeek(&ptr, HAMCORE_HEADER_DATA, HAMCORE_HEADER_SIZE); uint32_t tmp = BigEndian32((uint32_t)num); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); for (size_t i = 0; i < num; ++i) { @@ -357,24 +357,24 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ const size_t path_length = strlen(file->Path); tmp = BigEndian32((uint32_t)path_length + 1); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); - WriteAndSeek(&ptr, file->Path, path_length); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, file->Path, path_length); free(file->Path); tmp = BigEndian32((uint32_t)file->OriginalSize); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); tmp = BigEndian32((uint32_t)file->Size); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); tmp = BigEndian32((uint32_t)file->Offset); - WriteAndSeek(&ptr, &tmp, sizeof(tmp)); + Ham_WriteAndSeek(&ptr, &tmp, sizeof(tmp)); } for (size_t i = 0; i < num; ++i) { COMPRESSED_FILE *compressed_file = &compressed_files[i]; - WriteAndSeek(&ptr, compressed_file->Data, compressed_file->File.Size); + Ham_WriteAndSeek(&ptr, compressed_file->Data, compressed_file->File.Size); free(compressed_file->Data); } @@ -382,14 +382,14 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ bool ok = false; - FILE *handle = FileOpen(dst_path, true); + FILE *handle = Ham_FileOpen(dst_path, true); if (!handle) { fprintf(stderr, "HamcoreBuild(): Failed to open \"%s\"!\n", dst_path); goto FINAL; } - if (!FileWrite(handle, buffer, buffer_size)) + if (!Ham_FileWrite(handle, buffer, buffer_size)) { fprintf(stderr, "HamcoreBuild(): Failed to write \"%s\"!\n", dst_path); goto FINAL; @@ -397,7 +397,7 @@ bool HamcoreBuild(const char *dst_path, const char *base_path, const char **src_ ok = true; FINAL: - FileClose(handle); + Ham_FileClose(handle); free(buffer); return ok; } diff --git a/Memory.c b/Memory.c index 237efb9..c9a8a34 100644 --- a/Memory.c +++ b/Memory.c @@ -2,9 +2,7 @@ #include -size_t CompressionBufferSize(const size_t original_size) { return original_size * 2 + 256; } - -uint32_t Swap32(const uint32_t value) +uint32_t Ham_Swap32(const uint32_t value) { uint32_t swapped; ((uint8_t *)&swapped)[0] = ((uint8_t *)&value)[3]; @@ -14,7 +12,7 @@ uint32_t Swap32(const uint32_t value) return swapped; } -void WriteAndSeek(void **dst, const void *src, const size_t size) +void Ham_WriteAndSeek(void **dst, const void *src, const size_t size) { if (!dst || !*dst) { diff --git a/Memory.h b/Memory.h index f84e67c..02ec269 100644 --- a/Memory.h +++ b/Memory.h @@ -7,13 +7,13 @@ #ifdef BYTE_ORDER_BIG_ENDIAN #define BigEndian32 #else -#define BigEndian32 Swap32 +#define BigEndian32 Ham_Swap32 #endif -size_t CompressionBufferSize(const size_t original_size); +#define CompressionBufferSize(original_size) (original_size * 2 + 256) -uint32_t Swap32(const uint32_t value); +uint32_t Ham_Swap32(const uint32_t value); -void WriteAndSeek(void **dst, const void *src, const size_t size); +void Ham_WriteAndSeek(void **dst, const void *src, const size_t size); #endif -- cgit v1.2.3