1 /* Copyright (C) 2002, 2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Bruno Haible <bruno@clisp.org>.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 #include <sys/utsname.h>
21 #include <sys/sysctl.h>
25 #define SYSNAME "GNU/kFreeBSD"
26 #define SYSNAME_LEN 13
28 /* Check for bounds in pre-processor */
29 #if SYSNAME_LEN > _UTSNAME_SYSNAME_LENGTH
33 /* Put information about the system in NAME. */
35 __uname (struct utsname
*name
)
37 int request
[2] = { CTL_KERN
};
40 /* Fill sysname: "uname -s". */
41 strcpy (name
->sysname
, SYSNAME
);
43 /* Fill nodename: "uname -n". Fetch sysctl "kern.hostname". */
44 request
[1] = KERN_HOSTNAME
;
45 len
= sizeof (name
->nodename
);
46 if (__sysctl (request
, 2, name
->nodename
, &len
, NULL
, 0) >= 0)
48 if (len
< sizeof (name
->nodename
))
49 name
->nodename
[len
] = '\0';
52 /* Fill release: "uname -r". Fetch sysctl "kern.osrelease". */
53 request
[1] = KERN_OSRELEASE
;
54 len
= sizeof (name
->release
);
55 if (__sysctl (request
, 2, name
->release
, &len
, NULL
, 0) >= 0)
57 if (len
< sizeof (name
->release
))
58 name
->release
[len
] = '\0';
61 /* Fill version: "uname -v". Fetch sysctl "kern.version". */
62 request
[1] = KERN_VERSION
;
63 len
= sizeof (name
->version
);
64 if (__sysctl (request
, 2, name
->version
, &len
, NULL
, 0) >= 0)
66 if (len
< sizeof (name
->version
))
67 name
->version
[len
] = '\0';
70 /* Remove trailing whitespace. Turn non-trailing whitespace to
73 char *p0
= name
->version
;
74 char *p
= p0
+ __strnlen (p0
, sizeof (name
->version
));
76 while (p
> p0
&& (p
[-1] == '\t' || p
[-1] == '\n' || p
[-1] == ' '))
82 if (*p
== '\t' || *p
== '\n')
88 /* Check for bounds in pre-processor */
89 # if 7 > _UTSNAME_MACHINE_LENGTH
92 /* Pristine FreeBSD kernel would return "amd64". Avoid that. */
93 strcpy (name
->machine
, "x86_64");
95 /* Fill machine: "uname -m". Fetch sysctl "hw.machine". */
97 request
[1] = HW_MACHINE
;
98 len
= sizeof (name
->machine
);
99 if (__sysctl (request
, 2, name
->machine
, &len
, NULL
, 0) >= 0)
101 if (len
< sizeof (name
->machine
))
102 name
->machine
[len
] = '\0';
108 libc_hidden_def (__uname
)
109 weak_alias (__uname
, uname
)
110 libc_hidden_def (uname
)