]> granicus.if.org Git - handbrake/commitdiff
libhb: add an implementation of strerror_r()
authorSean McGovern <gseanmcg@gmail.com>
Sun, 10 Jul 2016 21:22:45 +0000 (17:22 -0400)
committerSean McGovern <gseanmcg@gmail.com>
Tue, 12 Jul 2016 03:05:26 +0000 (23:05 -0400)
libhb/compat.c
libhb/compat.h

index 1ab3893e82ebd078492c0efff6aa5c8c56a4e5a6..449edff03fd38860076f59bb0499a22f060830bd 100644 (file)
@@ -40,3 +40,40 @@ char *strtok_r(char *s, const char *delim, char **save_ptr)
     return token;
 }
 #endif // HB_NEED_STRTOK_R
+
+#ifndef HAS_STRERROR_R
+#ifndef _GNU_SOURCE
+#include <sys/types.h>
+#include <errno.h>
+#include <string.h>
+
+#define ERRSTR_LEN 20
+
+int strerror_r(int errnum, char *strerrbuf, size_t buflen)
+{
+    int ret = 0;
+    char errstr[ERRSTR_LEN];
+
+    if (strerrbuf == NULL || buflen == 0)
+    {
+        ret = ERANGE;
+        goto done;
+    }
+
+    if(snprintf(errstr, ERRSTR_LEN - 1, "unknown error %d", errnum) < 0)
+    {
+        ret = EINVAL;
+        goto done;
+    }
+
+    if (snprintf(strerrbuf, buflen, errstr) < 0)
+    {
+        ret = EINVAL;
+        goto done;
+    }
+
+done:
+    return ret;
+}
+#endif // _GNU_SOURCE
+#endif // HAS_STRERROR_R
index 8c4ad58bf5903f53950d93438c28f3ef41168b76..618941e9e78cd74750cf193d67c035d88de73248 100644 (file)
 char *strtok_r(char *s, const char *delim, char **save_ptr);
 #endif // HB_NEED_STRTOK_R
 
+#ifndef HAS_STRERROR_R
+#ifndef _GNU_SOURCE
+#include <sys/types.h>
+/*
+ * POSIX definition of strerror_r() -- see http://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html
+ */
+int strerror_r(int errnum, char *strerrbuf, size_t buflen);
+#endif // _GNU_SOURCE
+#endif // HAVE_STRERROR_R
+
 #endif // HB_COMPAT_H