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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       gets — get a string from a stdin stream
14

SYNOPSIS

16       #include <stdio.h>
17
18       char *gets(char *s);
19

DESCRIPTION

21       The functionality described on this reference page is aligned with  the
22       ISO C  standard.  Any  conflict between the requirements described here
23       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2008
24       defers to the ISO C standard.
25
26       The  gets()  function  shall read bytes from the standard input stream,
27       stdin, into the array pointed to by s, until a <newline> is read or  an
28       end-of-file  condition is encountered. Any <newline> shall be discarded
29       and a null byte shall be placed immediately after the  last  byte  read
30       into the array.
31
32       The gets() function may mark the last data access timestamp of the file
33       associated with stream for update. The last data access timestamp shall
34       be  marked  for  update  by  the first successful execution of fgetc(),
35       fgets(), fread(), fscanf(), getc(), getchar(),  getdelim(),  getline(),
36       gets(),  or  scanf()  using  stream that returns data not supplied by a
37       prior call to ungetc().
38

RETURN VALUE

40       Upon successful completion, gets() shall return s.  If the  end-of-file
41       indicator  for  the  stream is set, or if the stream is at end-of-file,
42       the end-of-file indicator for the stream shall be set and gets()  shall
43       return  a null pointer. If a read error occurs, the error indicator for
44       the stream shall be set, gets() shall return a null  pointer,  and  set
45       errno to indicate the error.
46

ERRORS

48       Refer to fgetc().
49
50       The following sections are informative.
51

EXAMPLES

53       None.
54

APPLICATION USAGE

56       Reading  a  line  that  overflows  the array pointed to by s results in
57       undefined behavior. The use of fgets() is recommended.
58
59       Since the user cannot specify  the  length  of  the  buffer  passed  to
60       gets(),  use  of this function is discouraged. The length of the string
61       read is unlimited. It is possible to overflow this buffer in such a way
62       as  to  cause  applications to fail, or possible system security viola‐
63       tions.
64
65       Applications should use the fgets() function instead of the obsolescent
66       gets() function.
67

RATIONALE

69       The standard developers decided to mark the gets() function as obsoles‐
70       cent even though it is in the ISO C standard due to the possibility  of
71       buffer overflow.
72

FUTURE DIRECTIONS

74       The gets() function may be removed in a future version.
75

SEE ALSO

77       Section 2.5, Standard I/O Streams, feof(), ferror(), fgets()
78
79       The Base Definitions volume of POSIX.1‐2008, <stdio.h>
80
82       Portions  of  this text are reprinted and reproduced in electronic form
83       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
84       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
85       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
86       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
87       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
88       event of any discrepancy between this version and the original IEEE and
89       The Open Group Standard, the original IEEE and The Open Group  Standard
90       is  the  referee document. The original Standard can be obtained online
91       at http://www.unix.org/online.html .
92
93       Any typographical or formatting errors that appear  in  this  page  are
94       most likely to have been introduced during the conversion of the source
95       files to man page format. To report such errors,  see  https://www.ker
96       nel.org/doc/man-pages/reporting_bugs.html .
97
98
99
100IEEE/The Open Group                  2013                             GETS(3P)
Impressum