diff options
-rw-r--r-- | lib/libc/shlib_version | 2 | ||||
-rw-r--r-- | lib/libc/stdio/getchar.c | 17 | ||||
-rw-r--r-- | lib/libc/stdio/putchar.c | 19 | ||||
-rw-r--r-- | lib/libc/string/Makefile.inc | 4 | ||||
-rw-r--r-- | lib/libc/string/strerror.3 | 22 | ||||
-rw-r--r-- | lib/libc/string/strerror_r.c | 30 | ||||
-rw-r--r-- | lib/libc_r/shlib_version | 2 | ||||
-rw-r--r-- | lib/libpthread/shlib_version | 2 |
8 files changed, 87 insertions, 11 deletions
diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index f9e1eb4296a..59ded4be242 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,2 +1,2 @@ major=28 -minor=7 # note: remember to update minor in ../libc_r/shlib_version +minor=8 # note: remember to update minor in ../libc_r/shlib_version diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c index 029f19f94fd..4590d1abd29 100644 --- a/lib/libc/stdio/getchar.c +++ b/lib/libc/stdio/getchar.c @@ -35,13 +35,26 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getchar.c,v 1.3 2001/07/09 06:57:44 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: getchar.c,v 1.4 2002/11/21 20:45:05 marc Exp $"; #endif /* LIBC_SCCS and not lint */ +#include <stdio.h> + +/* + * A subroutine version of the macro getchar_unlocked. + */ +#undef getchar_unlocked + +int +getchar_unlocked() +{ + return (getc_unlocked(stdin)); +} + + /* * A subroutine version of the macro getchar. */ -#include <stdio.h> #undef getchar diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index 22aa47aaefb..47480d494f3 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -35,11 +35,24 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: putchar.c,v 1.3 2001/07/09 06:57:44 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: putchar.c,v 1.4 2002/11/21 20:45:05 marc Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +#undef putchar_unlocked +/* + * A subrouting version of the macro putchar_unlocked + */ +int +putchar_unlocked(c) + int c; +{ + FILE *so = stdout; + + return (putc_unlocked(c,so)); +} + #undef putchar /* @@ -49,7 +62,7 @@ int putchar(c) int c; { - register FILE *so = stdout; + FILE *so = stdout; - return (__sputc(c, so)); + return (putc(c, so)); } diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index e7b81d0c43f..3cd172287b7 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile.inc,v 1.10 2001/09/05 16:27:01 mickey Exp $ +# $OpenBSD: Makefile.inc,v 1.11 2002/11/21 20:45:05 marc Exp $ # string sources .PATH: ${LIBCSRCDIR}/arch/${MACHINE_ARCH}/string ${LIBCSRCDIR}/string SRCS+= bm.c memccpy.c strcasecmp.c strcoll.c strdup.c strerror.c \ - strlcat.c strmode.c strsignal.c strtok.c strxfrm.c \ + strerror_r.c strlcat.c strmode.c strsignal.c strtok.c strxfrm.c \ __strerror.c __strsignal.c # machine-dependent net sources diff --git a/lib/libc/string/strerror.3 b/lib/libc/string/strerror.3 index 11bacd313e9..05cb7e9d9c9 100644 --- a/lib/libc/string/strerror.3 +++ b/lib/libc/string/strerror.3 @@ -33,7 +33,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: strerror.3,v 1.4 2000/10/23 19:14:41 aaron Exp $ +.\" $OpenBSD: strerror.3,v 1.5 2002/11/21 20:45:05 marc Exp $ .\" .Dd June 29, 1991 .Dt STRERROR 3 @@ -45,6 +45,8 @@ .Fd #include <string.h> .Ft char * .Fn strerror "int errnum" +.Ft int +.Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen" .Sh DESCRIPTION The .Fn strerror @@ -58,6 +60,20 @@ characters, including the trailing NUL. The array pointed to is not to be modified by the program, but may be overwritten by subsequent calls to .Fn strerror . +.Pp +.Fn strerror_r +is a thread safe version of +.Fn strerror +that places the error message in the given buffer +.Fa strerrbuf . +If the error message is larger then +.Fa buflen +the message will be truncated to fit within buflen and +.Er ERANGE +is returned. +.Fn strerror_r +returns zero upon successful completion. +An error number is returned, otherwise. .Sh SEE ALSO .Xr intro 2 , .Xr perror 3 , @@ -67,3 +83,7 @@ The .Fn strerror function conforms to .St -ansiC . +The +.Fn strerror_r +function conforms to +.St -p1003.1 . diff --git a/lib/libc/string/strerror_r.c b/lib/libc/string/strerror_r.c new file mode 100644 index 00000000000..aab6db5303c --- /dev/null +++ b/lib/libc/string/strerror_r.c @@ -0,0 +1,30 @@ +/* $OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $ */ +/* Public Domain <marc@snafu.org> */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strerror_r.c,v 1.1 2002/11/21 20:45:05 marc Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include <errno.h> +#include <limits.h> +#include <string.h> + +extern char *__strerror(int, char *); + +int +strerror_r(int errnum, char *strerrbuf, size_t buflen) +{ + int save_errno; + int ret_errno; + char buf[NL_TEXTMAX]; + + save_errno = errno; + errno = 0; + __strerror(errnum, buf); + if (strlcpy(strerrbuf, buf, buflen) >= buflen) + errno = ERANGE; + ret_errno = errno; + errno = save_errno; + + return (ret_errno); +} diff --git a/lib/libc_r/shlib_version b/lib/libc_r/shlib_version index a805acda7f7..e29c46e3713 100644 --- a/lib/libc_r/shlib_version +++ b/lib/libc_r/shlib_version @@ -1,2 +1,2 @@ major=6 -minor=7 +minor=8 diff --git a/lib/libpthread/shlib_version b/lib/libpthread/shlib_version index b49665a51a9..3468ab48289 100644 --- a/lib/libpthread/shlib_version +++ b/lib/libpthread/shlib_version @@ -1,2 +1,2 @@ major=0 -minor=7 +minor=8 |