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