# HG changeset patch # User Richard Lowe # Date 1308788604 25200 # Node ID 8bbc95af7713ee2cb681ad092130d824e0408733 # Parent d4e1700ca0911eac75adab98d166cc9c6ff4db89 2062 libbc uname() deals with nodename/nodeext distastefully Reviewed by: Joshua M. Clulow Reviewed by: Alexander Eremin Reviewed by: Robert Mustacchi Approved by: Gordon Ross diff -r d4e1700ca091 -r 8bbc95af7713 usr/src/lib/libbc/libc/sys/common/uname.c --- a/usr/src/lib/libbc/libc/sys/common/uname.c Fri Feb 03 20:27:13 2012 +0100 +++ b/usr/src/lib/libbc/libc/sys/common/uname.c Wed Jun 22 17:23:24 2011 -0700 @@ -24,23 +24,21 @@ * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include #include #include #include -/* +/* * utsname structure has a different format in SVr4/SunOS 5.0. * The data needs to be mapped before returning to the user. */ -/* +/* * The following values and structure are from the SVR4 utsname.h. */ #define NEW_SYS_NMLN 257 -#define SYS_NMLN 9 +#define SYS_NMLN 9 #define SYS_NDLN 65 struct n_utsname { @@ -51,14 +49,14 @@ char machine[NEW_SYS_NMLN]; }; -int uname( uts ) -register struct utsname *uts; /* where to put results */ +int +uname(struct utsname *uts) { - return(bc_uname(uts)); + return (bc_uname(uts)); } -int bc_uname( uts ) -struct utsname *uts; +int +bc_uname(struct utsname *uts) { struct n_utsname n_uts; int ret; @@ -67,9 +65,18 @@ memcpy(uts->sysname, n_uts.sysname, SYS_NMLN); if (strlen(n_uts.sysname) > SYS_NMLN) uts->sysname[SYS_NMLN-1] = '\0'; - memcpy(uts->nodename, n_uts.nodename, SYS_NDLN); + + /* + * The nodename was originally 9 bytes (including NUL), but a + * field was added, following it, extending it to SYS_NDLN. + * So we have to copy it in two passes + */ + memcpy(uts->nodename, n_uts.nodename, SYS_NMLN); + memcpy(uts->nodeext, n_uts.nodename + SYS_NMLN, + SYS_NDLN - SYS_NMLN); if (strlen(n_uts.nodename) > SYS_NDLN) - uts->nodename[SYS_NDLN-1] = '\0'; + uts->nodeext[sizeof (uts->nodeext) - 1] = '\0'; + memcpy(uts->release, n_uts.release, SYS_NMLN); if (strlen(n_uts.release) > SYS_NMLN) uts->release[SYS_NMLN-1] = '\0'; @@ -81,5 +88,5 @@ uts->machine[SYS_NMLN-1] = '\0'; } - return(ret); + return (ret); }