BSD 4_4 development
[unix-history] / usr / share / man / cat3 / fgets.0
FGETS(3) BSD Programmer's Manual FGETS(3)
N\bNA\bAM\bME\bE
f\bfg\bge\bet\bts\bs, g\bge\bet\bts\bs - get a line from a stream
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
#\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<s\bst\btd\bdi\bio\bo.\b.h\bh>\b>
_\bc_\bh_\ba_\br _\b*
f\bfg\bge\bet\bts\bs(_\bc_\bh_\ba_\br _\b*_\bs_\bt_\br, _\bs_\bi_\bz_\be_\b__\bt _\bs_\bi_\bz_\be, _\bF_\bI_\bL_\bE _\b*_\bs_\bt_\br_\be_\ba_\bm);
_\bc_\bh_\ba_\br _\b*
g\bge\bet\bts\bs(_\bc_\bh_\ba_\br _\b*_\bs_\bt_\br);
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
The f\bfg\bge\bet\bts\bs() function reads at most one less than the number of characters
specified by size from the given _\bs_\bt_\br_\be_\ba_\bm and stores them in the string
_\bs_\bt_\br. Reading stops when a newline character is found, at end-of-file or
error. The newline, if any, is retained. In any case a `\0' character
is appended to end the string.
The g\bge\bet\bts\bs() function is equivalent to f\bfg\bge\bet\bts\bs() with an infinite size and a
_\bs_\bt_\br_\be_\ba_\bm of _\bs_\bt_\bd_\bi_\bn, except that the newline character (if any) is not stored
in the string. It is the caller's responsibility to ensure that the in-
put line, if any, is sufficiently short to fit in the string.
R\bRE\bET\bTU\bUR\bRN\bN V\bVA\bAL\bLU\bUE\bES\bS
Upon successful completion, f\bfg\bge\bet\bts\bs() and g\bge\bet\bts\bs() return a pointer to the
string. If end-of-file or an error occurs before any characters are
read, they return NULL. The f\bfg\bge\bet\bts\bs() and functions g\bge\bet\bts\bs() do not distin-
guish between end-of-file and error, and callers must use feof(3) and
ferror(3) to determine which occurred.
E\bER\bRR\bRO\bOR\bRS\bS
[EBADF] The given _\bs_\bt_\br_\be_\ba_\bm is not a readable stream.
The function f\bfg\bge\bet\bts\bs() may also fail and set _\be_\br_\br_\bn_\bo for any of the errors
specified for the routines fflush(3), fstat(2), read(2), or malloc(3).
The function g\bge\bet\bts\bs() may also fail and set _\be_\br_\br_\bn_\bo for any of the errors
specified for the routine getchar(3).
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
feof(3), ferror(3), fgetline(3)
S\bST\bTA\bAN\bND\bDA\bAR\bRD\bDS\bS
The functions f\bfg\bge\bet\bts\bs() and g\bge\bet\bts\bs() conform to ANSI C X3.159-1989 (``ANSI C
'').
B\bBU\bUG\bGS\bS
Since it is usually impossible to ensure that the next input line is less
than some arbitrary length, and because overflowing the input buffer is
almost invariably a security violation, programs should _\bN_\bE_\bV_\bE_\bR use g\bge\bet\bts\bs().
The g\bge\bet\bts\bs() function exists purely to conform to ANSI C X3.159-1989
(``ANSI C '').
4.4BSD June 4, 1993 1