blob: e31104da1fc4a3039c335f1a39d40743d13031b1 [file]
<html lang="en">
<head>
<title>gets - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Stdio.html#Stdio" title="Stdio">
<link rel="prev" href="getline.html#getline" title="getline">
<link rel="next" href="getw.html#getw" title="getw">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="gets"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="getw.html#getw">getw</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="getline.html#getline">getline</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Stdio.html#Stdio">Stdio</a>
<hr>
</div>
<h3 class="section">4.38 <code>gets</code>&mdash;get character string (obsolete, use <code>fgets</code> instead)</h3>
<p><a name="index-gets-225"></a><a name="index-g_t_005fgets_005fr-226"></a><strong>Synopsis</strong>
<pre class="example"> #include &lt;stdio.h&gt;
char *gets(char *<var>buf</var>);
char *_gets_r(struct _reent *<var>reent</var>, char *<var>buf</var>);
</pre>
<p><strong>Description</strong><br>
Reads characters from standard input until a newline is found.
The characters up to the newline are stored in <var>buf</var>. The
newline is discarded, and the buffer is terminated with a 0.
<p>This is a <em>dangerous</em> function, as it has no way of checking
the amount of space available in <var>buf</var>. One of the attacks
used by the Internet Worm of 1988 used this to overrun a
buffer allocated on the stack of the finger daemon and
overwrite the return address, causing the daemon to execute
code downloaded into it over the connection.
<p>The alternate function <code>_gets_r</code> is a reentrant version. The extra
argument <var>reent</var> is a pointer to a reentrancy structure.
<p><br>
<strong>Returns</strong><br>
<code>gets</code> returns the buffer passed to it, with the data filled
in. If end of file occurs with some data already accumulated,
the data is returned with no other indication. If end of file
occurs with no data in the buffer, NULL is returned.
<p>Supporting OS subroutines required: <code>close</code>, <code>fstat</code>, <code>isatty</code>,
<code>lseek</code>, <code>read</code>, <code>sbrk</code>, <code>write</code>.
<p><br>
</body></html>