[BACK]Return to uname.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gen

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libc/gen/uname.c between version 1.1 and 1.12

version 1.1, 1994/05/07 02:52:59 version 1.12, 2014/06/14 13:09:37
Line 1 
Line 1 
   /*      $NetBSD$        */
   
 /*-  /*-
  * Copyright (c) 1994   * Copyright (c) 1994
  *      The Regents of the University of California.  All rights reserved.   *      The Regents of the University of California.  All rights reserved.
Line 10 
Line 12 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software   * 3. Neither the name of the University nor the names of its contributors
  *    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  
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
Line 31 
Line 29 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
   #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)  #if defined(LIBC_SCCS) && !defined(lint)
   #if 0
 static char sccsid[] = "@(#)uname.c     8.1 (Berkeley) 1/4/94";  static char sccsid[] = "@(#)uname.c     8.1 (Berkeley) 1/4/94";
   #else
   __RCSID("$NetBSD$");
   #endif
 #endif /* LIBC_SCCS and not lint */  #endif /* LIBC_SCCS and not lint */
   
   #include "namespace.h"
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/sysctl.h>  #include <sys/sysctl.h>
 #include <sys/utsname.h>  #include <sys/utsname.h>
   
   #include <assert.h>
   #include <errno.h>
   
   #ifdef __weak_alias
   __weak_alias(uname,_uname)
   #endif
   
 int  int
 uname(name)  uname(struct utsname *name)
         struct utsname *name;  
 {  {
         int mib[2], rval;          int mib[2];
         size_t len;          size_t len;
         char *p;          char *p;
   
         rval = 0;          _DIAGASSERT(name != NULL);
   
         mib[0] = CTL_KERN;          mib[0] = CTL_KERN;
         mib[1] = KERN_OSTYPE;          mib[1] = KERN_OSTYPE;
         len = sizeof(name->sysname);          len = sizeof(name->sysname);
         if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1)          if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1)
                 rval = -1;                  goto error;
   
         mib[0] = CTL_KERN;          mib[0] = CTL_KERN;
         mib[1] = KERN_HOSTNAME;          mib[1] = KERN_HOSTNAME;
         len = sizeof(name->nodename);          len = sizeof(name->nodename);
         if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1)          if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1)
                 rval = -1;                  goto error;
   
         mib[0] = CTL_KERN;          mib[0] = CTL_KERN;
         mib[1] = KERN_OSRELEASE;          mib[1] = KERN_OSRELEASE;
         len = sizeof(name->release);          len = sizeof(name->release);
         if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1)          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[0] = CTL_KERN;
         mib[1] = KERN_VERSION;          mib[1] = KERN_VERSION;
         len = sizeof(name->version);          len = sizeof(name->version);
         if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1)          if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) {
                 rval = -1;                  if (errno == ENOMEM) {
         else                          /*
                 for (p = name->version; len--; ++p)                           * string is too long for {struct utsname}.version.
                         if (*p == '\n' || *p == '\t')                           * Just use the truncated string.
                                 if (len > 1)                           * XXX: We could mark the truncation with "..."
                                         *p = ' ';                           */
                                 else                          name->version[sizeof(name->version) - 1] = '\0';
                                         *p = '\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[0] = CTL_HW;
         mib[1] = HW_MACHINE;          mib[1] = HW_MACHINE;
         len = sizeof(name->machine);          len = sizeof(name->machine);
         if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1)          if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1)
                 rval = -1;                  goto error;
         return (rval);          return (0);
   
   error:
           return (-1);
 }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.12

CVSweb <webmaster@jp.NetBSD.org>