diff options
| author | espie <> | 2004-05-03 05:07:34 +0000 |
|---|---|---|
| committer | espie <> | 2004-05-03 05:07:34 +0000 |
| commit | 76aa3dd62e5e4b02cca65819f1c8d9938aec06fd (patch) | |
| tree | cc1b644adae829dec9c5b074cb0a9ba027eb4839 /src/lib/libc/string/strerror.c | |
| parent | 3b9905250348125fe22a21c5b8f4eb7ae5fbcded (diff) | |
| download | openbsd-76aa3dd62e5e4b02cca65819f1c8d9938aec06fd.tar.gz openbsd-76aa3dd62e5e4b02cca65819f1c8d9938aec06fd.tar.bz2 openbsd-76aa3dd62e5e4b02cca65819f1c8d9938aec06fd.zip | |
build the error message in strerror_r.c directly, avoiding one copy there.
handle a few subtle details caught by the regression tests: correct
termination, non copying if buffer length == 0, errno setting.
let all former users of __strerror go through strerror_r.
Work by Todd Miller and I. Okay millert@.
Diffstat (limited to 'src/lib/libc/string/strerror.c')
| -rw-r--r-- | src/lib/libc/string/strerror.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/src/lib/libc/string/strerror.c b/src/lib/libc/string/strerror.c index 6496f50afd..edb6af7386 100644 --- a/src/lib/libc/string/strerror.c +++ b/src/lib/libc/string/strerror.c | |||
| @@ -28,23 +28,17 @@ | |||
| 28 | */ | 28 | */ |
| 29 | 29 | ||
| 30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 31 | static char *rcsid = "$OpenBSD: strerror.c,v 1.5 2003/06/11 21:08:16 deraadt Exp $"; | 31 | static char *rcsid = "$OpenBSD: strerror.c,v 1.6 2004/05/03 05:07:34 espie Exp $"; |
| 32 | #endif /* LIBC_SCCS and not lint */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 33 | 33 | ||
| 34 | #include <string.h> | 34 | #include <string.h> |
| 35 | #include <limits.h> | 35 | #include <limits.h> |
| 36 | 36 | ||
| 37 | /* | ||
| 38 | * Since perror() is not allowed to change the contents of strerror()'s | ||
| 39 | * static buffer, both functions supply their own buffers to the | ||
| 40 | * internal function __strerror(). | ||
| 41 | */ | ||
| 42 | |||
| 43 | extern char *__strerror(int, char *); | ||
| 44 | |||
| 45 | char * | 37 | char * |
| 46 | strerror(int num) | 38 | strerror(int num) |
| 47 | { | 39 | { |
| 48 | static char buf[NL_TEXTMAX]; | 40 | static char buf[NL_TEXTMAX]; |
| 49 | return __strerror(num, buf); | 41 | |
| 42 | (void)strerror_r(num, buf, sizeof(buf)); | ||
| 43 | return (buf); | ||
| 50 | } | 44 | } |
