1.\" Copyright (c) 1990, 1991, 1993 2.\" The Regents of the University of California. 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.\" @(#)fgetln.3 8.3 (Berkeley) 4/19/94 33.\" $FreeBSD$ 34.\" 35.Dd April 19, 1994 36.Dt FGETLN 3 37.Os 38.Sh NAME 39.Nm fgetln 40.Nd get a line from a stream 41.Sh SYNOPSIS 42.Fd #include <stdio.h> 43.Ft char * 44.Fn fgetln "FILE *stream" "size_t *len" 45.Sh DESCRIPTION 46The 47.Fn fgetln 48function 49returns a pointer to the next line from the stream referenced by 50.Fa stream . 51This line is 52.Em not 53a C string as it does not end with a terminating 54.Dv NUL 55character. 56The length of the line, including the final newline, 57is stored in the memory location to which 58.Fa len 59points. 60(Note, however, that if the line is the last 61in a file that does not end in a newline, 62the returned text will not contain a newline.) 63.Sh RETURN VALUES 64Upon successful completion a pointer is returned; 65this pointer becomes invalid after the next 66.Tn I/O 67operation on 68.Fa stream 69(whether successful or not) 70or as soon as the stream is closed. 71Otherwise, 72.Dv NULL 73is returned. 74The 75.Fn fgetln 76function 77does not distinguish between end-of-file and error; the routines 78.Xr feof 3 79and 80.Xr ferror 3 81must be used 82to determine which occurred. 83If an error occurs, the global variable 84.Va errno 85is set to indicate the error. 86The end-of-file condition is remembered, even on a terminal, and all 87subsequent attempts to read will return 88.Dv NULL 89until the condition is 90cleared with 91.Xr clearerr 3 . 92.Pp 93The text to which the returned pointer points may be modified, 94provided that no changes are made beyond the returned size. 95These changes are lost as soon as the pointer becomes invalid. 96.Sh ERRORS 97.Bl -tag -width [EBADF] 98.It Bq Er EBADF 99The argument 100.Fa stream 101is not a stream open for reading. 102.El 103.Pp 104The 105.Fn fgetln 106function 107may also fail and set 108.Va errno 109for any of the errors specified for the routines 110.Xr fflush 3 , 111.Xr malloc 3 , 112.Xr read 2 , 113.Xr stat 2 , 114or 115.Xr realloc 3 . 116.Sh SEE ALSO 117.Xr ferror 3 , 118.Xr fgets 3 , 119.Xr fopen 3 , 120.Xr putc 3 121.Sh HISTORY 122The 123.Fn fgetln 124function first appeared in 125.Bx 4.4 . 126