r6831@lvps87-230-33-50: verhaegs | 2008-02-03 14:08:57 +0100
[tangerine.git] / compiler / clib / fgets.c
bloba25cf55c9bf2862a42e8f3a4d4812c9078955896
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C 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 "__open.h"
14 #include "__errno.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->fh, buffer, size);
76 if (!buffer)
78 if (IoErr ())
80 errno = IoErr2errno(IoErr());
81 stream->flags |= _STDIO_ERROR;
83 else
85 stream->flags |= _STDIO_EOF;
89 return buffer;
90 } /* fgets */