6 #include "system/nth_alloc.h"
7 #include "system/stacktrace.h"
8 #include "lt_adapters.h"
16 struct dirent *dirent;
19 DIR *opendir(const char *dirpath)
21 trace_assert(dirpath);
23 char buffer[MAX_PATH];
24 snprintf(buffer, MAX_PATH, "%s\\*", dirpath);
26 DIR *dir = nth_calloc(1, sizeof(DIR));
28 dir->hFind = FindFirstFile(buffer, &dir->data);
29 if (dir->hFind == INVALID_HANDLE_VALUE) {
43 struct dirent *readdir(DIR *dirp)
47 if (dirp->dirent == NULL) {
48 dirp->dirent = nth_calloc(1, sizeof(struct dirent));
50 if(!FindNextFile(dirp->hFind, &dirp->data)) {
55 memset(dirp->dirent->d_name, 0, sizeof(dirp->dirent->d_name));
60 sizeof(dirp->dirent->d_name) - 1);
65 void closedir(DIR *dirp)
69 FindClose(dirp->hFind);
78 String read_whole_file(Memory *memory, const char *filepath)
80 trace_assert(filepath);
82 String result = string(0, NULL);
83 FILE *f = fopen(filepath, "rb");
85 if (fseek(f, 0, SEEK_END) < 0) goto end;
88 if (fseek(f, 0, SEEK_SET) < 0) goto end;
89 result.count = (size_t) m;
90 char *buffer = memory_alloc(memory, result.count);
91 size_t n = fread(buffer, 1, result.count, f);
92 trace_assert(n == result.count);