summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>1999-09-26 16:00:35 +0000
committerespie <espie@openbsd.org>1999-09-26 16:00:35 +0000
commit237f250d1616725ddebbaea096642812b2b4e558 (patch)
treecb96710fd3147ac57e8162e511d7e7a55d27ffd3 /lib/libc
parentRemove extraneous comma (diff)
downloadwireguard-openbsd-237f250d1616725ddebbaea096642812b2b4e558.tar.xz
wireguard-openbsd-237f250d1616725ddebbaea096642812b2b4e558.zip
Proper coding idioms.
[yes, there ARE some systems where read and write >SSIZE_MAX work, and physicists use those features to write huge files in one swoop]
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/sys/read.222
-rw-r--r--lib/libc/sys/write.222
2 files changed, 42 insertions, 2 deletions
diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2
index e56ea368702..4c25c984adb 100644
--- a/lib/libc/sys/read.2
+++ b/lib/libc/sys/read.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: read.2,v 1.12 1999/09/26 14:16:31 espie Exp $
+.\" $OpenBSD: read.2,v 1.13 1999/09/26 16:00:35 espie Exp $
.\" $NetBSD: read.2,v 1.6 1995/02/27 12:35:47 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -193,6 +193,26 @@ The
.Fn read
function is expected to conform to
.St -p1003.1-88 .
+.Sh CAVEATS
+Error checks should explicitly test for \-1.
+Code such as
+.Bd -literal
+ while ((nr = read(fd, buf, sizeof buf)) > 0)
+.Ed
+.Pp
+is not maximally portable, as some platforms allow for
+.Va nbytes
+to range between
+.Dv SSIZE_MAX
+and
+.Dv SIZE_MAX
+\- 2, in which case the return value of an error-free
+.Nm read
+may appear as a negative number distinct from \-1.
+Proper loops should use
+.Bd -literal
+ while ((nr = read(fd, buf, sizeof buf)) != -1 && nr != 0)
+.Ed
.Sh HISTORY
The
.Fn readv
diff --git a/lib/libc/sys/write.2 b/lib/libc/sys/write.2
index 13f87e67dd2..ce5e17a3cdb 100644
--- a/lib/libc/sys/write.2
+++ b/lib/libc/sys/write.2
@@ -1,4 +1,4 @@
-.\" $OpenBSD: write.2,v 1.14 1999/09/26 14:16:31 espie Exp $
+.\" $OpenBSD: write.2,v 1.15 1999/09/26 16:00:35 espie Exp $
.\" $NetBSD: write.2,v 1.6 1995/02/27 12:39:43 cgd Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
@@ -221,6 +221,26 @@ The
.Fn write
function is expected to conform to
.St -p1003.1-88 .
+.Sh CAVEATS
+Error checks should explicitly test for \-1.
+Code such as
+.Bd -literal
+ while ((nr = write(fd, buf, sizeof buf)) > 0)
+.Ed
+.Pp
+is not maximally portable, as some platforms allow for
+.Va nbytes
+to range between
+.Dv SSIZE_MAX
+and
+.Dv SIZE_MAX
+\- 2, in which case the return value of an error-free
+.Nm write
+may appear as a negative number distinct from \-1.
+Proper loops should use
+.Bd -literal
+ while ((nr = write(fd, buf, sizeof buf)) != -1 && nr != 0)
+.Ed
.Sh HISTORY
The
.Fn writev