| 87 | } |
| 88 | |
| 89 | cbm_dirent_t *cbm_readdir(cbm_dir_t *d) { |
| 90 | if (!d || d->done) { |
| 91 | return NULL; |
| 92 | } |
| 93 | if (!d->first) { |
| 94 | if (!FindNextFileW(d->find_handle, &d->find_data)) { |
| 95 | d->done = true; |
| 96 | return NULL; |
| 97 | } |
| 98 | } |
| 99 | d->first = false; |
| 100 | |
| 101 | while (d->find_data.cFileName[0] == L'.' && |
| 102 | (d->find_data.cFileName[1] == L'\0' || |
| 103 | (d->find_data.cFileName[1] == L'.' && d->find_data.cFileName[2] == L'\0'))) { |
| 104 | if (!FindNextFileW(d->find_handle, &d->find_data)) { |
| 105 | d->done = true; |
| 106 | return NULL; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | char *u8 = cbm_wide_to_utf8(d->find_data.cFileName); |
| 111 | if (!u8) { |
| 112 | d->done = true; |
| 113 | return NULL; |
| 114 | } |
| 115 | size_t nlen = strlen(u8); |
| 116 | if (nlen >= CBM_DIRENT_NAME_MAX) { |
| 117 | nlen = CBM_DIRENT_NAME_MAX - SKIP_ONE; |
| 118 | } |
| 119 | memcpy(d->entry.name, u8, nlen); |
| 120 | d->entry.name[nlen] = '\0'; |
| 121 | free(u8); |
| 122 | d->entry.is_dir = (d->find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; |
| 123 | d->entry.d_type = 0; |
| 124 | return &d->entry; |
| 125 | } |
| 126 | |
| 127 | int cbm_path_info_utf8(const char *path, cbm_path_info_t *out) { |
| 128 | if (!path || !out) { |