Commit 449360d1 authored by rswindell's avatar rswindell
Browse files

Define a thread-safe/re-entrant version of strerror(): safe_strerror() which...

Define a thread-safe/re-entrant version of strerror(): safe_strerror() which is just thin wrapper around strerror_s on Windows and strerror_r elsewhere.
parent cb22c743
......@@ -866,3 +866,18 @@ BOOL DLLCALL terminate_pid(pid_t pid)
#endif
}
/****************************************************************************/
/* Re-entrant (thread-safe) version of strerror() */
/* GNU (not POSIX) inspired API */
/****************************************************************************/
char* safe_strerror(int errnum, char *buf, size_t buflen)
{
strlcpy(buf, "Unknown error", buflen);
#if defined(_WIN32)
strerror_s(buf, buflen, errnum);
#else
strerror_r(errnum, buf, buflen);
#endif
return buf;
}
......@@ -278,6 +278,9 @@ DLLEXPORT char* DLLCALL truncnl(char* str);
#define STRERROR(x) truncsp(strerror(x))
#endif
/* Re-entrant version of strerror() */
DLLEXPORT char* DLLCALL safe_strerror(int errnum, char* buf, size_t buflen);
/*********************/
/* Utility Functions */
/*********************/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment