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

NAME

12       gets - get a string from a stdin stream
13

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

34       Upon successful completion, gets() shall return s. If the stream is  at
35       end-of-file,  the end-of-file indicator for the stream shall be set and
36       gets() shall return a null pointer.  If a read error occurs, the  error
37       indicator  for  the  stream  shall  be  set, gets() shall return a null
38       pointer,  and set errno to indicate the error.
39

ERRORS

41       Refer to fgetc().
42
43       The following sections are informative.
44

EXAMPLES

46       None.
47

APPLICATION USAGE

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

RATIONALE

62       None.
63

FUTURE DIRECTIONS

65       None.
66

SEE ALSO

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