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 2010-06-12 "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)):
49 _POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700
58 reads an entire line from \fIstream\fP,
59 storing the address of the buffer containing the text into
61 The buffer is null-terminated and includes the newline character, if
68 will allocate a buffer for storing the line,
69 which should be freed by the user program.
70 (In this case, the value in
74 Alternatively, before calling
77 can contain a pointer to a
78 .BR malloc (3)\-allocated
82 If the buffer is not large enough to hold the line,
92 In either case, on a successful call,
96 will be updated to reflect the buffer address and allocated size respectively.
101 except that a line delimiter other than newline can be specified as the
106 a delimiter character is not added if one was not present
107 in the input before end of file was reached.
113 return the number of characters read, including the delimiter character,
114 but not including the terminating null byte.
115 This value can be used
116 to handle embedded null bytes in the line read.
118 Both functions return \-1 on failure to read a line (including end-of-file
131 These functions are available since libc 4.6.27.
137 were originally GNU extensions.
138 They were standardized in POSIX.1-2008.
153 fp = fopen("/etc/motd", "r");
157 while ((read = getline(&line, &len, fp)) != \-1) {
158 printf("Retrieved line of length %zu :\en", read);
173 .BR feature_test_macros (7)