From b0ae9b37424255b4943e224b9200ec99351b8667 Mon Sep 17 00:00:00 2001 From: "Thomas E. Spanjaard" Date: Wed, 6 Dec 2006 11:58:57 +0000 Subject: [PATCH] Fix a bug in our confstr(3) implementation, it did not conform to POSIX 1003.2. It returned -1 for errors where it should have returned 0. Also, fix the only consumer of confstr(3) in our tree, getconf(1). Dragonfly-bug: Reviewed-by: Victor Balada Diaz --- lib/libc/gen/confstr.3 | 8 +++++--- lib/libc/gen/confstr.c | 11 +++++++---- usr.bin/getconf/getconf.c | 5 +++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/libc/gen/confstr.3 b/lib/libc/gen/confstr.3 index c6bea6b7e5..986a4cbd75 100644 --- a/lib/libc/gen/confstr.3 +++ b/lib/libc/gen/confstr.3 @@ -31,9 +31,9 @@ .\" .\" @(#)confstr.3 8.1 (Berkeley) 6/4/93 .\" $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 $ +.\" $DragonFly: src/lib/libc/gen/confstr.3,v 1.4 2006/12/06 11:58:57 tgen Exp $ .\" -.Dd June 4, 1993 +.Dd December 5, 2006 .Dt CONFSTR 3 .Os .Sh NAME @@ -90,7 +90,7 @@ environment variable that finds all the standard utilities. .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 @@ argument is invalid. .El .Sh SEE ALSO .Xr sysctl 3 +.Rs +.St -p1003.2 .Sh HISTORY The .Fn confstr diff --git a/lib/libc/gen/confstr.c b/lib/libc/gen/confstr.c index 07f28b97c1..9206da9c2c 100644 --- a/lib/libc/gen/confstr.c +++ b/lib/libc/gen/confstr.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)confstr.c 8.1 (Berkeley) 6/4/93 - * $DragonFly: src/lib/libc/gen/confstr.c,v 1.3 2005/11/13 00:07:42 swildner Exp $ + * $DragonFly: src/lib/libc/gen/confstr.c,v 1.4 2006/12/06 11:58:57 tgen Exp $ */ #include @@ -55,15 +55,18 @@ confstr(int name, char *buf, size_t len) 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 diff --git a/usr.bin/getconf/getconf.c b/usr.bin/getconf/getconf.c index 4c3db534cc..b96012b84d 100644 --- a/usr.bin/getconf/getconf.c +++ b/usr.bin/getconf/getconf.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/usr.bin/getconf/getconf.c,v 1.6.2.1 2002/10/27 04:18:40 wollman Exp $ - * $DragonFly: src/usr.bin/getconf/getconf.c,v 1.3 2003/11/04 20:25:45 dillon Exp $ + * $DragonFly: src/usr.bin/getconf/getconf.c,v 1.4 2006/12/06 11:58:57 tgen Exp $ */ #include @@ -141,8 +141,9 @@ do_confstr(const char *name, int key) char *buf; size_t len; + errno = 0; len = confstr(key, 0, 0); - if (len == (size_t)-1) + if (len == 0 && errno != 0) err(EX_OSERR, "confstr: %s", name); if (len == 0) { -- 2.41.0