diff options
author | mike <mike@FreeBSD.org> | 2003-01-03 16:44:42 +0000 |
---|---|---|
committer | mike <mike@FreeBSD.org> | 2003-01-03 16:44:42 +0000 |
commit | d6f399392ed34649b9bc2255c6744e3527ff9f71 (patch) | |
tree | dcc6f1181fe4e0351288beb4d4f7f4524488e537 /lib/libc/string/strerror.c | |
parent | b884c995dbabefd65829684e2d99e0d31d271447 (diff) | |
download | FreeBSD-src-d6f399392ed34649b9bc2255c6744e3527ff9f71.zip FreeBSD-src-d6f399392ed34649b9bc2255c6744e3527ff9f71.tar.gz |
Optimize errstr() by reducing the number of times it walks a string.
As a side effect, it makes the code easier to read and requires less
pointer arithmetic.
Test by: strerror regression test
Submitted by: Tim Kientzle <kientzle@acm.org>
Diffstat (limited to 'lib/libc/string/strerror.c')
-rw-r--r-- | lib/libc/string/strerror.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/libc/string/strerror.c b/lib/libc/string/strerror.c index 428ff38..02fba0c 100644 --- a/lib/libc/string/strerror.c +++ b/lib/libc/string/strerror.c @@ -57,22 +57,20 @@ __FBSDID("$FreeBSD$"); static void errstr(int num, char *buf, size_t len) { - char *p, *t; + char *t; unsigned int uerr; char tmp[EBUFSIZE]; - if (strlcpy(buf, UPREFIX, len) >= len) - return; - t = tmp; + t = tmp + sizeof(tmp); + *--t = '\0'; uerr = (num >= 0) ? num : -num; do { - *t++ = "0123456789"[uerr % 10]; + *--t = "0123456789"[uerr % 10]; } while (uerr /= 10); if (num < 0) - *t++ = '-'; - for (p = buf + sizeof(UPREFIX) - 1; t > tmp && p < buf + len - 1;) - *p++ = *--t; - *p = '\0'; + *--t = '-'; + strlcpy(buf, UPREFIX, len); + strlcat(buf, t, len); } int |