summaryrefslogtreecommitdiffstats
path: root/libhb
diff options
context:
space:
mode:
authorSean McGovern <[email protected]>2016-07-10 17:22:45 -0400
committerSean McGovern <[email protected]>2016-07-11 23:05:26 -0400
commitb8bf66f0b15842ce240a3320ca4d23aaf8165bf0 (patch)
tree821b07cb5f004b89cc8614c7f9073bf69a6b35dd /libhb
parente44e48382e1a97815f005e3efd6c36c06c773c40 (diff)
libhb: add an implementation of strerror_r()
Diffstat (limited to 'libhb')
-rw-r--r--libhb/compat.c37
-rw-r--r--libhb/compat.h10
2 files changed, 47 insertions, 0 deletions
diff --git a/libhb/compat.c b/libhb/compat.c
index 1ab3893e8..449edff03 100644
--- a/libhb/compat.c
+++ b/libhb/compat.c
@@ -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
diff --git a/libhb/compat.h b/libhb/compat.h
index 8c4ad58bf..618941e9e 100644
--- a/libhb/compat.h
+++ b/libhb/compat.h
@@ -25,4 +25,14 @@
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