diff options
author | marc <> | 2002-11-21 20:45:05 +0000 |
---|---|---|
committer | marc <> | 2002-11-21 20:45:05 +0000 |
commit | a5b4134ef006a2be508ba3af1cfa90305c508e24 (patch) | |
tree | ed0b4084b8195b16382831ffc19e2cb68ba7588a /src | |
parent | 835bcf7be2030a2ecb03922fd3a821fe06474356 (diff) | |
download | openbsd-a5b4134ef006a2be508ba3af1cfa90305c508e24.tar.gz openbsd-a5b4134ef006a2be508ba3af1cfa90305c508e24.tar.bz2 openbsd-a5b4134ef006a2be508ba3af1cfa90305c508e24.zip |
Add strerror_r and functions versions of getchar_unlocked and
putchar_unlocked. Crank the minor on related libs. OK fgs@, deraadt@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/string/Makefile.inc | 4 | ||||
-rw-r--r-- | src/lib/libc/string/strerror.3 | 22 | ||||
-rw-r--r-- | src/lib/libc/string/strerror_r.c | 30 |
3 files changed, 53 insertions, 3 deletions
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index e7b81d0c43..3cd172287b 100644 --- a/src/lib/libc/string/Makefile.inc +++ b/src/lib/libc/string/Makefile.inc | |||
@@ -1,10 +1,10 @@ | |||
1 | # $OpenBSD: Makefile.inc,v 1.10 2001/09/05 16:27:01 mickey Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.11 2002/11/21 20:45:05 marc Exp $ |
2 | 2 | ||
3 | # string sources | 3 | # string sources |
4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string ${LIBCSRCDIR}/string | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string ${LIBCSRCDIR}/string |
5 | 5 | ||
6 | SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ | 6 | SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ |
7 | strlcat.c strmode.c strsignal.c strtok.c strxfrm.c \ | 7 | strerror_r.c strlcat.c strmode.c strsignal.c strtok.c strxfrm.c \ |
8 | __strerror.c __strsignal.c | 8 | __strerror.c __strsignal.c |
9 | 9 | ||
10 | # machine-dependent net sources | 10 | # machine-dependent net sources |
diff --git a/src/lib/libc/string/strerror.3 b/src/lib/libc/string/strerror.3 index 11bacd313e..05cb7e9d9c 100644 --- a/src/lib/libc/string/strerror.3 +++ b/src/lib/libc/string/strerror.3 | |||
@@ -33,7 +33,7 @@ | |||
33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
34 | .\" SUCH DAMAGE. | 34 | .\" SUCH DAMAGE. |
35 | .\" | 35 | .\" |
36 | .\" $OpenBSD: strerror.3,v 1.4 2000/10/23 19:14:41 aaron Exp $ | 36 | .\" $OpenBSD: strerror.3,v 1.5 2002/11/21 20:45:05 marc Exp $ |
37 | .\" | 37 | .\" |
38 | .Dd June 29, 1991 | 38 | .Dd June 29, 1991 |
39 | .Dt STRERROR 3 | 39 | .Dt STRERROR 3 |
@@ -45,6 +45,8 @@ | |||
45 | .Fd #include <string.h> | 45 | .Fd #include <string.h> |
46 | .Ft char * | 46 | .Ft char * |
47 | .Fn strerror "int errnum" | 47 | .Fn strerror "int errnum" |
48 | .Ft int | ||
49 | .Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen" | ||
48 | .Sh DESCRIPTION | 50 | .Sh DESCRIPTION |
49 | The | 51 | The |
50 | .Fn strerror | 52 | .Fn strerror |
@@ -58,6 +60,20 @@ characters, including the trailing NUL. | |||
58 | The array pointed to is not to be modified by the program, but may be | 60 | The array pointed to is not to be modified by the program, but may be |
59 | overwritten by subsequent calls to | 61 | overwritten by subsequent calls to |
60 | .Fn strerror . | 62 | .Fn strerror . |
63 | .Pp | ||
64 | .Fn strerror_r | ||
65 | is a thread safe version of | ||
66 | .Fn strerror | ||
67 | that places the error message in the given buffer | ||
68 | .Fa strerrbuf . | ||
69 | If the error message is larger then | ||
70 | .Fa buflen | ||
71 | the message will be truncated to fit within buflen and | ||
72 | .Er ERANGE | ||
73 | is returned. | ||
74 | .Fn strerror_r | ||
75 | returns zero upon successful completion. | ||
76 | An error number is returned, otherwise. | ||
61 | .Sh SEE ALSO | 77 | .Sh SEE ALSO |
62 | .Xr intro 2 , | 78 | .Xr intro 2 , |
63 | .Xr perror 3 , | 79 | .Xr perror 3 , |
@@ -67,3 +83,7 @@ The | |||
67 | .Fn strerror | 83 | .Fn strerror |
68 | function conforms to | 84 | function conforms to |
69 | .St -ansiC . | 85 | .St -ansiC . |
86 | The | ||
87 | .Fn strerror_r | ||
88 | function conforms to | ||
89 | .St -p1003.1 . | ||
diff --git a/src/lib/libc/string/strerror_r.c b/src/lib/libc/string/strerror_r.c new file mode 100644 index 0000000000..aab6db5303 --- /dev/null +++ b/src/lib/libc/string/strerror_r.c | |||
@@ -0,0 +1,30 @@ | |||
1 | /* $OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $ */ | ||
2 | /* Public Domain <marc@snafu.org> */ | ||
3 | |||
4 | #if defined(LIBC_SCCS) && !defined(lint) | ||
5 | static char *rcsid = "$OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $"; | ||
6 | #endif /* LIBC_SCCS and not lint */ | ||
7 | |||
8 | #include <errno.h> | ||
9 | #include <limits.h> | ||
10 | #include <string.h> | ||
11 | |||
12 | extern char *__strerror(int, char *); | ||
13 | |||
14 | int | ||
15 | strerror_r(int errnum, char *strerrbuf, size_t buflen) | ||
16 | { | ||
17 | int save_errno; | ||
18 | int ret_errno; | ||
19 | char buf[NL_TEXTMAX]; | ||
20 | |||
21 | save_errno = errno; | ||
22 | errno = 0; | ||
23 | __strerror(errnum, buf); | ||
24 | if (strlcpy(strerrbuf, buf, buflen) >= buflen) | ||
25 | errno = ERANGE; | ||
26 | ret_errno = errno; | ||
27 | errno = save_errno; | ||
28 | |||
29 | return (ret_errno); | ||
30 | } | ||