Added a test for MUIA_Listview_SelectChange.
[AROS.git] / compiler / stdc / fgets.c
blob510390ae230f77baf754f1c20f3049ac38e113a2
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function fgets().
6 */
7 #include <proto/dos.h>
8 #include <errno.h>
10 #include "__stdio.h"
12 /*****************************************************************************
14 NAME */
15 #include <stdio.h>
17 char * fgets (
19 /* SYNOPSIS */
20 char * buffer,
21 int size,
22 FILE * stream)
24 /* FUNCTION
25 Read one line of characters from the stream into the buffer.
26 Reading will stop, when a newline ('\n') is encountered, EOF
27 or when the buffer is full. If a newline is read, then it is
28 put into the buffer. The last character in the buffer is always
29 '\0' (Therefore at most size-1 characters can be read in one go).
31 INPUTS
32 buffer - Write characters into this buffer
33 size - This is the size of the buffer in characters.
34 stream - Read from this stream
36 RESULT
37 buffer or NULL in case of an error or EOF.
39 NOTES
41 EXAMPLE
42 // Read a file line by line
43 char line[256];
45 // Read until EOF
46 while (fgets (line, sizeof (line), fh))
48 // Evaluate the line
51 BUGS
53 SEE ALSO
54 fopen(), gets(), fputs(), putc()
56 INTERNALS
58 ******************************************************************************/
60 if (!(stream->flags & __STDCIO_STDIO_READ))
62 SetIoErr(ERROR_READ_PROTECTED);
63 errno = EACCES;
64 stream->flags |= __STDCIO_STDIO_ERROR;
65 return NULL;
68 buffer = FGets (stream->fh, buffer, size);
70 if (!buffer)
72 LONG ioerr = IoErr();
74 if (ioerr)
76 errno = __stdc_ioerr2errno(ioerr);
77 stream->flags |= __STDCIO_STDIO_ERROR;
79 else
81 stream->flags |= __STDCIO_STDIO_EOF;
85 return buffer;
86 } /* fgets */