Indentation fix, cleanup.
[AROS.git] / compiler / stdc / gets.c
blob13b26d6d782cd53d12e02529339b89f90b7380f1
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function gets().
6 */
7 #include <libraries/stdcio.h>
8 #include <string.h>
10 /*****************************************************************************
12 NAME */
13 #include <stdio.h>
15 char * gets (
17 /* SYNOPSIS */
18 char * buffer)
20 /* FUNCTION
21 Read one line of characters from the standard input stream into
22 the buffer. Reading will stop, when a newline ('\n') is encountered,
23 EOF or when the buffer is full. If a newline is read, then it is
24 replaced by '\0'. The last character in the buffer is always '\0'.
26 INPUTS
27 buffer - Write characters into this buffer
29 RESULT
30 buffer when succesfull. NULL in case of an error or when EOF without any
31 characters read. In the latter case buffer array is unchanged.
33 NOTES
35 EXAMPLE
37 BUGS
38 Never use this function. gets() does not know how large the buffer
39 is and will continue to store characters past the end of the buffer
40 if it has not encountered a newline or EOF yet. Use fgets() instead.
42 SEE ALSO
43 fgets()
45 INTERNALS
47 ******************************************************************************/
49 struct StdCIOBase *StdCIOBase = __aros_getbase_StdCIOBase();
50 char *s = buffer;
51 int c;
53 c = getchar();
54 while(c != '\n' && c != EOF)
56 *s = c;
57 s++;
58 c = getchar();
61 if (ferror(StdCIOBase->_stdin))
63 *s = 0;
64 return NULL;
66 else if (c == EOF && s == buffer)
68 return NULL;
70 else
72 *s = 0;
73 return buffer;
75 } /* gets */