1gets(3)                    Library Functions Manual                    gets(3)
2
3
4

NAME

6       gets - get a string from standard input (DEPRECATED)
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdio.h>
13
14       [[deprecated]] char *gets(char *s);
15

DESCRIPTION

17       Never use this function.
18
19       gets()  reads  a  line from stdin into the buffer pointed to by s until
20       either a terminating newline or EOF, which it replaces with a null byte
21       ('\0').  No check for buffer overrun is performed (see BUGS below).
22

RETURN VALUE

24       gets()  returns s on success, and NULL on error or when end of file oc‐
25       curs while no characters have been read.  However, given  the  lack  of
26       buffer  overrun  checking, there can be no guarantees that the function
27       will even return.
28

ATTRIBUTES

30       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
31       tributes(7).
32
33       ┌────────────────────────────────────────────┬───────────────┬─────────┐
34Interface                                   Attribute     Value   
35       ├────────────────────────────────────────────┼───────────────┼─────────┤
36gets()                                      │ Thread safety │ MT-Safe │
37       └────────────────────────────────────────────┴───────────────┴─────────┘
38

STANDARDS

40       POSIX.1-2008.
41

HISTORY

43       C89, POSIX.1-2001.
44
45       LSB deprecates gets().  POSIX.1-2008 marks gets() obsolescent.  ISO C11
46       removes the specification of gets() from  the  C  language,  and  since
47       glibc 2.16, glibc header files don't expose the function declaration if
48       the _ISOC11_SOURCE feature test macro is defined.
49

BUGS

51       Never use gets().  Because it is impossible to tell without knowing the
52       data  in  advance  how  many  characters  gets() will read, and because
53       gets() will continue to store characters past the end of the buffer, it
54       is  extremely dangerous to use.  It has been used to break computer se‐
55       curity.  Use fgets() instead.
56
57       For more information, see CWE-242 (aka  "Use  of  Inherently  Dangerous
58       Function") at http://cwe.mitre.org/data/definitions/242.html
59

SEE ALSO

61       read(2), write(2), ferror(3), fgetc(3), fgets(3), fgetwc(3), fgetws(3),
62       fopen(3),  fread(3),  fseek(3),   getline(3),   getwchar(3),   puts(3),
63       scanf(3), ungetwc(3), unlocked_stdio(3), feature_test_macros(7)
64
65
66
67Linux man-pages 6.04              2023-03-30                           gets(3)
Impressum