Author: rmh Date: 2006-01-18 23:27:24 +0000 (Wed, 18 Jan 2006) New Revision: 1073
Modified: trunk/glibc-2.3-head/sysdeps/kfreebsd/uname.c Log: Rewrite uname.c to use SYS_uname. Runs 1.54 faster. Modified: trunk/glibc-2.3-head/sysdeps/kfreebsd/uname.c =================================================================== --- trunk/glibc-2.3-head/sysdeps/kfreebsd/uname.c 2006-01-18 19:56:23 UTC (rev 1072) +++ trunk/glibc-2.3-head/sysdeps/kfreebsd/uname.c 2006-01-18 23:27:24 UTC (rev 1073) @@ -1,6 +1,6 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. +/* Copyright (C) 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. - Contributed by Bruno Haible <[EMAIL PROTECTED]>, 2002. + Contributed by Robert Millan <[EMAIL PROTECTED]> The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -17,110 +17,28 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <sys/syscall.h> #include <sys/utsname.h> -#include <sys/sysctl.h> -#include <errno.h> #include <string.h> -/* Dummy values used as a fallback. */ -#define UNAME_SYSNAME "GNU/kFreeBSD" -#define UNAME_RELEASE "4.0" -#define UNAME_VERSION "GENERIC" -#define UNAME_MACHINE "mmix" +#define SYSNAME "GNU/kFreeBSD" +#define SYSNAME_LEN 13 -/* Put information about the system in NAME. */ +/* Check for bounds in pre-processor */ +#if SYSNAME_LEN > _UTSNAME_SYSNAME_LENGTH +#error +#endif + int -__uname (struct utsname *name) +__uname (struct utsname *uname) { - /* Fill nodename: "uname -n". Fetch sysctl "kern.hostname". */ - { - int request[2] = { CTL_KERN, KERN_HOSTNAME }; - size_t len = sizeof (name->nodename); - if (__sysctl (request, 2, name->nodename, &len, NULL, 0) >= 0) - { - if (len < sizeof (name->nodename)) - name->nodename[len] = '\0'; - } - else - { - if (errno != ENOMEM) - strncpy (name->nodename, "localhost", sizeof (name->nodename)); - } - } + if (syscall (SYS_uname, uname) == -1) + return -1; - /* Fill sysname: "uname -s". Fetch sysctl "kern.ostype". */ - { - strncpy (name->sysname, UNAME_SYSNAME, sizeof (name->sysname)); - } + strcpy (uname->sysname, SYSNAME); - /* Fill release: "uname -r". Fetch sysctl "kern.osrelease". */ - { - int request[2] = { CTL_KERN, KERN_OSRELEASE }; - size_t len = sizeof (name->release); - if (__sysctl (request, 2, name->release, &len, NULL, 0) >= 0) - { - if (len < sizeof (name->release)) - name->release[len] = '\0'; - } - else - { - if (errno != ENOMEM) - strncpy (name->release, UNAME_RELEASE, sizeof (name->release)); - } - } - - /* Fill version: "uname -v". Fetch sysctl "kern.version". */ - { - int request[2] = { CTL_KERN, KERN_VERSION }; - size_t len = sizeof (name->version); - if (__sysctl (request, 2, name->version, &len, NULL, 0) >= 0) - { - if (len < sizeof (name->version)) - name->version[len] = '\0'; - } - else - { - if (errno != ENOMEM) - strncpy (name->version, UNAME_VERSION, sizeof (name->version)); - } - - /* Remove trailing whitespace. Turn non-trailing whitespace to - spaces. */ - { - char *p0 = name->version; - char *p = p0 + __strnlen (p0, sizeof (name->version)); - - while (p > p0 && (p[-1] == '\t' || p[-1] == '\n' || p[-1] == ' ')) - *--p = '\0'; - - while (p > p0) - { - --p; - if (*p == '\t' || *p == '\n') - *p = ' '; - } - } - } - - /* Fill machine: "uname -m". Fetch sysctl "hw.machine". */ - { - int request[2] = { CTL_HW, HW_MACHINE }; - size_t len = sizeof (name->machine); - if (__sysctl (request, 2, name->machine, &len, NULL, 0) >= 0) - { - if (len < sizeof (name->machine)) - name->machine[len] = '\0'; - } - else - { - if (errno != ENOMEM) - strncpy (name->machine, UNAME_MACHINE, sizeof (name->machine)); - } - } - return 0; } -libc_hidden_def (__uname) - weak_alias (__uname, uname) +libc_hidden_def (__uname) libc_hidden_def (uname) -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]