1 .\" Copyright (c) 2009 David Schultz <das@FreeBSD.org>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" $FreeBSD: src/lib/libc/stdio/getline.3,v 1.2 2009/04/06 13:50:04 das Exp $
33 .Nd get a line from a stream
37 .Fd "#define _WITH_GETLINE"
40 .Fn getdelim "char ** restrict linep" "size_t * restrict linecapp" "int delimiter" " FILE * restrict stream"
42 .Fn getline "char ** restrict linep" "size_t * restrict linecapp" " FILE * restrict stream"
46 function reads a line from
48 delimited by the character
52 function is equivalent to
54 with the newline character as the delimiter.
55 The delimiter character is included as part of the line, unless
56 the end of the file is reached.
57 The caller may provide a pointer to a malloc buffer for the line in
59 and the capacity of that buffer in
67 These functions may expand the buffer as needed, as if via
79 functions return the number of characters written, excluding the
82 The value \-1 is returned if an error occurs, or if end-of-file is reached.
84 The following code fragment reads lines from a file and
85 writes them to standard output.
88 function is used in case the line contains embedded
91 .Bd -literal -offset indent
95 while ((linelen = getline(&line, &linecap, fp)) > 0)
96 fwrite(line, linelen, 1, stdout);
99 Many application writers used the name
103 function was introduced in
105 so a prototype is not provided by default in order to avoid
106 compatibility problems.
107 Applications that wish to use the
109 function described herein should either request a strict
111 environment by defining the macro
113 to the value 200809 or greater, or by defining the macro
115 prior to the inclusion of
117 For compatibility with GNU libc, defining either
121 prior to the inclusion of
127 These functions may fail if:
137 No delimiter was found in the first
142 These functions may also fail for any of the errors specified for
158 These routines first appeared in
161 There are no wide character versions of