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 2009-12-05 "GNU" "Linux Programmer's Manual"
26 getline, getdelim \- delimited string input
31 .BI "ssize_t getline(char **" lineptr ", size_t *" n ", FILE *" stream );
33 .BI "ssize_t getdelim(char **" lineptr ", size_t *" n ", int " delim \
38 Feature Test Macro Requirements for glibc (see
39 .BR feature_test_macros (7)):
52 _POSIX_C_SOURCE >= 200809 || _XOPEN_SOURCE >= 700
55 reads an entire line from \fIstream\fP,
56 storing the address of the buffer containing the text into
58 The buffer is null-terminated and includes the newline character, if
65 will allocate a buffer for storing the line,
66 which should be freed by the user program.
71 Alternatively, before calling
74 can contain a pointer to a
75 .BR malloc (3)\-allocated
79 If the buffer is not large enough to hold the line,
89 In either case, on a successful call,
93 will be updated to reflect the buffer address and allocated size respectively.
98 except a line delimiter other than newline can be specified as the
103 a delimiter character is not added if one was not present
104 in the input before end of file was reached.
110 return the number of characters read, including the delimiter character,
111 but not including the terminating null byte.
112 This value can be used
113 to handle embedded null bytes in the line read.
115 Both functions return \-1 on failure to read a line (including end of file
128 These functions are available since libc 4.6.27.
134 were originally GNU extensions.
135 They were standardized in POSIX.1-2008.
150 fp = fopen("/etc/motd", "r");
154 while ((read = getline(&line, &len, fp)) != \-1) {
155 printf("Retrieved line of length %zu :\en", read);
171 .BR feature_test_macros (7)