OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / gets.3
1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified Wed Jul 28 11:12:07 1993 by Rik Faith (faith@cs.unc.edu)
26 .\" Modified Fri Sep  8 15:48:13 1995 by Andries Brouwer (aeb@cwi.nl)
27 .\" Modified 2013-12-31, David Malcolm <dmalcolm@redhat.com>
28 .\"     Split gets(3) into its own page; fgetc() et al. move to fgetc(3)
29 .TH GETS 3  2014-01-24 "GNU" "Linux Programmer's Manual"
30 .SH NAME
31 gets \- get a string from standard input (DEPRECATED)
32 .SH SYNOPSIS
33 .nf
34 .B #include <stdio.h>
35 .sp
36 .BI "char *gets(char *" "s" );
37 .fi
38 .SH DESCRIPTION
39 .IR "Never use this function" .
40
41 .BR gets ()
42 reads a line from
43 .I stdin
44 into the buffer pointed to by
45 .I s
46 until either a terminating newline or
47 .BR EOF ,
48 which it replaces with a null byte (\(aq\e0\(aq).
49 No check for buffer overrun is performed (see BUGS below).
50 .SH RETURN VALUE
51 .BR gets ()
52 returns
53 .I s
54 on success, and NULL
55 on error or when end of file occurs while no characters have been read.
56 However, given the lack of buffer overrun checking, there can be no
57 guarantees that the function will even return.
58 .SH CONFORMING TO
59 C89, C99, POSIX.1-2001.
60
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
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)
108 .SH COLOPHON
109 This page is part of release 3.79 of the Linux
110 .I man-pages
111 project.
112 A description of the project,
113 information about reporting bugs,
114 and the latest version of this page,
115 can be found at
116 \%http://www.kernel.org/doc/man\-pages/.