diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/replace/replace.c | 18 | ||||
-rw-r--r-- | lib/replace/replace.h | 2 | ||||
-rw-r--r-- | lib/replace/wscript | 7 |
3 files changed, 26 insertions, 1 deletions
diff --git a/lib/replace/replace.c b/lib/replace/replace.c index b5d7f117857..9351b6c94e3 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -820,6 +820,24 @@ int rep_strerror_r(int errnum, char *buf, size_t buflen) strncpy(buf, s, buflen); return 0; } +#elif (!defined(STRERROR_R_XSI_NOT_GNU)) +#undef strerror_r +int rep_strerror_r(int errnum, char *buf, size_t buflen) +{ + char *s = strerror_r(errnum, buf, buflen); + if (s == NULL) { + /* Shouldn't happen, should always get a string */ + return EINVAL; + } + if (s != buf) { + strlcpy(buf, s, buflen); + if (strlen(s) > buflen - 1) { + return ERANGE; + } + } + return 0; + +} #endif #ifndef HAVE_CLOCK_GETTIME diff --git a/lib/replace/replace.h b/lib/replace/replace.h index 1dbeacfff66..a41e9f89d20 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -628,7 +628,7 @@ ssize_t rep_pwrite(int __fd, const void *__buf, size_t __nbytes, off_t __offset) char *rep_get_current_dir_name(void); #endif -#ifndef HAVE_STRERROR_R +#if (!defined(HAVE_STRERROR_R) || !defined(STRERROR_R_XSI_NOT_GNU)) #define strerror_r rep_strerror_r int rep_strerror_r(int errnum, char *buf, size_t buflen); #endif diff --git a/lib/replace/wscript b/lib/replace/wscript index eeb1b3ebcf0..33f49eb5aa8 100644 --- a/lib/replace/wscript +++ b/lib/replace/wscript @@ -627,6 +627,13 @@ removeea setea conf.RECURSE('system') conf.SAMBA_CONFIG_H() + if conf.CHECK_FUNCS('strerror_r'): + # Check if strerror_r is XSI-Compatable, the default GNU implementation + # is not + conf.CHECK_CODE('int strerror_r(int errnum, char *buf, size_t buflen);', + 'STRERROR_R_XSI_NOT_GNU', + headers='string.h', addmain=False, link=False, + msg="Checking for XSI (rather than GNU) prototype for strerror_r") REPLACEMENT_FUNCTIONS = { |