386BSD 0.1 development
[unix-history] / usr / src / lib / libc / stdio / fgetline.3
CommitLineData
8d2f28ac
WJ
1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)fgetline.3 5.4 (Berkeley) 4/19/91
33.\"
34.Dd April 19, 1991
35.Dt FGETLINE 3
36.Os
37.Sh NAME
38.Nm fgetline
39.Nd get a line from a stream
40.Sh SYNOPSIS
41.Fd #include <stdio.h>
42.Ft char *
43.Fn fgetline "FILE *stream" "size_t *len"
44.Sh DESCRIPTION
45The
46.Fn fgetline
47function
48returns a pointer to the next line from the stream referenced by
49.Fa stream .
50The newline character at the end of the line is replaced by a
51.Dv NUL .
52.Pp
53If
54.Fa len
55is non-NULL, the length of the line, not counting the terminating
56.Dv NUL ,
57is stored in the memory location it references.
58.Sh RETURN VALUES
59Upon successful completion a pointer is returned;
60this pointer becomes invalid after the next
61.Tn I/O
62operation on
63.Fa stream
64(whether successful or not)
65or as soon as the stream is closed.
66Otherwise,
67.Dv NULL
68is returned.
69The
70.Fn fgetline
71function
72does not distinguish between end-of-file and error; the routines
73.Xr feof 3
74and
75.Xr ferror 3
76must be used
77to determine which occurred.
78If an error occurrs, the global variable
79.Va errno
80is set to indicate the error.
81The end-of-file condition is remembered, even on a terminal, and all
82subsequent attempts to read will return
83.Dv NULL
84until the condition is
85cleared with
86.Xr clearerr 3 .
87.Pp
88The text to which the returned pointer points may be modified,
89provided that no changes are made beyond the terminating
90.Dv NUL .
91These changes are lost as soon as the pointer becomes invalid.
92.Sh ERRORS
93.Bl -tag -width [EBADF]
94.It Bq Er EBADF
95The argument
96.Fa stream
97is not a stream open for reading.
98.El
99.Pp
100The
101.Fn fgetline
102function
103may also fail and set
104.Va errno
105for any of the errors specified for the routines
106.Xr fflush 3 ,
107.Xr malloc 3 ,
108.Xr read 2 ,
109.Xr stat 2 ,
110or
111.Xr realloc 3 .
112.Sh SEE ALSO
113.Xr ferror 3 ,
114.Xr fgets 3 ,
115.Xr fopen 3 ,
116.Xr putc 3
117.Sh HISTORY
118The
119.Fn fgetline
120function is
121.Ud .
122.Sh BUGS
123It is not possible to tell whether the final line of an input file
124was terminated with a newline.