[9] | 1 | /* uname() - get system info Author: Kees J. Bot
|
---|
| 2 | * 7 Nov 1994
|
---|
| 3 | * Returns information about the Minix system. Alas most
|
---|
| 4 | * of it is gathered at compile time, so machine is wrong, and
|
---|
| 5 | * release and version become wrong if not recompiled.
|
---|
| 6 | * More chip types and Minix versions need to be added.
|
---|
| 7 | */
|
---|
| 8 | #define uname _uname
|
---|
| 9 | #define open _open
|
---|
| 10 | #define read _read
|
---|
| 11 | #define close _close
|
---|
| 12 | #include <sys/types.h>
|
---|
| 13 | #include <sys/utsname.h>
|
---|
| 14 | #include <unistd.h>
|
---|
| 15 | #include <fcntl.h>
|
---|
| 16 | #include <string.h>
|
---|
| 17 | #include <errno.h>
|
---|
| 18 | #include <minix/config.h>
|
---|
| 19 | #include <minix/com.h>
|
---|
| 20 | #include <minix/minlib.h>
|
---|
| 21 |
|
---|
| 22 | int uname(name) struct utsname *name;
|
---|
| 23 | {
|
---|
| 24 | int hf, n, err;
|
---|
| 25 | struct kinfo kinfo;
|
---|
| 26 | char *nl;
|
---|
| 27 |
|
---|
| 28 | /* Read the node name from /etc/hostname.file. */
|
---|
| 29 | if ((hf = open("/etc/hostname.file", O_RDONLY)) < 0) {
|
---|
| 30 | if (errno != ENOENT) return(-1);
|
---|
| 31 | strcpy(name->nodename, "noname");
|
---|
| 32 | } else {
|
---|
| 33 | n = read(hf, name->nodename, sizeof(name->nodename) - 1);
|
---|
| 34 | err = errno;
|
---|
| 35 | close(hf);
|
---|
| 36 | errno = err;
|
---|
| 37 | if (n < 0) return(-1);
|
---|
| 38 | name->nodename[n] = 0;
|
---|
| 39 | if ((nl = strchr(name->nodename, '\n')) != NULL) {
|
---|
| 40 | memset(nl, 0, (name->nodename + sizeof(name->nodename)) - nl);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | getsysinfo(PM_PROC_NR, SI_KINFO, &kinfo);
|
---|
| 45 |
|
---|
| 46 | strcpy(name->sysname, "Minix");
|
---|
| 47 | strcpy(name->release, kinfo.release);
|
---|
| 48 | strcpy(name->version, kinfo.version);
|
---|
| 49 | #if (CHIP == INTEL)
|
---|
| 50 | name->machine[0] = 'i';
|
---|
| 51 | strcpy(name->machine + 1, itoa(getprocessor()));
|
---|
| 52 | #if _WORD_SIZE == 4
|
---|
| 53 | strcpy(name->arch, "i386");
|
---|
| 54 | #else
|
---|
| 55 | strcpy(name->arch, "i86");
|
---|
| 56 | #endif
|
---|
| 57 | #endif
|
---|
| 58 | return(0);
|
---|
| 59 | }
|
---|