diff options
-rw-r--r-- | libhb/compat.c | 37 | ||||
-rw-r--r-- | libhb/compat.h | 10 |
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 |