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 \
39 reads an entire line from \fIstream\fP,
40 storing the address of the buffer containing the text into
42 The buffer is null-terminated and includes the newline character, if
49 will allocate a buffer for storing the line,
50 which should be freed by the user program.
55 Alternatively, before calling
58 can contain a pointer to a
59 .BR malloc (3)\-allocated
63 If the buffer is not large enough to hold the line,
73 In either case, on a successful call,
77 will be updated to reflect the buffer address and allocated size respectively.
82 except a line delimiter other than newline can be specified as the
87 a delimiter character is not added if one was not present
88 in the input before end of file was reached.
94 return the number of characters read, including the delimiter character,
95 but not including the terminating null byte.
96 This value can be used
97 to handle embedded null bytes in the line read.
99 Both functions return \-1 on failure to read a line (including end of file
117 They are available since libc 4.6.27.
131 fp = fopen("/etc/motd", "r");
134 while ((read = getline(&line, &len, fp)) != \-1) {
135 printf("Retrieved line of length %zu :\en", read);
150 .BR feature_test_macros (7)