Remove use of non-threadsafe strerror

Add helper class to use strerror_r or strerror_s
This commit is contained in:
Jonathan G Rennison
2024-06-10 18:18:18 +01:00
parent 81ba704477
commit 102ba8932e
5 changed files with 46 additions and 10 deletions

View File

@@ -306,4 +306,17 @@ inline bool IsWhitespace(char32_t c)
char *strcasestr(const char *haystack, const char *needle);
#endif /* strcasestr is available */
/**
* The use of a struct is so that when used as an argument to seprintf/etc, the buffer lives
* on the stack with a lifetime which lasts until the end of the statement.
* This avoids using a static buffer which is thread-unsafe, or needing to call malloc, which would then nee to be freed.
*/
struct StrErrorDumper {
const char *Get(int errornum);
const char *GetLast();
private:
char buf[128];
};
#endif /* STRING_FUNC_H */