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:
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 */