summaryrefslogtreecommitdiff
path: root/src/util/file/file_stdio.c
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2026-09-05 19:18:44 -0400
committerAndrew Opalach <andrew@akon.city> 2026-09-05 19:18:44 -0400
commita27216c145b1b13ad863e49e5400778ad608640f (patch)
tree2531f2337c5a99af8c3f93676ddf0eb86e3715f4 /src/util/file/file_stdio.c
parent3a51988d764d54723288dc31a1779ece44cac1e9 (diff)
downloadlibnaunet-a27216c145b1b13ad863e49e5400778ad608640f.tar.gz
libnaunet-a27216c145b1b13ad863e49e5400778ad608640f.tar.bz2
libnaunet-a27216c145b1b13ad863e49e5400778ad608640f.zip
Fix Windows locale and error messages
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/util/file/file_stdio.c')
-rw-r--r--src/util/file/file_stdio.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/util/file/file_stdio.c b/src/util/file/file_stdio.c
index 5bdc7d9..6a30137 100644
--- a/src/util/file/file_stdio.c
+++ b/src/util/file/file_stdio.c
@@ -4,12 +4,27 @@
#ifdef NAUNET_ON_WINDOWS
#include "../../winwrap.h"
+#else
+#include <unistd.h>
#endif
#include "../error.h"
#include "file.h"
+static void check_error_description(s32 err)
+{
+#ifdef NAUNET_ON_WINDOWS
+ err = GetLastError();
+ char *strerror = nn_win32_error_message(err);
+ if (strerror) {
+ log_error("Error description: %s.", strerror);
+ }
+#else
+ log_error("Error description: %s.", nn_strerror(err));
+#endif
+}
+
static inline bool open_stdio_file(FILE **file, str *path, const char *mode)
{
char *c_str = al_str_to_c_str(path);
@@ -34,7 +49,8 @@ bool nn_file_open(struct nn_file *file, str *path, s32 flags)
{
const char *mode = (flags & NNWT_FILE_CREATE) ? "wb+" : "rb+";
if (!open_stdio_file(&file->file, path, mode)) {
- log_error("fopen(%.*s) failed (%d: %s).", al_str_x(path), errno, nn_strerror(errno));
+ log_error("fopen(%.*s) failed (%d).", al_str_x(path), errno);
+ check_error_description(errno);
return false;
}