summaryrefslogtreecommitdiff
path: root/lib/replace
diff options
context:
space:
mode:
Diffstat (limited to 'lib/replace')
-rw-r--r--lib/replace/replace.c13
-rw-r--r--lib/replace/replace.h4
2 files changed, 11 insertions, 6 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