Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2006-06-15 00:49:11 +0400
committerJeff Johnston <jjohnstn@redhat.com>2006-06-15 00:49:11 +0400
commit4dc0c0c4e5f76c22b39976dd381e04699ab0f09d (patch)
treec3ac4ca00812cff8cbdaf27f698768a73f922ffb /newlib/libc/stdio/fgets.c
parent1b9cba59c38702b6bcdec116591d3c7191ea7ad7 (diff)
2006-06-14 Jeff Johnston <jjohnstn@redhat.com>
* 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 <math.h>.
Diffstat (limited to 'newlib/libc/stdio/fgets.c')
-rw-r--r--newlib/libc/stdio/fgets.c37
1 files changed, 33 insertions, 4 deletions
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 <stdio.h>
char *fgets(char *<[buf]>, int <[n]>, FILE *<[fp]>);
+ #include <stdio.h>
+ char *_fgets_r(struct _reent *<[ptr]>, char *<[buf]>, int <[n]>, FILE *<[fp]>);
+
TRAD_SYNOPSIS
#include <stdio.h>
char *fgets(<[buf]>,<[n]>,<[fp]>)
@@ -33,11 +38,21 @@ TRAD_SYNOPSIS
int <[n]>;
FILE *<[fp]>;
+ #include <stdio.h>
+ 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
+ <<fgets>> and is passed an additional reentrancy structure
+ pointer: <[ptr]>.
RETURNS
<<fgets>> returns the buffer passed to it, with the data
@@ -66,7 +81,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
*/
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 */