update mappings to reflect recent changes
[AROS.git] / compiler / clib / fgets.c
blob473a0b6686e10beb6840a87fcf912d30ba3242de
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function fgets().
6 */
8 #include <errno.h>
9 #include <dos/dos.h>
10 #include <dos/dosextens.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include "__fdesc.h"
14 #include "__stdio.h"
16 /*****************************************************************************
18 NAME */
19 #include <stdio.h>
21 char * fgets (
23 /* SYNOPSIS */
24 char * buffer,
25 int size,
26 FILE * stream)
28 /* FUNCTION
29 Read one line of characters from the stream into the buffer.
30 Reading will stop, when a newline ('\n') is encountered, EOF
31 or when the buffer is full. If a newline is read, then it is
32 put into the buffer. The last character in the buffer is always
33 '\0' (Therefore at most size-1 characters can be read in one go).
35 INPUTS
36 buffer - Write characters into this buffer
37 size - This is the size of the buffer in characters.
38 stream - Read from this stream
40 RESULT
41 buffer or NULL in case of an error or EOF.
43 NOTES
45 EXAMPLE
46 // Read a file line by line
47 char line[256];
49 // Read until EOF
50 while (fgets (line, sizeof (line), fh))
52 // Evaluate the line
55 BUGS
57 SEE ALSO
58 fopen(), gets(), fputs(), putc()
60 INTERNALS
62 ******************************************************************************/
64 fdesc *fdesc = __getfdesc(stream->fd);
66 if (!fdesc)
68 errno = EBADF;
69 stream->flags |= _STDIO_ERROR;
71 return NULL;
74 buffer = FGets ((BPTR)fdesc->fcb->fh, buffer, size);
76 if (!buffer)
78 if (IoErr ())
80 errno = __arosc_ioerr2errno(IoErr());
81 stream->flags |= _STDIO_ERROR;
83 else
85 stream->flags |= _STDIO_EOF;
89 return buffer;
90 } /* fgets */