Mercurial
diff dowa/d_memory.c @ 64:a30944e5719e
Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Tue, 23 Dec 2025 15:18:46 -0800 |
| parents | 636eab07809d |
| children | ecb6ee6a22c3 |
line wrap: on
line diff
--- a/dowa/d_memory.c Tue Dec 23 14:00:37 2025 -0800 +++ b/dowa/d_memory.c Tue Dec 23 15:18:46 2025 -0800 @@ -474,6 +474,7 @@ printf("-----------\n"); } +#ifdef DIRECTORY int Dowa_HashMap_Cache_Folder(Dowa_PHashMap p_hash_map, const char *folder_path) { if (!p_hash_map || !folder_path) @@ -503,12 +504,12 @@ FILE *f = fopen(fullpath, "rb"); if (!f) { perror("fopen"); continue; } + // Allocate exact file size (no extra byte for null terminator) void *buf = p_hash_map->p_arena ? - Dowa_Arena_Allocate(p_hash_map->p_arena, size + 1) : - malloc(size + 1); + Dowa_Arena_Allocate(p_hash_map->p_arena, size) : + malloc(size); if (!buf) { perror("malloc"); fclose(f); closedir(dir); return -1; } - if (fread(buf, 1, size, f) != size) { perror("fread"); @@ -518,8 +519,8 @@ } fclose(f); - ((char *)buf)[size] = '\0'; - Dowa_HashMap_Push_Value_With_Type(p_hash_map, entry->d_name, buf, size + 1, DOWA_HASH_MAP_TYPE_STRING); + // Store file data as-is without null terminator (for binary files like images) + Dowa_HashMap_Push_Value_With_Type(p_hash_map, entry->d_name, buf, size, DOWA_HASH_MAP_TYPE_STRING); if (!p_hash_map->p_arena) Dowa_Free(buf); // Dowa_HashMap_PushValue made its own copy } @@ -550,3 +551,4 @@ closedir(dir); return 0; } +#endif