Fixed compatibility of output.
[AROS.git] / compiler / posixc / gets.c
blob99b115696c83c840c980f3b10078b5060e626be1
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function gets().
6 */
8 #include <dos/dos.h>
9 #include <dos/dosextens.h>
10 #include <proto/exec.h>
11 #include <proto/dos.h>
12 #include <libraries/posixc.h>
13 #include "__fdesc.h"
15 #include <string.h>
17 /*****************************************************************************
19 NAME */
20 #include <stdio.h>
22 char * gets (
24 /* SYNOPSIS */
25 char * buffer)
27 /* FUNCTION
28 Read one line of characters from the standard input stream into
29 the buffer. Reading will stop, when a newline ('\n') is encountered,
30 EOF or when the buffer is full. If a newline is read, then it is
31 replaced by '\0'. The last character in the buffer is always '\0'.
33 INPUTS
34 buffer - Write characters into this buffer
36 RESULT
37 buffer or NULL in case of an error or EOF.
39 NOTES
41 EXAMPLE
43 BUGS
44 Never use this function. gets() does not know how large the buffer
45 is and will continue to store characters past the end of the buffer
46 if it has not encountered a newline or EOF yet. Use fgets() instead.
48 SEE ALSO
49 fgets()
51 INTERNALS
53 ******************************************************************************/
55 struct PosixCBase *PosixCBase = __aros_getbase_PosixCBase();
57 char *s = fgets(buffer, BUFSIZ, PosixCBase->_stdin);
58 if (s)
60 /* strip trailing \n */
61 size_t sl = strlen(s);
62 if ( (sl > 0) && (s[sl-1] == '\n') )
64 s[sl-1] = '\0';
67 return s;
68 } /* gets */