1 .\" Copyright (c) 2001 John Levon <moz@compsoc.man.ac.uk>
2 .\" Based in part on GNU libc documentation
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .TH GETLINE 3 2006-05-17 "GNU" "Linux Programmer's Manual"
26 getline, getdelim \- delimited string input
29 .B #define _GNU_SOURCE
32 .BI "ssize_t getline(char **" lineptr ", size_t *" n ", FILE *" stream );
34 .BI "ssize_t getdelim(char **" lineptr ", size_t *" n ", int " delim ", FILE *" stream );
37 reads an entire line from \fIstream\fP,
38 storing the address of the buffer containing the text into
40 The buffer is null-terminated and includes the newline character, if
43 .\" FIXME what happens if *lineptr is NULL but *n isn't zero ?
44 .\" Answer: *n is ignored and a new buffer is allocated
49 will allocate a buffer for storing the line, which should be freed
51 Alternatively, before calling
54 can contain a pointer to a
55 .BR malloc ()\-allocated
58 bytes in size. If the buffer is not large enough to hold the line,
66 as necessary. In either case, on a successful call,
70 will be updated to reflect the buffer address and allocated size respectively.
75 except a line delimiter other than newline can be specified as the
79 a delimiter character is not added if one was not present
80 in the input before end of file was reached.
86 return the number of characters read, including the delimiter character,
87 but not including the terminating null byte. This value can be used
88 to handle embedded null bytes in the line read.
90 Both functions return \-1 on failure to read a line (including end of file
115 fp = fopen("/etc/motd", "r");
118 while ((read = getline(&line, &len, fp)) != \-1) {
119 printf("Retrieved line of length %zu :\en", read);
133 They are available since libc 4.6.27.
141 .BR feature_test_macros (7)