diff options
Diffstat (limited to 'src/util/file/file_stdio.c')
| -rw-r--r-- | src/util/file/file_stdio.c | 18 |
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; } |