Skip to content

Conversation

@KillerxDBr
Copy link
Contributor

@KillerxDBr KillerxDBr commented Feb 19, 2025

  • Refactored "nob_win32_error_message" to not return NULL if snprintf fail for some reason, it will always return a string now.

  • Made a proper Windows API version of "nob_mkdir_if_not_exists".

  • Finished "nob_file_exists", now it returns -1 in case of error. ("distinguish between "does not exists" and other errors")

  • Added a ifdef to minirent static function declarations to avoid compiler warnings when using nob.h in header mode:

.\nob.h:586:13: warning: 'opendir' declared 'static' but never defined [-Wunused-function]
  586 | static DIR *opendir(const char *dirpath);
      |             ^~~~~~~

nob cant be compiled on Windows if UNICODE/_UNICODE macros are enable, so i changed all windows API calls and structs to the A version, there was some using the macro (E.g. "CopyFile" instead of "CopyFileA" or "CopyFileW") versions, that changed if those macros are defined.

E.g.

nob.h: In function 'nob_copy_file':
nob.h:720:19: error: passing argument 1 of 'CopyFileW' from incompatible pointer type [-Wincompatible-pointer-types]
  720 |     if (!CopyFile(src_path, dst_path, FALSE)) {
      |                   ^~~~~~~~
      |                   |
      |                   const char *
In file included from C:/msys64/ucrt64/include/windows.h:70,
                 from nob.h:197:
C:/msys64/ucrt64/include/winbase.h:2304:48: note: expected 'LPCWSTR' {aka 'const short unsigned int *'} but argument is of type 'const char *'
 2304 |   WINBASEAPI WINBOOL WINAPI CopyFileW (LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName, WINBOOL bFailIfExists);
  • Fix for "nob_read_entire_file" to be able to handle files larger than 2GB on Win32

@KillerxDBr KillerxDBr changed the title Improvements to nob_win32_error_message, nob_mkdir_if_not_exists, nob_file_exists, WinApi ANSI calls Fix errors when compiling with UNICODE macro, improvements to nob_win32_error_message, nob_mkdir_if_not_exists, nob_file_exists Mar 6, 2025
@KillerxDBr
Copy link
Contributor Author

I will refactor this one more time

@KillerxDBr KillerxDBr closed this May 19, 2025
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