summaryrefslogtreecommitdiffstats
path: root/libhb/compat.c
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/compat.c
parente44e48382e1a97815f005e3efd6c36c06c773c40 (diff)
libhb: add an implementation of strerror_r()
Diffstat (limited to 'libhb/compat.c')
-rw-r--r--libhb/compat.c37
1 files changed, 37 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