On Wed, 19 Oct 2016 09:11:36 -0600, "Todd C. Miller" wrote: > Currently, syslog_r() avoids using strerror() since it is not > reentrant. We have a reentrant strerror_r() so let's use it.
Since strerror_r() always fills in the buffer there is no need to check the return value. If saved_errno is not a valid error number, strerror_r() will use "Unknown error: %d". - todd Index: lib/libc/gen/syslog_r.c =================================================================== RCS file: /cvs/src/lib/libc/gen/syslog_r.c,v retrieving revision 1.15 diff -u -p -u -r1.15 syslog_r.c --- lib/libc/gen/syslog_r.c 27 Mar 2016 16:28:56 -0000 1.15 +++ lib/libc/gen/syslog_r.c 19 Oct 2016 15:48:41 -0000 @@ -138,18 +138,13 @@ __vsyslog_r(int pri, struct syslog_data } } - /* strerror() is not reentrant */ - for (t = fmt_cpy, fmt_left = FMT_LEN; (ch = *fmt); ++fmt) { if (ch == '%' && fmt[1] == 'm') { + char ebuf[NL_TEXTMAX]; + ++fmt; - if (reentrant) { - prlen = snprintf(t, fmt_left, "Error %d", - saved_errno); - } else { - prlen = snprintf(t, fmt_left, "%s", - strerror(saved_errno)); - } + (void)strerror_r(saved_errno, ebuf, sizeof(ebuf)); + prlen = snprintf(t, fmt_left, "%s", ebuf); if (prlen < 0) prlen = 0; if (prlen >= fmt_left)