]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/gets.3
54bf95aa84e4596e94aa813d483b5f8554721a92
[thirdparty/man-pages.git] / man3 / gets.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .\" Modified Wed Jul 28 11:12:07 1993 by Rik Faith (faith@cs.unc.edu)
6 .\" Modified Fri Sep 8 15:48:13 1995 by Andries Brouwer (aeb@cwi.nl)
7 .\" Modified 2013-12-31, David Malcolm <dmalcolm@redhat.com>
8 .\" Split gets(3) into its own page; fgetc() et al. move to fgetc(3)
9 .TH GETS 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
10 .SH NAME
11 gets \- get a string from standard input (DEPRECATED)
12 .SH LIBRARY
13 Standard C library
14 .RI ( libc ", " \-lc )
15 .SH SYNOPSIS
16 .nf
17 .B #include <stdio.h>
18 .PP
19 .BI "char *gets(char *" "s" );
20 .fi
21 .SH DESCRIPTION
22 .IR "Never use this function" .
23 .PP
24 .BR gets ()
25 reads a line from
26 .I stdin
27 into the buffer pointed to by
28 .I s
29 until either a terminating newline or
30 .BR EOF ,
31 which it replaces with a null byte (\(aq\e0\(aq).
32 No check for buffer overrun is performed (see BUGS below).
33 .SH RETURN VALUE
34 .BR gets ()
35 returns
36 .I s
37 on success, and NULL
38 on error or when end of file occurs while no characters have been read.
39 However, given the lack of buffer overrun checking, there can be no
40 guarantees that the function will even return.
41 .SH ATTRIBUTES
42 For an explanation of the terms used in this section, see
43 .BR attributes (7).
44 .ad l
45 .nh
46 .TS
47 allbox;
48 lbx lb lb
49 l l l.
50 Interface Attribute Value
51 T{
52 .BR gets ()
53 T} Thread safety MT-Safe
54 .TE
55 .hy
56 .ad
57 .sp 1
58 .SH STANDARDS
59 C89, C99, POSIX.1-2001.
60 .PP
61 LSB deprecates
62 .BR gets ().
63 POSIX.1-2008 marks
64 .BR gets ()
65 obsolescent.
66 ISO C11 removes the specification of
67 .BR gets ()
68 from the C language, and since version 2.16,
69 glibc header files don't expose the function declaration if the
70 .B _ISOC11_SOURCE
71 feature test macro is defined.
72 .SH BUGS
73 Never use
74 .BR gets ().
75 Because it is impossible to tell without knowing the data in advance how many
76 characters
77 .BR gets ()
78 will read, and because
79 .BR gets ()
80 will continue to store characters past the end of the buffer,
81 it is extremely dangerous to use.
82 It has been used to break computer security.
83 Use
84 .BR fgets ()
85 instead.
86 .PP
87 For more information, see CWE-242 (aka "Use of Inherently Dangerous
88 Function") at
89 http://cwe.mitre.org/data/definitions/242.html
90 .SH SEE ALSO
91 .BR read (2),
92 .BR write (2),
93 .BR ferror (3),
94 .BR fgetc (3),
95 .BR fgets (3),
96 .BR fgetwc (3),
97 .BR fgetws (3),
98 .BR fopen (3),
99 .BR fread (3),
100 .BR fseek (3),
101 .BR getline (3),
102 .BR getwchar (3),
103 .BR puts (3),
104 .BR scanf (3),
105 .BR ungetwc (3),
106 .BR unlocked_stdio (3),
107 .BR feature_test_macros (7)