Commit | Line | Data |
---|---|---|
8d2f28ac WJ |
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 3. All advertising materials mentioning features or use of this software | |
13 | .\" must display the following acknowledgement: | |
14 | .\" This product includes software developed by the University of | |
15 | .\" California, Berkeley and its contributors. | |
16 | .\" 4. Neither the name of the University nor the names of its contributors | |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" @(#)fgetline.3 5.4 (Berkeley) 4/19/91 | |
33 | .\" | |
34 | .Dd April 19, 1991 | |
35 | .Dt FGETLINE 3 | |
36 | .Os | |
37 | .Sh NAME | |
38 | .Nm fgetline | |
39 | .Nd get a line from a stream | |
40 | .Sh SYNOPSIS | |
41 | .Fd #include <stdio.h> | |
42 | .Ft char * | |
43 | .Fn fgetline "FILE *stream" "size_t *len" | |
44 | .Sh DESCRIPTION | |
45 | The | |
46 | .Fn fgetline | |
47 | function | |
48 | returns a pointer to the next line from the stream referenced by | |
49 | .Fa stream . | |
50 | The newline character at the end of the line is replaced by a | |
51 | .Dv NUL . | |
52 | .Pp | |
53 | If | |
54 | .Fa len | |
55 | is non-NULL, the length of the line, not counting the terminating | |
56 | .Dv NUL , | |
57 | is stored in the memory location it references. | |
58 | .Sh RETURN VALUES | |
59 | Upon successful completion a pointer is returned; | |
60 | this pointer becomes invalid after the next | |
61 | .Tn I/O | |
62 | operation on | |
63 | .Fa stream | |
64 | (whether successful or not) | |
65 | or as soon as the stream is closed. | |
66 | Otherwise, | |
67 | .Dv NULL | |
68 | is returned. | |
69 | The | |
70 | .Fn fgetline | |
71 | function | |
72 | does not distinguish between end-of-file and error; the routines | |
73 | .Xr feof 3 | |
74 | and | |
75 | .Xr ferror 3 | |
76 | must be used | |
77 | to determine which occurred. | |
78 | If an error occurrs, the global variable | |
79 | .Va errno | |
80 | is set to indicate the error. | |
81 | The end-of-file condition is remembered, even on a terminal, and all | |
82 | subsequent attempts to read will return | |
83 | .Dv NULL | |
84 | until the condition is | |
85 | cleared with | |
86 | .Xr clearerr 3 . | |
87 | .Pp | |
88 | The text to which the returned pointer points may be modified, | |
89 | provided that no changes are made beyond the terminating | |
90 | .Dv NUL . | |
91 | These changes are lost as soon as the pointer becomes invalid. | |
92 | .Sh ERRORS | |
93 | .Bl -tag -width [EBADF] | |
94 | .It Bq Er EBADF | |
95 | The argument | |
96 | .Fa stream | |
97 | is not a stream open for reading. | |
98 | .El | |
99 | .Pp | |
100 | The | |
101 | .Fn fgetline | |
102 | function | |
103 | may also fail and set | |
104 | .Va errno | |
105 | for any of the errors specified for the routines | |
106 | .Xr fflush 3 , | |
107 | .Xr malloc 3 , | |
108 | .Xr read 2 , | |
109 | .Xr stat 2 , | |
110 | or | |
111 | .Xr realloc 3 . | |
112 | .Sh SEE ALSO | |
113 | .Xr ferror 3 , | |
114 | .Xr fgets 3 , | |
115 | .Xr fopen 3 , | |
116 | .Xr putc 3 | |
117 | .Sh HISTORY | |
118 | The | |
119 | .Fn fgetline | |
120 | function is | |
121 | .Ud . | |
122 | .Sh BUGS | |
123 | It is not possible to tell whether the final line of an input file | |
124 | was terminated with a newline. |