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