Bail out on the first sysctl() error as suggested by Pierre Pronchery in

PR lib/35403. christos agreed it's cleaner.
This commit is contained in:
cbiere 2007-01-15 22:26:35 +00:00
parent 2148d49b3a
commit f13e324ee5

View File

@ -1,4 +1,4 @@
/* $NetBSD: uname.c,v 1.9 2003/08/07 16:42:59 agc Exp $ */
/* $NetBSD: uname.c,v 1.10 2007/01/15 22:26:35 cbiere Exp $ */
/*-
* Copyright (c) 1994
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)uname.c 8.1 (Berkeley) 1/4/94";
#else
__RCSID("$NetBSD: uname.c,v 1.9 2003/08/07 16:42:59 agc Exp $");
__RCSID("$NetBSD: uname.c,v 1.10 2007/01/15 22:26:35 cbiere Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@ -54,52 +54,53 @@ int
uname(name)
struct utsname *name;
{
int mib[2], rval;
int mib[2];
size_t len;
char *p;
rval = 0;
_DIAGASSERT(name != NULL);
mib[0] = CTL_KERN;
mib[1] = KERN_OSTYPE;
len = sizeof(name->sysname);
if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1)
rval = -1;
goto error;
mib[0] = CTL_KERN;
mib[1] = KERN_HOSTNAME;
len = sizeof(name->nodename);
if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1)
rval = -1;
goto error;
mib[0] = CTL_KERN;
mib[1] = KERN_OSRELEASE;
len = sizeof(name->release);
if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1)
rval = -1;
goto error;
/* 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') {
if (len > 1)
*p = ' ';
else
*p = '\0';
}
goto error;
/* The version may have newlines in it, turn them into spaces. */
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;
return (rval);
goto error;
return (0);
error:
return (-1);
}