186 lines
4.5 KiB
HTML
186 lines
4.5 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of GETS</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>GETS</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
gets - get a string from standard input (DEPRECATED)
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>></B>
|
|
|
|
<B>char *gets(char *</B><I>s</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
<I>Never use this function</I>.
|
|
|
|
<P>
|
|
|
|
<B>gets</B>()
|
|
|
|
reads a line from
|
|
<I>stdin</I>
|
|
|
|
into the buffer pointed to by
|
|
<I>s</I>
|
|
|
|
until either a terminating newline or
|
|
<B>EOF</B>,
|
|
|
|
which it replaces with a null byte ('\0').
|
|
No check for buffer overrun is performed (see BUGS below).
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
<B>gets</B>()
|
|
|
|
returns
|
|
<I>s</I>
|
|
|
|
on success, and NULL
|
|
on error or when end of file occurs while no characters have been read.
|
|
However, given the lack of buffer overrun checking, there can be no
|
|
guarantees that the function will even return.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>gets</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
C89, C99, POSIX.1-2001.
|
|
<P>
|
|
|
|
LSB deprecates
|
|
<B>gets</B>().
|
|
|
|
POSIX.1-2008 marks
|
|
<B>gets</B>()
|
|
|
|
obsolescent.
|
|
ISO C11 removes the specification of
|
|
<B>gets</B>()
|
|
|
|
from the C language, and since version 2.16,
|
|
glibc header files don't expose the function declaration if the
|
|
<B>_ISOC11_SOURCE</B>
|
|
|
|
feature test macro is defined.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
Never use
|
|
<B>gets</B>().
|
|
|
|
Because it is impossible to tell without knowing the data in advance how many
|
|
characters
|
|
<B>gets</B>()
|
|
|
|
will read, and because
|
|
<B>gets</B>()
|
|
|
|
will continue to store characters past the end of the buffer,
|
|
it is extremely dangerous to use.
|
|
It has been used to break computer security.
|
|
Use
|
|
<B>fgets</B>()
|
|
|
|
instead.
|
|
<P>
|
|
|
|
For more information, see CWE-242 (aka "Use of Inherently Dangerous
|
|
Function") at
|
|
<A HREF="http://cwe.mitre.org/data/definitions/242.html">http://cwe.mitre.org/data/definitions/242.html</A>
|
|
<A NAME="lbAI"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+read">read</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+write">write</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ferror">ferror</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fgetc">fgetc</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fgets">fgets</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fgetwc">fgetwc</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fgetws">fgetws</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fopen">fopen</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fread">fread</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fseek">fseek</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getline">getline</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getwchar">getwchar</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+puts">puts</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+scanf">scanf</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ungetwc">ungetwc</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+unlocked_stdio">unlocked_stdio</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="4"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">ATTRIBUTES</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">BUGS</A><DD>
|
|
<DT id="8"><A HREF="#lbAI">SEE ALSO</A><DD>
|
|
<DT id="9"><A HREF="#lbAJ">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:44 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|