| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: getdelim.3,v 1.4 2009/11/30 22:51:46 roy Exp $ | | 1 | .\" $NetBSD: getdelim.3,v 1.5 2009/11/30 23:23:29 roy Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 2009 The NetBSD Foundation, Inc. | | 3 | .\" Copyright (c) 2009 The NetBSD Foundation, Inc. |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | | 6 | .\" This code is derived from software contributed to The NetBSD Foundation |
7 | .\" by Roy Marples. | | 7 | .\" by Roy Marples. |
8 | .\" | | 8 | .\" |
9 | .\" Redistribution and use in source and binary forms, with or without | | 9 | .\" Redistribution and use in source and binary forms, with or without |
10 | .\" modification, are permitted provided that the following conditions | | 10 | .\" modification, are permitted provided that the following conditions |
11 | .\" are met: | | 11 | .\" are met: |
12 | .\" 1. Redistributions of source code must retain the above copyright | | 12 | .\" 1. Redistributions of source code must retain the above copyright |
13 | .\" notice, this list of conditions and the following disclaimer. | | 13 | .\" notice, this list of conditions and the following disclaimer. |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 14 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| @@ -81,26 +81,33 @@ is equivalent to | | | @@ -81,26 +81,33 @@ is equivalent to |
81 | .Fa getdelim | | 81 | .Fa getdelim |
82 | with the delimiter set to the newline character. | | 82 | with the delimiter set to the newline character. |
83 | .Sh RETURN VALUES | | 83 | .Sh RETURN VALUES |
84 | The | | 84 | The |
85 | .Fn getdelim | | 85 | .Fn getdelim |
86 | and | | 86 | and |
87 | .Fn getline | | 87 | .Fn getline |
88 | functions return the number of characters read, including the delimiter. | | 88 | functions return the number of characters read, including the delimiter. |
89 | If no characters were read and the stream is at end-of-file, the functions | | 89 | If no characters were read and the stream is at end-of-file, the functions |
90 | return \-1. | | 90 | return \-1. |
91 | If an error occurs, the functions return \-1 and the global variable | | 91 | If an error occurs, the functions return \-1 and the global variable |
92 | .Va errno | | 92 | .Va errno |
93 | is set to indicate the error. | | 93 | is set to indicate the error. |
| | | 94 | .Pp |
| | | 95 | The functions do not distinguish between end-of-file and error, |
| | | 96 | and callers must use |
| | | 97 | .Xr feof 3 |
| | | 98 | and |
| | | 99 | .Xr ferror 3 |
| | | 100 | to determine which occurred. |
94 | .Sh EXAMPLE | | 101 | .Sh EXAMPLE |
95 | The following code fragment reads lines from a file and writes them to | | 102 | The following code fragment reads lines from a file and writes them to |
96 | standard output. | | 103 | standard output. |
97 | .Bd -literal -offset indent | | 104 | .Bd -literal -offset indent |
98 | char *line = NULL; | | 105 | char *line = NULL; |
99 | size_t linesize = 0; | | 106 | size_t linesize = 0; |
100 | ssize_t linelen; | | 107 | ssize_t linelen; |
101 | while ((linelen = getline(&line, &linesize, fp)) != -1) | | 108 | while ((linelen = getline(&line, &linesize, fp)) != -1) |
102 | fwrite(line, linelen, 1, stdout); | | 109 | fwrite(line, linelen, 1, stdout); |
103 | | | 110 | |
104 | if (ferror(fp)) | | 111 | if (ferror(fp)) |
105 | perror("getline"); | | 112 | perror("getline"); |
106 | .Sh ERRORS | | 113 | .Sh ERRORS |