1GETS(P)                    POSIX Programmer's Manual                   GETS(P)
2
3
4

NAME

6       gets - get a string from a stdin stream
7

SYNOPSIS

9       #include <stdio.h>
10
11       char *gets(char *s);
12
13

DESCRIPTION

15       The  gets()  function  shall read bytes from the standard input stream,
16       stdin, into the array pointed to by s, until a <newline> is read or  an
17       end-of-file condition is encountered.  Any <newline> shall be discarded
18       and a null byte shall be placed immediately after the  last  byte  read
19       into the array.
20
21       The  gets() function may mark the st_atime field of the file associated
22       with stream for update. The st_atime field shall be marked  for  update
23       by the first successful execution of fgetc(), fgets(), fread(), getc(),
24       getchar(), gets(), fscanf(), or scanf() using stream that returns  data
25       not supplied by a prior call to ungetc().
26

RETURN VALUE

28       Upon  successful completion, gets() shall return s. If the stream is at
29       end-of-file, the end-of-file indicator for the stream shall be set  and
30       gets()  shall return a null pointer.  If a read error occurs, the error
31       indicator for the stream shall be  set,  gets()  shall  return  a  null
32       pointer,    and set errno to indicate the error.
33

ERRORS

35       Refer to fgetc() .
36
37       The following sections are informative.
38

EXAMPLES

40       None.
41

APPLICATION USAGE

43       Reading  a  line  that  overflows  the array pointed to by s results in
44       undefined behavior. The use of fgets() is recommended.
45
46       Since the user cannot specify  the  length  of  the  buffer  passed  to
47       gets(),  use  of this function is discouraged. The length of the string
48       read is unlimited. It is possible to overflow this buffer in such a way
49       as  to  cause  applications to fail, or possible system security viola‐
50       tions.
51
52       It is recommended that the fgets() function  should  be  used  to  read
53       input lines.
54

RATIONALE

56       None.
57

FUTURE DIRECTIONS

59       None.
60

SEE ALSO

62       feof()   ,  ferror()  ,  fgets()  ,  the  Base  Definitions  volume  of
63       IEEE Std 1003.1-2001, <stdio.h>
64
66       Portions of this text are reprinted and reproduced in  electronic  form
67       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
68       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
69       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
70       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
71       event of any discrepancy between this version and the original IEEE and
72       The Open Group Standard, the original IEEE and The Open Group  Standard
73       is  the  referee document. The original Standard can be obtained online
74       at http://www.opengroup.org/unix/online.html .
75
76
77
78IEEE/The Open Group                  2003                              GETS(P)
Impressum