Skip to content

fix for #243#244

Open
Stemt wants to merge 6 commits into
tsoding:mainfrom
Stemt:main
Open

fix for #243#244
Stemt wants to merge 6 commits into
tsoding:mainfrom
Stemt:main

Conversation

@Stemt
Copy link
Copy Markdown

@Stemt Stemt commented May 18, 2026

I added:

  • The char utf8_name[MAX_PATH] buffer inside Nob_Dir_Entry.nob__private.

I changed:

  • FindFirstFile inside nob_dir_entry_open to FindFirstFileW.
  • FindNextFile inside nob_dir_entry_next to FindNextFileW.
  • WIN32_FIND_DATA inside Nob_Dir_Entry.nob__private to WIN32_FIND_DATAW.
  • GetCurrentDirectory inside nob_get_current_dir_temp with GetCurrentDirectoryW.

I tried to keep the memory allocation consistent with the previous behaviour.
So inside get_current_dir_temp() I use the temp allocator for a temporary utf16 buffer, but in the nob_dir_entry functions it uses a the new utf8_name buffer which takes the place of the WIN32_FIND_DATAA.cFileName buffer.

This has the disadvantage that valid file names might not fit inside this new buffer but I think this is a decent compromise as opposed to requiring the use of the temp allocator for example.

To validate that this works I wrote quick little test:

#if 0
cc -Wall -Wextra -Werror -g -o app main.c && ./app
exit 0
#endif

#define NOB_IMPLEMENTATION
#include "nob.h"

int main(void){
  nob_log(NOB_INFO, "current_dir: %s", nob_get_current_dir_temp());
  File_Paths paths = {0};
  assert(read_entire_dir(".", &paths));
  da_foreach(const char*, path, &paths){
    const unsigned char* p = (const unsigned char*) *path;
    fprintf(stderr, "%s", p);
    fprintf(stderr, "\n");
    while(*p != '\0'){
      fprintf(stderr, "%02X ", *p);
      p++;
    }
    fprintf(stderr, "\n");
  }
  return 0;
}

Here is the result before the change:

[INFO] current_dir: C:\msys64\tmp\test_path\t
.
2E
..
2E 2E
app.exe
61 70 70 2E 65 78 65
main.c
6D 61 69 6E 2E 63
nob.h
6E 6F 62 2E 68
t
74 EA 73 74

Here is the result after the change:

[INFO] current_dir: C:\msys64\tmp\test_path\têst
.
2E
..
2E 2E
app.exe
61 70 70 2E 65 78 65
main.c
6D 61 69 6E 2E 63
nob.h
6E 6F 62 2E 68
têst
74 C3 AA 73 74

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant