From: Eric Biggers Date: Thu, 28 Mar 2013 01:23:00 +0000 (-0500) Subject: Replace _wcserror_s for Windows XP compatibility X-Git-Tag: v1.3.3~102 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=ad4f8818b728ef7cd1c5304bcd50a545df7acc8a;ds=sidebyside Replace _wcserror_s for Windows XP compatibility --- diff --git a/src/win32.c b/src/win32.c index 3dc20a94..7636c5fe 100644 --- a/src/win32.c +++ b/src/win32.c @@ -39,6 +39,7 @@ #include "lookup_table.h" #include "security.h" #include "endianness.h" +#include #include @@ -1534,4 +1535,20 @@ fail: return -1; } + +/* This really could be replaced with _wcserror_s, but this doesn't seem to + * actually be available in MSVCRT.DLL on Windows XP (perhaps it's statically + * linked in by Visual Studio...?). */ +extern int +win32_strerror_r_replacement(int errnum, wchar_t *buf, size_t buflen) +{ + static pthread_mutex_t strerror_lock = PTHREAD_MUTEX_INITIALIZER; + + pthread_mutex_lock(&strerror_lock); + mbstowcs(buf, strerror(errnum), buflen); + buf[buflen - 1] = '\0'; + pthread_mutex_unlock(&strerror_lock); + return 0; +} + #endif /* __WIN32__ */ diff --git a/src/win32.h b/src/win32.h index 82cdeef3..45909768 100644 --- a/src/win32.h +++ b/src/win32.h @@ -76,4 +76,7 @@ win32_global_init(); extern void win32_global_cleanup(); +extern int +win32_strerror_r_replacement(int errnum, tchar *buf, size_t buflen); + #endif /* _WIMLIB_WIN32_H */ diff --git a/wimlib_tchar.h b/wimlib_tchar.h index 4d722379..b27fbeab 100644 --- a/wimlib_tchar.h +++ b/wimlib_tchar.h @@ -53,7 +53,7 @@ typedef wchar_t tchar; * function defined ourselves. */ # define TSTRDUP WSTRDUP # define tmkdir(path, mode) _wmkdir(path) -# define tstrerror_r(errnum, buf, bufsize) _wcserror_s(buf, bufsize, errnum) +# define tstrerror_r win32_strerror_r_replacement # define trename win32_rename_replacement # define ttruncate win32_truncate_replacement #else /* __WIN32__ */