diff options
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/Makefile.inc | 6 | ||||
-rw-r--r-- | lib/libc/stdio/clrerr.c | 4 | ||||
-rw-r--r-- | lib/libc/stdio/flockfile.c | 49 | ||||
-rw-r--r-- | lib/libc/stdio/getc.c | 21 | ||||
-rw-r--r-- | lib/libc/stdio/putc.c | 27 |
5 files changed, 97 insertions, 10 deletions
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc index c83779e225e..18eb2722926 100644 --- a/lib/libc/stdio/Makefile.inc +++ b/lib/libc/stdio/Makefile.inc @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile.inc,v 1.7 1998/08/30 22:19:38 millert Exp $ +# $OpenBSD: Makefile.inc,v 1.8 1998/11/20 11:18:48 d Exp $ # stdio sources -.PATH: ${.CURDIR}/stdio +.PATH: ${LIBCSRCDIR}/stdio CFLAGS+=-DFLOATING_POINT @@ -14,7 +14,7 @@ SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \ scanf.c setbuf.c setbuffer.c setvbuf.c snprintf.c sprintf.c sscanf.c \ stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c vasprintf.c vfprintf.c \ vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c vsscanf.c \ - wbuf.c wsetup.c + wbuf.c wsetup.c flockfile.c MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fopen.3 fputs.3 \ fread.3 fseek.3 funopen.3 getc.3 mktemp.3 perror.3 printf.3 putc.3 \ diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c index 90de2ddaaca..1bd72b93fb5 100644 --- a/lib/libc/stdio/clrerr.c +++ b/lib/libc/stdio/clrerr.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: clrerr.c,v 1.2 1996/08/19 08:32:17 tholo Exp $"; +static char rcsid[] = "$OpenBSD: clrerr.c,v 1.3 1998/11/20 11:18:48 d Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> @@ -45,5 +45,7 @@ void clearerr(fp) FILE *fp; { + flockfile(fp); __sclearerr(fp); + funlockfile(fp); } diff --git a/lib/libc/stdio/flockfile.c b/lib/libc/stdio/flockfile.c new file mode 100644 index 00000000000..d720aee991a --- /dev/null +++ b/lib/libc/stdio/flockfile.c @@ -0,0 +1,49 @@ +/* $OpenBSD: flockfile.c,v 1.1 1998/11/20 11:18:48 d Exp $ */ + +#include <stdio.h> +#include "thread_private.h" + +#ifndef _THREAD_SAFE + +/* + * Subroutine versions of the macros in <stdio.h> + * Note that these are all no-ops because libc does not do threads. + */ + +#undef flockfile +#undef ftrylockfile +#undef funlockfile +#undef _flockfile_debug + +void +flockfile(fp) + FILE * fp; +{ +} + +int +ftrylockfile(fp) + FILE * fp; +{ + return 0; +} + +void +funlockfile(fp) + FILE * fp; +{ +} + +void +_flockfile_debug(fp, fname, lineno) + FILE * fp; + const char * fname; + int lineno; +{ +} + +#else /* _THREAD_SAFE */ + +/* Actual implementation of file locking in libc_r/uthread/uthread_file.c */ + +#endif /* _THREAD_SAFE */ diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c index ff4a5168a3f..ce990968202 100644 --- a/lib/libc/stdio/getc.c +++ b/lib/libc/stdio/getc.c @@ -35,12 +35,24 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getc.c,v 1.2 1996/08/19 08:32:51 tholo Exp $"; +static char rcsid[] = "$OpenBSD: getc.c,v 1.3 1998/11/20 11:18:48 d Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> /* + * A subroutine version of the macro getc_unlocked. + */ +#undef getc_unlocked + +int +getc_unlocked(fp) + FILE *fp; +{ + return (__sgetc(fp)); +} + +/* * A subroutine version of the macro getc. */ #undef getc @@ -49,5 +61,10 @@ int getc(fp) register FILE *fp; { - return (__sgetc(fp)); + int c; + + flockfile(fp); + c = __sgetc(fp); + funlockfile(fp); + return (c); } diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index b43af508a55..f9a23b2cd41 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: putc.c,v 1.3 1996/10/28 05:32:55 tholo Exp $"; +static char rcsid[] = "$OpenBSD: putc.c,v 1.4 1998/11/20 11:18:48 d Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> @@ -43,11 +43,12 @@ static char rcsid[] = "$OpenBSD: putc.c,v 1.3 1996/10/28 05:32:55 tholo Exp $"; #include "local.h" /* - * A subroutine version of the macro putc. + * A subroutine version of the macro putc_unlocked. */ -#undef putc +#undef putc_unlocked -putc(c, fp) +int +putc_unlocked(c, fp) int c; register FILE *fp; { @@ -57,3 +58,21 @@ putc(c, fp) } return (__sputc(c, fp)); } + +/* + * A subroutine version of the macro putc. + */ +#undef putc + +int +putc(c, fp) + int c; + FILE *fp; +{ + int ret; + + flockfile(fp); + ret = putc_unlocked(c, fp); + funlockfile(fp); + return (ret); +} |