summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-03-29 20:53:16 +1100
committerAndrew Tridgell <tridge@samba.org>2010-03-29 21:34:29 +1100
commit686221eae28ff58fb048fdc7132e1413dedb6eb9 (patch)
treef3eb5ae4c35dd18d1128fb8d7f87577562d7213c
parent7ed349caceed2524d897d957cee98ad1cdc4704c (diff)
downloadsamba-686221eae28ff58fb048fdc7132e1413dedb6eb9.tar.gz
samba-686221eae28ff58fb048fdc7132e1413dedb6eb9.tar.bz2
samba-686221eae28ff58fb048fdc7132e1413dedb6eb9.zip
s4-waf: use the libreplace strerror_r if needed
-rw-r--r--lib/replace/replace.c13
-rw-r--r--lib/replace/replace.h4
-rw-r--r--source4/heimdal_build/internal.mk1
-rw-r--r--source4/heimdal_build/roken.h9
4 files changed, 20 insertions, 7 deletions
diff --git a/lib/replace/replace.c b/lib/replace/replace.c
index 6a325400f4..12716ea6d3 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -748,10 +748,15 @@ char *rep_get_current_dir_name(void)
}
#endif
-#ifndef HAVE_STRERROR_R
-char *rep_strerror_r(int errnum, char *buf, size_t buflen)
+#if !defined(HAVE_STRERROR_R) || !defined(STRERROR_R_PROTO_COMPATIBLE)
+int rep_strerror_r(int errnum, char *buf, size_t buflen)
{
- strncpy(buf, strerror(errnum), buflen);
- return buf;
+ char *s = strerror(errnum);
+ if (strlen(s)+1 > buflen) {
+ errno = ERANGE;
+ return -1;
+ }
+ strncpy(buf, s, buflen);
+ return 0;
}
#endif
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index 9eb6604c96..7adc224bf2 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -512,9 +512,9 @@ 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_PROTO_COMPATIBLE)
#define strerror_r rep_strerror_r
-char *rep_strerror_r(int errnum, char *buf, size_t buflen);
+int rep_strerror_r(int errnum, char *buf, size_t buflen);
#endif
#ifdef HAVE_LIMITS_H
diff --git a/source4/heimdal_build/internal.mk b/source4/heimdal_build/internal.mk
index 6c6bfcec65..8b834ab525 100644
--- a/source4/heimdal_build/internal.mk
+++ b/source4/heimdal_build/internal.mk
@@ -640,7 +640,6 @@ HEIMDAL_ROKEN_OBJ_FILES = \
$(heimdalsrcdir)/lib/roken/erealloc.o \
$(heimdalsrcdir)/lib/roken/simple_exec.o \
$(heimdalsrcdir)/lib/roken/strcollect.o \
- $(heimdalsrcdir)/lib/roken/strerror_r.o \
$(heimdalsrcdir)/lib/roken/rtbl.o \
$(heimdalsrcdir)/lib/roken/cloexec.o \
$(heimdalsrcdir)/lib/roken/xfree.o \
diff --git a/source4/heimdal_build/roken.h b/source4/heimdal_build/roken.h
index c95e6dfaef..172dc76a29 100644
--- a/source4/heimdal_build/roken.h
+++ b/source4/heimdal_build/roken.h
@@ -111,6 +111,15 @@
#define HAVE_GETTIMEOFDAY
#endif
+/* force the use of the libreplace strerror_r */
+#ifndef HAVE_STRERROR_R
+#define HAVE_STRERROR_R
+#endif
+#ifndef STRERROR_R_PROTO_COMPATIBLE
+#define STRERROR_R_PROTO_COMPATIBLE
+#endif
+
+
/* we lie about having pidfile() so that NetBSD5 can compile. Nothing
in the parts of heimdal we use actually uses pidfile(), and we
don't use it in Samba, so this works, although its ugly */