VAX .s routines only work with the old stdio
[unix-history] / usr / src / lib / libc / stdio / fgets.3
CommitLineData
639aed4c 1.\" Copyright (c) 1990 The Regents of the University of California.
952018c5 2.\" All rights reserved.
2e146d0b 3.\"
639aed4c
KB
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek.
6.\"
91cff1e1 7.\" %sccs.include.redist.man%
952018c5 8.\"
639aed4c 9.\" @(#)fgets.3 6.5 (Berkeley) %G%
952018c5
KB
10.\"
11.TH FGETS 3 ""
639aed4c 12.UC 7
2e146d0b 13.SH NAME
639aed4c 14fgets, gets \- get a line from a stream
2e146d0b 15.SH SYNOPSIS
952018c5 16.nf
639aed4c
KB
17.ft B
18#include <stdio.h>
19
20char *
21fgets(char *str, size_t size, FILE *stream);
952018c5 22
639aed4c
KB
23char *
24gets(char *str);
25.ft R
952018c5 26.fi
2e146d0b 27.SH DESCRIPTION
639aed4c
KB
28.I Fgets
29reads at most one less than the number of characters specified by
30.IR size
31from the given
2e146d0b 32.I stream
639aed4c
KB
33into the string
34.IR str .
35Reading stops when a newline character is found,
36at end-of-file or error.
37The newline, if any, is retained.
38In any case a '\e0' character is appended to end the string.
952018c5 39.PP
639aed4c
KB
40.I Gets
41is equivalent to
952018c5 42.I fgets
639aed4c
KB
43with an infinite
44.I size
45and a
46.I stream
47of
48.BR stdin ,
49except that the newline character (if any) is not stored in the string.
50It is the caller's responsibility to ensure that the input line,
51if any, is sufficiently short to fit in the string.
2e146d0b 52.SH "SEE ALSO"
639aed4c
KB
53feof(3), ferror(3), fgetline(3)
54.SH "RETURN VALUE"
55.PP
56Upon successful completion,
2e146d0b 57.I fgets
639aed4c
KB
58and
59.I gets
60return
61.IR s .
62If end-of-file or an error occurs before any characters are read,
63they return NULL.
64Callers must use
65.I feof
66and
67.I ferror
68to determine which occurred.
69.SH ERRORS
70.TP 15
71[EBADF]
72.I Stream
73is not a readable stream.
74.PP
75.I Fgets
76may also fail and set
77.I errno
78for any of the errors specified for the routines
79.IR fflush (3),
80.IR fstat (2),
81.IR read (2),
82or
83.IR malloc (3).
84.PP
85.I Gets
86may also fail and set
87.I errno
88for any of the errors specified for the routine
89.IR getchar (3).
90.SH BUGS
91Since it is usually impossible to ensure that the next input line
92is less than some arbitrary length, and because overflowing the
93input buffer is almost invariably a security violation, programs
94should
95.B NEVER
96use
97.IR gets .
98.I Gets
99exists purely to conform to ANSI X3.159-1989.
100.SH STANDARDS
101.I Fgets
102and
103.I gets
104conform to ANSI X3.159-1989 (``ANSI C'').