summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGary Lockyer <gary@catalyst.net.nz>2017-06-01 13:26:38 +1200
committerJeremy Allison <jra@samba.org>2017-06-13 18:38:14 +0200
commit378ae342c4e2e6b5bafbe54067d35344746be41b (patch)
treec6d07db14d53436d1adfd15e4ad61b04570d1855 /lib
parent40cc7a1eb339cf45d2b3e121832a89f61dd1776f (diff)
downloadsamba-378ae342c4e2e6b5bafbe54067d35344746be41b.tar.gz
strerror_r: provide XSI-compliant strerror_r
Provide a XSI-compliant strerror_r on GNU based systems. The default GNU strerror_r is not XSI-compliant, this patch wraps the GNU-specific call in an XSI-compliant wrapper. This reverts 18ed32ce0821d11c0c06d82c07ba1c27b0c2b886 which tried to make Heimdal use roken, rather than libreplace for strerror_r. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/replace/replace.c18
-rw-r--r--lib/replace/replace.h2
-rw-r--r--lib/replace/wscript7
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 = {