Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/gen/uname.c,v rcsdiff: /ftp/cvs/cvsroot/src/lib/libc/gen/uname.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.1 retrieving revision 1.12 diff -u -p -r1.1 -r1.12 --- src/lib/libc/gen/uname.c 1994/05/07 02:52:59 1.1 +++ src/lib/libc/gen/uname.c 2014/06/14 13:09:37 1.12 @@ -1,3 +1,5 @@ +/* $NetBSD: uname.c,v 1.12 2014/06/14 13:09:37 apb Exp $ */ + /*- * Copyright (c) 1994 * The Regents of the University of California. All rights reserved. @@ -10,11 +12,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,60 +29,86 @@ * SUCH DAMAGE. */ +#include #if defined(LIBC_SCCS) && !defined(lint) +#if 0 static char sccsid[] = "@(#)uname.c 8.1 (Berkeley) 1/4/94"; +#else +__RCSID("$NetBSD: uname.c,v 1.12 2014/06/14 13:09:37 apb Exp $"); +#endif #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include +#include +#include + +#ifdef __weak_alias +__weak_alias(uname,_uname) +#endif + int -uname(name) - struct utsname *name; +uname(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'; + if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) { + if (errno == ENOMEM) { + /* + * string is too long for {struct utsname}.version. + * Just use the truncated string. + * XXX: We could mark the truncation with "..." + */ + name->version[sizeof(name->version) - 1] = '\0'; + } + else 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); }