aboutsummaryrefslogtreecommitdiffstats
path: root/src/system.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-09 22:29:55 -0400
committerDavid Robillard <d@drobilla.net>2022-01-13 23:03:49 -0500
commitcc03e614b22b5695a1bbe0bedebd1bf0cf284bf7 (patch)
treee77be535c4dae3c9edade87492e0d0a297d62c9a /src/system.c
parentbf4f881c2241fa8ae6459bd9c8ee6cc83ee563a9 (diff)
downloadserd-cc03e614b22b5695a1bbe0bedebd1bf0cf284bf7.tar.gz
serd-cc03e614b22b5695a1bbe0bedebd1bf0cf284bf7.tar.bz2
serd-cc03e614b22b5695a1bbe0bedebd1bf0cf284bf7.zip
Use thread-safe strerror_r() if available
Diffstat (limited to 'src/system.c')
-rw-r--r--src/system.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/system.c b/src/system.c
index 76a39ad2..4a70c204 100644
--- a/src/system.c
+++ b/src/system.c
@@ -27,6 +27,20 @@
#include <stdlib.h>
#include <string.h>
+int
+serd_system_strerror(const int errnum, char* const buf, const size_t buflen)
+{
+#if USE_STRERROR_R
+ return strerror_r(errnum, buf, buflen);
+
+#else // Not thread-safe, but... oh well?
+ const char* const message = strerror(errnum);
+
+ strncpy(buf, message, buflen);
+ return 0;
+#endif
+}
+
void*
serd_malloc_aligned(const size_t alignment, const size_t size)
{