1 .\" $NetBSD: getdelim.3,v 1.6 2009/12/01 08:15:50 wiz Exp $
3 .\" Copyright (c) 2009 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
36 .Nd read a delimited record from a stream
42 .Fn getdelim "char ** restrict lineptr" "size_t * restrict n" "int delimiter" "FILE * restrict stream"
44 .Fn getline "char ** restrict lineptr" "size_t * restrict n" "FILE * restrict stream"
48 function reads from the
50 until it encounters a character matching the
52 character, storing the input in
55 .Dv NUL Ns No -terminated
56 and includes the delimiter.
62 must be pre-allocated to at least
68 is large enough to hold the input, updating
70 to reflect the new size.
73 must be representable as an unsigned char, and
82 with the delimiter set to the newline character.
88 functions return the number of characters read, including the delimiter.
89 If no characters were read and the stream is at end-of-file, the functions
91 If an error occurs, the functions return \-1 and the global variable
93 is set to indicate the error.
95 The functions do not distinguish between end-of-file and error,
100 to determine which occurred.
102 The following code fragment reads lines from a file and writes them to
104 .Bd -literal -offset indent
108 while ((linelen = getline(\*[Am]line, \*[Am]linesize, fp)) != -1)
109 fwrite(line, linelen, 1, stdout);
115 .Bl -tag -width [EOVERFLOW]
124 More than SSIZE_MAX characters were read without encountering the delimiter.
131 functions may also fail and set
133 for any of the errors specified in the routines