. pci driver now returns devices, even when they have been pci_reserve()d
[minix3.git] / lib / posix / _uname.c
blob5ee45dc78b59e8af3a5f2053ca2b509f2420f78d
1 /* uname(3) - describe the machine. Author: Kees J. Bot
2 * 5 Dec 1992
3 */
5 #define uname _uname
6 #include <errno.h>
7 #include <fcntl.h>
8 #include <unistd.h>
9 #include <string.h>
10 #include <sys/types.h>
11 #include <sys/utsname.h>
13 #define uts_get(field, string) \
14 if (sysuname(_UTS_GET, field, name->string, sizeof(name->string)) < 0) \
15 return -1; \
16 name->string[sizeof(name->string)-1]= 0;
18 int uname(name)
19 struct utsname *name;
21 int hf, n, err;
22 char *nl;
24 /* Get each of the strings with a sysuname call. Null terminate them,
25 * because the buffers in the kernel may grow before this and the
26 * programs are recompiled.
28 uts_get(_UTS_SYSNAME, sysname);
29 uts_get(_UTS_NODENAME, nodename);
30 uts_get(_UTS_RELEASE, release);
31 uts_get(_UTS_VERSION, version);
32 uts_get(_UTS_MACHINE, machine);
33 uts_get(_UTS_ARCH, arch);
34 #if 0
35 uts_get(_UTS_KERNEL, kernel);
36 uts_get(_UTS_HOSTNAME, hostname);
37 uts_get(_UTS_BUS, bus);
38 #endif
40 /* Try to read the node name from /etc/hostname.file. This information
41 * should be stored in the kernel.
43 if ((hf = open("/etc/hostname.file", O_RDONLY)) < 0) {
44 if (errno != ENOENT) return(-1);
45 } else {
46 n = read(hf, name->nodename, sizeof(name->nodename) - 1);
47 err = errno;
48 close(hf);
49 errno = err;
50 if (n < 0) return(-1);
51 name->nodename[n] = 0;
52 if ((nl = strchr(name->nodename, '\n')) != NULL) {
53 memset(nl, 0, (name->nodename +
54 sizeof(name->nodename)) - nl);
57 return 0;
61 * $PchId: _uname.c,v 1.4 1995/11/27 20:09:08 philip Exp $