From f67c7e2560b78ee550b7432f3ea9066620f8b66a Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Sat, 27 Aug 2005 21:35:01 +0000 Subject: [PATCH] Add real function versions of the _unlocked family. Use putc for putchar directly. --- include/stdio.h | 9 ++++++++- lib/libc/stdio/feof.c | 12 +++++++++--- lib/libc/stdio/ferror.c | 12 +++++++++--- lib/libc/stdio/fileno.c | 14 ++++++++++---- lib/libc/stdio/getc.c | 10 +++++++++- lib/libc/stdio/getchar.c | 18 ++++++++++-------- lib/libc/stdio/putc.c | 11 ++++++++--- lib/libc/stdio/putchar.c | 21 +++++++++++---------- 8 files changed, 74 insertions(+), 33 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index bfaec3c642..1c7ea505f1 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -35,7 +35,7 @@ * * @(#)stdio.h 8.5 (Berkeley) 4/29/95 * $FreeBSD: src/include/stdio.h,v 1.24.2.5 2002/11/09 08:07:20 imp Exp $ - * $DragonFly: src/include/stdio.h,v 1.10 2005/08/27 21:32:24 joerg Exp $ + * $DragonFly: src/include/stdio.h,v 1.11 2005/08/27 21:35:01 joerg Exp $ */ #ifndef _STDIO_H_ @@ -165,7 +165,9 @@ __BEGIN_DECLS void clearerr(FILE *); int fclose(FILE *); int feof(FILE *); +int feof_unlocked(FILE *); int ferror(FILE *); +int ferror_unlocked(FILE *); int fflush(FILE *); int fgetc(FILE *); int fgetpos(FILE *, fpos_t *); @@ -182,7 +184,9 @@ int fsetpos(FILE *, const fpos_t *); long ftell(FILE *); size_t fwrite(const void *, size_t, size_t, FILE *); int getc(FILE *); +int getc_unlocked(FILE *); int getchar(void); +int getchar_unlocked(void); char *gets(char *); #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE) extern __const int sys_nerr; /* perror(3) external variables */ @@ -191,7 +195,9 @@ extern __const char *__const sys_errlist[]; void perror(const char *); int printf(const char *, ...); int putc(int, FILE *); +int putc_unlocked(int, FILE *); int putchar(int); +int putchar_unlocked(int); int puts(const char *); int remove(const char *); int rename(const char *, const char *); @@ -222,6 +228,7 @@ __BEGIN_DECLS char *ctermid(char *); FILE *fdopen(int, const char *); int fileno(FILE *); +int fileno_unlocked(FILE *); int ftrylockfile(FILE *); void flockfile(FILE *); void funlockfile(FILE *); diff --git a/lib/libc/stdio/feof.c b/lib/libc/stdio/feof.c index e5c7703ae9..7ad9c2cb01 100644 --- a/lib/libc/stdio/feof.c +++ b/lib/libc/stdio/feof.c @@ -35,19 +35,25 @@ * * @(#)feof.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/feof.c,v 1.6 1999/08/28 00:00:57 peter Exp $ - * $DragonFly: src/lib/libc/stdio/feof.c,v 1.5 2004/06/09 23:35:45 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/feof.c,v 1.6 2005/08/27 21:35:01 joerg Exp $ */ #include #include "libc_private.h" /* - * A subroutine version of the macro feof. + * A subroutine version of the macros feof and feof_unlocked. */ -#undef feof +#undef feof_unlocked int feof(FILE *fp) { return(__sfeof(fp)); } + +int +feof_unlocked(FILE *fp) +{ + return(__sfeof(fp)); +} diff --git a/lib/libc/stdio/ferror.c b/lib/libc/stdio/ferror.c index dc5a011b5a..981b23ddad 100644 --- a/lib/libc/stdio/ferror.c +++ b/lib/libc/stdio/ferror.c @@ -35,18 +35,24 @@ * * @(#)ferror.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/ferror.c,v 1.6 1999/08/28 00:00:57 peter Exp $ - * $DragonFly: src/lib/libc/stdio/ferror.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/ferror.c,v 1.4 2005/08/27 21:35:01 joerg Exp $ */ #include /* - * A subroutine version of the macro ferror. + * A subroutine version of the macros ferror and ferror_unlocked. */ -#undef ferror +#undef ferror_unlocked int ferror(FILE *fp) { return (__sferror(fp)); } + +int +ferror_unlocked(FILE *fp) +{ + return (__sferror(fp)); +} diff --git a/lib/libc/stdio/fileno.c b/lib/libc/stdio/fileno.c index 51a65a62ec..f755bff5e1 100644 --- a/lib/libc/stdio/fileno.c +++ b/lib/libc/stdio/fileno.c @@ -35,7 +35,7 @@ * * @(#)fileno.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fileno.c,v 1.6 1999/08/28 00:01:01 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fileno.c,v 1.5 2005/07/23 20:23:05 joerg Exp $ + * $DragonFly: src/lib/libc/stdio/fileno.c,v 1.6 2005/08/27 21:35:01 joerg Exp $ */ #include "namespace.h" @@ -44,11 +44,11 @@ #include "libc_private.h" +#undef fileno_unlocked + /* - * A subroutine version of the macro fileno. + * A subroutine version of the macros fileno and fileno_unlocked. */ -#undef fileno - int fileno(FILE *fp) { @@ -60,3 +60,9 @@ fileno(FILE *fp) return (fd); } + +int +fileno_unlocked(FILE *fp) +{ + return(__sfileno(fp)); +} diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c index a724c6b9b2..e2853b3249 100644 --- a/lib/libc/stdio/getc.c +++ b/lib/libc/stdio/getc.c @@ -35,7 +35,7 @@ * * @(#)getc.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/getc.c,v 1.7.2.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/getc.c,v 1.3 2005/01/31 22:29:40 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/getc.c,v 1.4 2005/08/27 21:35:01 joerg Exp $ */ #include "namespace.h" @@ -43,6 +43,8 @@ #include "un-namespace.h" #include "libc_private.h" +#undef getc_unlocked + int getc(FILE *fp) { @@ -52,3 +54,9 @@ getc(FILE *fp) FUNLOCKFILE(fp); return (retval); } + +int +getc_unlocked(FILE *fp) +{ + return(__sgetc(fp)); +} diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c index 6c1a3021c3..3d03ff5acb 100644 --- a/lib/libc/stdio/getchar.c +++ b/lib/libc/stdio/getchar.c @@ -35,25 +35,27 @@ * * @(#)getchar.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/getchar.c,v 1.7 1999/08/28 00:01:09 peter Exp $ - * $DragonFly: src/lib/libc/stdio/getchar.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/getchar.c,v 1.5 2005/08/27 21:35:01 joerg Exp $ */ /* - * A subroutine version of the macro getchar. + * A subroutine version of the macros getchar and getchar_unlocked. */ #include "namespace.h" #include #include "un-namespace.h" #include "libc_private.h" -#undef getchar +#undef getchar_unlocked int getchar(void) { - int retval; - FLOCKFILE(stdin); - retval = getc(stdin); - FUNLOCKFILE(stdin); - return (retval); + return(getc(stdin)); +} + +int +getchar_unlocked(void) +{ + return(getc_unlocked(stdin)); } diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index 261387902e..af5049f3e6 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -35,7 +35,7 @@ * * @(#)putc.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/putc.c,v 1.7 1999/08/28 00:01:12 peter Exp $ - * $DragonFly: src/lib/libc/stdio/putc.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/putc.c,v 1.6 2005/08/27 21:35:01 joerg Exp $ */ #include "namespace.h" @@ -43,13 +43,13 @@ #include "un-namespace.h" #include "libc_private.h" +#undef putc_unlocked + /* * putc has traditionally been a macro in . That is no * longer true because POSIX requires it to be thread-safe. POSIX * does define putc_unlocked() which is defined as a macro and is * probably what you want to use instead. - * - * #undef putc */ int putc(int c, FILE *fp) @@ -60,3 +60,8 @@ putc(int c, FILE *fp) FUNLOCKFILE(fp); return (retval); } + +int putc_unlocked(int c, FILE *fp) +{ + return(__sputc(c, fp)); +} diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index 0c85aad919..aa84b08105 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -35,7 +35,7 @@ * * @(#)putchar.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/putchar.c,v 1.7 1999/08/28 00:01:12 peter Exp $ - * $DragonFly: src/lib/libc/stdio/putchar.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/putchar.c,v 1.6 2005/08/27 21:35:01 joerg Exp $ */ #include "namespace.h" @@ -43,25 +43,26 @@ #include "un-namespace.h" #include "libc_private.h" +#undef putchar_unlocked + /* * putchar has traditionally been a macro in . That is no * longer true because POSIX requires it to be thread-safe. POSIX * does define putchar_unlocked() which is defined as a macro and is * probably what you want to use instead. - * - * #undef putchar */ + /* - * A subroutine version of the macro putchar + * A subroutine version of the macros putchar and putchar_unlocked. */ int putchar(int c) { - int retval; - FILE *so = stdout; + return(putc(c, stdout)); +} - FLOCKFILE(so); - retval = __sputc(c, so); - FUNLOCKFILE(so); - return (retval); +int +putchar_unlocked(int c) +{ + return(putc_unlocked(c, stdout)); } -- 2.11.4.GIT