diff options
author | wollman <wollman@FreeBSD.org> | 1994-10-13 20:31:19 +0000 |
---|---|---|
committer | wollman <wollman@FreeBSD.org> | 1994-10-13 20:31:19 +0000 |
commit | 2cdbc4bdd37c8bf2805f0f1cabb388203be8425c (patch) | |
tree | 141a2a7f1895425643ea9736061da2e85c722203 /lib/libc/gen/uname.c | |
parent | 30cf7d5f6893f88f245b262d7170e95ebd845558 (diff) | |
download | FreeBSD-src-2cdbc4bdd37c8bf2805f0f1cabb388203be8425c.zip FreeBSD-src-2cdbc4bdd37c8bf2805f0f1cabb388203be8425c.tar.gz |
sysctl(3) can return an error (setting errno to ENOMEM) when the
fields in the utsname structure are too small to hold their
corresponding MIB variables. Don't return an error in this case.
Diffstat (limited to 'lib/libc/gen/uname.c')
-rw-r--r-- | lib/libc/gen/uname.c | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/lib/libc/gen/uname.c b/lib/libc/gen/uname.c index 9857b29..1511c1f 100644 --- a/lib/libc/gen/uname.c +++ b/lib/libc/gen/uname.c @@ -32,12 +32,15 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)uname.c 8.1 (Berkeley) 1/4/94"; +/*static char sccsid[] = "From: @(#)uname.c 8.1 (Berkeley) 1/4/94";*/ +static const char rcsid[] = + "$Id$"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> #include <sys/sysctl.h> #include <sys/utsname.h> +#include <errno.h> int uname(name) @@ -46,45 +49,73 @@ uname(name) int mib[2], rval; size_t len; char *p; + int oerrno; rval = 0; mib[0] = CTL_KERN; mib[1] = KERN_OSTYPE; len = sizeof(name->sysname); - if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) - rval = -1; + oerrno = errno; + if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) { + if(errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } mib[0] = CTL_KERN; mib[1] = KERN_HOSTNAME; len = sizeof(name->nodename); - if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) - rval = -1; + oerrno = errno; + if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) { + if(errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } mib[0] = CTL_KERN; mib[1] = KERN_OSRELEASE; len = sizeof(name->release); - if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) - rval = -1; + oerrno = errno; + if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) { + if(errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } /* The version may have newlines in it, turn them into spaces. */ mib[0] = CTL_KERN; mib[1] = KERN_VERSION; len = sizeof(name->version); - if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) - rval = -1; - else - for (p = name->version; len--; ++p) - if (*p == '\n' || *p == '\t') + oerrno = errno; + if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) { + if (errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } else { + for (p = name->version; len--; ++p) { + if (*p == '\n' || *p == '\t') { if (len > 1) *p = ' '; else *p = '\0'; + } + } + } mib[0] = CTL_HW; mib[1] = HW_MACHINE; len = sizeof(name->machine); - if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) - rval = -1; + oerrno = errno; + if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) { + if (errno == ENOMEM) + errno = oerrno; + else + rval = -1; + } return (rval); } |