xref: /original-bsd/lib/libc/stdio/fgetln.3 (revision a5a45b47)
1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)fgetln.3	5.4 (Berkeley) 04/19/91
7.\"
8.Dd
9.Dt FGETLINE 3
10.Os
11.Sh NAME
12.Nm fgetline
13.Nd get a line from a stream
14.Sh SYNOPSIS
15.Fd #include <stdio.h>
16.Ft char *
17.Fn fgetline "FILE *stream" "size_t *len"
18.Sh DESCRIPTION
19The
20.Fn fgetline
21function
22returns a pointer to the next line from the stream referenced by
23.Fa stream .
24The newline character at the end of the line is replaced by a
25.Dv NUL .
26.Pp
27If
28.Fa len
29is non-NULL, the length of the line, not counting the terminating
30.Dv NUL ,
31is stored in the memory location it references.
32.Sh RETURN VALUES
33Upon successful completion a pointer is returned;
34this pointer becomes invalid after the next
35.Tn I/O
36operation on
37.Fa stream
38(whether successful or not)
39or as soon as the stream is closed.
40Otherwise,
41.Dv NULL
42is returned.
43The
44.Fn fgetline
45function
46does not distinguish between end-of-file and error; the routines
47.Xr feof 3
48and
49.Xr ferror 3
50must be used
51to determine which occurred.
52If an error occurrs, the global variable
53.Va errno
54is set to indicate the error.
55The end-of-file condition is remembered, even on a terminal, and all
56subsequent attempts to read will return
57.Dv NULL
58until the condition is
59cleared with
60.Xr clearerr 3 .
61.Pp
62The text to which the returned pointer points may be modified,
63provided that no changes are made beyond the terminating
64.Dv NUL .
65These changes are lost as soon as the pointer becomes invalid.
66.Sh ERRORS
67.Bl -tag -width [EBADF]
68.It Bq Er EBADF
69The argument
70.Fa stream
71is not a stream open for reading.
72.El
73.Pp
74The
75.Fn fgetline
76function
77may also fail and set
78.Va errno
79for any of the errors specified for the routines
80.Xr fflush 3 ,
81.Xr malloc 3 ,
82.Xr read 2 ,
83.Xr stat 2 ,
84or
85.Xr realloc 3 .
86.Sh SEE ALSO
87.Xr ferror 3 ,
88.Xr fgets 3 ,
89.Xr fopen 3 ,
90.Xr putc 3
91.Sh HISTORY
92The
93.Fn fgetline
94function is
95.Ud .
96.Sh BUGS
97It is not possible to tell whether the final line of an input file
98was terminated with a newline.
99