SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
Windows/dirent.c
1 #include <windows.h>
2 #include <stdio.h>
3 #include <winnls.h>
4 #include <io.h>
5 #include "dirent.h"
6
7 DIR *opendir(const char *filename)
8 {
9 wchar_t w_filename[MAX_PATH + 3] = {0,};
10 unsigned length = MultiByteToWideChar(CP_UTF8, 0, filename, -1, w_filename, MAX_PATH);
11 if (length) {
12 w_filename[length - 1] = L'/';
13 w_filename[length] = L'*';
14 w_filename[length + 1] = 0;
15 }
16 DIR *ret = malloc(sizeof(*ret));
17 ret->handle = FindFirstFileW(w_filename, &ret->entry);
18 if (ret->handle == INVALID_HANDLE_VALUE) {
19 free(ret);
20 return NULL;
21 }
22
23 return ret;
24 }
25
26 int closedir(DIR *dir)
27 {
28 if (dir->handle != INVALID_HANDLE_VALUE) {
29 FindClose(dir->handle);
30 }
31 free(dir);
32 return 0;
33 }
34
35 struct dirent *readdir(DIR *dir)
36 {
37 if (dir->handle == INVALID_HANDLE_VALUE) {
38 return NULL;
39 }
40
41 WideCharToMultiByte(CP_UTF8, 0, dir->entry.cFileName, -1,
42 dir->out_entry.d_name, sizeof(dir->out_entry.d_name),
43 NULL, NULL);
44
45 if (!FindNextFileW(dir->handle, &dir->entry)) {
46 FindClose(dir->handle);
47 dir->handle = INVALID_HANDLE_VALUE;
48 }
49
50 return &dir->out_entry;
51 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.