Mon Nov 30 23:23:29 2009 UTC ()
Note that callers should use feof(3) or ferror(3) to distinguish between
EOF or an error.


(roy)
diff -r1.4 -r1.5 src/lib/libc/stdio/getdelim.3

cvs diff -r1.4 -r1.5 src/lib/libc/stdio/getdelim.3 (expand / switch to unified diff)

--- src/lib/libc/stdio/getdelim.3 2009/11/30 22:51:46 1.4
+++ src/lib/libc/stdio/getdelim.3 2009/11/30 23:23:29 1.5
@@ -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
82with the delimiter set to the newline character. 82with the delimiter set to the newline character.
83.Sh RETURN VALUES 83.Sh RETURN VALUES
84The 84The
85.Fn getdelim 85.Fn getdelim
86and 86and
87.Fn getline 87.Fn getline
88functions return the number of characters read, including the delimiter. 88functions return the number of characters read, including the delimiter.
89If no characters were read and the stream is at end-of-file, the functions 89If no characters were read and the stream is at end-of-file, the functions
90return \-1. 90return \-1.
91If an error occurs, the functions return \-1 and the global variable 91If an error occurs, the functions return \-1 and the global variable
92.Va errno 92.Va errno
93is set to indicate the error. 93is set to indicate the error.
 94.Pp
 95The functions do not distinguish between end-of-file and error,
 96and callers must use
 97.Xr feof 3
 98and
 99.Xr ferror 3
 100to determine which occurred.
94.Sh EXAMPLE 101.Sh EXAMPLE
95The following code fragment reads lines from a file and writes them to 102The following code fragment reads lines from a file and writes them to
96standard output. 103standard output.
97.Bd -literal -offset indent 104.Bd -literal -offset indent
98char *line = NULL; 105char *line = NULL;
99size_t linesize = 0; 106size_t linesize = 0;
100ssize_t linelen; 107ssize_t linelen;
101while ((linelen = getline(&line, &linesize, fp)) != -1) 108while ((linelen = getline(&line, &linesize, fp)) != -1)
102 fwrite(line, linelen, 1, stdout); 109 fwrite(line, linelen, 1, stdout);
103 110
104if (ferror(fp)) 111if (ferror(fp))
105 perror("getline"); 112 perror("getline");
106.Sh ERRORS 113.Sh ERRORS