confstr() should return 0, not -1, on errors
Thomas E. Spanjaard
tgen at netphreax.net
Tue Dec 5 11:26:13 PST 2006
Guy Harris wrote:
According to
http://www.opengroup.org/onlinepubs/009695399/functions/confstr.html
confstr() should return 0, not (size_t)-1, on errors. The current
DragonFly BSD implementation returns -1 if sysctl() fails.
See attached patch.
Cheers,
--
Thomas E. Spanjaard
tgen at netphreax.net
Index: confstr.3
===================================================================
RCS file: /home/dcvs/src/lib/libc/gen/confstr.3,v
retrieving revision 1.3
diff -u -r1.3 confstr.3
--- confstr.3 26 May 2006 19:39:36 -0000 1.3
+++ confstr.3 5 Dec 2006 18:43:12 -0000
@@ -33,7 +33,7 @@
.\" $FreeBSD: src/lib/libc/gen/confstr.3,v 1.5.2.5 2001/12/14 18:33:50 ru Exp $
.\" $DragonFly: src/lib/libc/gen/confstr.3,v 1.3 2006/05/26 19:39:36 swildner Exp $
.\"
-.Dd June 4, 1993
+.Dd December 5, 2006
.Dt CONFSTR 3
.Os
.Sh NAME
@@ -90,7 +90,7 @@
.Sh RETURN VALUES
If the call to
.Fn confstr
-is not successful, \-1 is returned and
+is not successful, 0 is returned and
.Va errno
is set appropriately.
Otherwise, if the variable does not have a configuration defined value,
@@ -123,6 +123,8 @@
.El
.Sh SEE ALSO
.Xr sysctl 3
+.Rs
+.St -p1003.2
.Sh HISTORY
The
.Fn confstr
Index: confstr.c
===================================================================
RCS file: /home/dcvs/src/lib/libc/gen/confstr.c,v
retrieving revision 1.3
diff -u -r1.3 confstr.c
--- confstr.c 13 Nov 2005 00:07:42 -0000 1.3
+++ confstr.c 5 Dec 2006 18:32:40 -0000
@@ -55,15 +55,18 @@
mib[0] = CTL_USER;
mib[1] = USER_CS_PATH;
if (sysctl(mib, 2, NULL, &tlen, NULL, 0) == -1)
- return (-1);
+ /*
+ * POSIX 1003.2 requires errors to return 0.
+ */
+ return (0);
if (len != 0 && buf != NULL) {
if ((p = malloc(tlen)) == NULL)
- return (-1);
+ return (0); /* POSIX 1003.2 */
if (sysctl(mib, 2, p, &tlen, NULL, 0) == -1) {
sverrno = errno;
free(p);
errno = sverrno;
- return (-1);
+ return (0); /* POSIX 1003.2 */
}
/*
* POSIX 1003.2 requires partial return of
Attachment:
signature.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgp00000.pgp
Type: application/octet-stream
Size: 186 bytes
Desc: "Description: OpenPGP digital signature"
URL: <http://lists.dragonflybsd.org/pipermail/bugs/attachments/20061205/c581c910/attachment-0022.obj>
More information about the Bugs
mailing list