summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/string/Makefile.inc4
-rw-r--r--src/lib/libc/string/strerror.322
-rw-r--r--src/lib/libc/string/strerror_r.c30
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
6SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ 6SRCS+= 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
49The 51The
50.Fn strerror 52.Fn strerror
@@ -58,6 +60,20 @@ characters, including the trailing NUL.
58The array pointed to is not to be modified by the program, but may be 60The array pointed to is not to be modified by the program, but may be
59overwritten by subsequent calls to 61overwritten by subsequent calls to
60.Fn strerror . 62.Fn strerror .
63.Pp
64.Fn strerror_r
65is a thread safe version of
66.Fn strerror
67that places the error message in the given buffer
68.Fa strerrbuf .
69If the error message is larger then
70.Fa buflen
71the message will be truncated to fit within buflen and
72.Er ERANGE
73is returned.
74.Fn strerror_r
75returns zero upon successful completion.
76An 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
68function conforms to 84function conforms to
69.St -ansiC . 85.St -ansiC .
86The
87.Fn strerror_r
88function 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)
5static 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
12extern char *__strerror(int, char *);
13
14int
15strerror_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}