From 4dc0c0c4e5f76c22b39976dd381e04699ab0f09d Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Wed, 14 Jun 2006 20:49:11 +0000 Subject: 2006-06-14 Jeff Johnston * libc/include/stdio.h: Add new reentrant I/O prototypes for read/write functions. Change getc/putc macros to have reentrant underlying macros/functions. This includes __sgetc_raw_r, __sgetc_r, and __sputc_r. * libc/stdio/fgetc.c: Fix and/or add reentrant version to call new reentrant I/O functions/macros for reading/writing. * libc/stdio/fgets.c: Ditto. * libc/stdio/fputc.c: Ditto. * libc/stdio/fputs.c: Ditto. * libc/stdio/fread.c: Ditto. * libc/stdio/fseek.c: Ditto. * libc/stdio64/fseeko64.c: Ditto. * libc/stdio/fwrite.c: Ditto. * libc/stdio/getc.c: Ditto. * libc/stdio/getc_u.c: Ditto. * libc/stdio/getchar.c: Ditto. * libc/stdio/getchar_u.c: Ditto. * libc/stdio/putc.c: Ditto. * libc/stdio/putc_u.c: Ditto. * libc/stdio/putchar.c: Ditto. * libc/stdio/puts.c: Ditto. * libc/stdio/vfprintf.c: Ditto. * libc/stdio/vfscanf.c: Ditto. * libc/stdio/fvwrite.c: Change __sfvwrite into reentrant __sfvwrite_r. Change all previous callers of __sfvwrite. Set errno to EBADF and set error flag on if attempt is made to write to file that does not allow writing. * libc/stdio/fvwrite.h: Fix new reentrant prototypes. * libc/stdio/local.h: Ditto. * libc/stdio/refill.c: Turn __srefill into reentrant __srefill_r. Set errno to EBADF and the error flag on if attempt is made to read unreadable file. Change all previous callers of __srefill. * libc/stdio/rget.c * libc/stdio/wbuf.c: Turn __swbuf into reentrant __swbuf_r. Change all previous callers of __swbuf. * libc/sys/linux/machine/i386/huge_val.h: Ifdef out file contents since huge value macros are already defined correctly for i386 by . --- newlib/libc/stdio/fgets.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'newlib/libc/stdio/fgets.c') diff --git a/newlib/libc/stdio/fgets.c b/newlib/libc/stdio/fgets.c index f5dde4903..741618705 100644 --- a/newlib/libc/stdio/fgets.c +++ b/newlib/libc/stdio/fgets.c @@ -21,11 +21,16 @@ FUNCTION INDEX fgets +INDEX + _fgets_r ANSI_SYNOPSIS #include char *fgets(char *<[buf]>, int <[n]>, FILE *<[fp]>); + #include + char *_fgets_r(struct _reent *<[ptr]>, char *<[buf]>, int <[n]>, FILE *<[fp]>); + TRAD_SYNOPSIS #include char *fgets(<[buf]>,<[n]>,<[fp]>) @@ -33,11 +38,21 @@ TRAD_SYNOPSIS int <[n]>; FILE *<[fp]>; + #include + char *_fgets_r(<[ptr]>, <[buf]>,<[n]>,<[fp]>) + struct _reent *<[ptr]>; + char *<[buf]>; + int <[n]>; + FILE *<[fp]>; + DESCRIPTION Reads at most <[n-1]> characters from <[fp]> until a newline is found. The characters including to the newline are stored in <[buf]>. The buffer is terminated with a 0. + The <<_fgets_r>> function is simply the reentrant version of + <> and is passed an additional reentrancy structure + pointer: <[ptr]>. RETURNS <> returns the buffer passed to it, with the data @@ -66,7 +81,8 @@ Supporting OS subroutines required: <>, <>, <>, */ char * -_DEFUN(fgets, (buf, n, fp), +_DEFUN(_fgets_r, (ptr, buf, n, fp), + struct _reent * ptr _AND char *buf _AND int n _AND FILE * fp) @@ -80,7 +96,7 @@ _DEFUN(fgets, (buf, n, fp), s = buf; - CHECK_INIT(_REENT); + CHECK_INIT(ptr); _flockfile (fp); #ifdef __SCLE @@ -88,7 +104,7 @@ _DEFUN(fgets, (buf, n, fp), { int c; /* Sorry, have to do it the slow way */ - while (--n > 0 && (c = __sgetc (fp)) != EOF) + while (--n > 0 && (c = __sgetc_r (ptr, fp)) != EOF) { *s++ = c; if (c == '\n') @@ -113,7 +129,7 @@ _DEFUN(fgets, (buf, n, fp), */ if ((len = fp->_r) <= 0) { - if (__srefill (fp)) + if (__srefill_r (ptr, fp)) { /* EOF: stop with partial or no line */ if (s == buf) @@ -156,3 +172,16 @@ _DEFUN(fgets, (buf, n, fp), _funlockfile (fp); return buf; } + +#ifndef _REENT_ONLY + +char * +_DEFUN(fgets, (buf, n, fp), + char *buf _AND + int n _AND + FILE * fp) +{ + return _fgets_r (_REENT, buf, n, fp); +} + +#endif /* !_REENT_ONLY */ -- cgit v1.2.3