2006-05-19 14:19:37 +02:00
|
|
|
/* uname(3) - describe the machine. Author: Kees J. Bot
|
|
|
|
* 5 Dec 1992
|
2005-04-21 16:53:53 +02:00
|
|
|
*/
|
2006-05-19 14:19:37 +02:00
|
|
|
|
|
|
|
#define uname _uname
|
|
|
|
#include <errno.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <fcntl.h>
|
2006-05-19 14:19:37 +02:00
|
|
|
#include <unistd.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
#include <string.h>
|
2006-05-19 14:19:37 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/utsname.h>
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-05-19 14:19:37 +02:00
|
|
|
#define uts_get(field, string) \
|
|
|
|
if (sysuname(_UTS_GET, field, name->string, sizeof(name->string)) < 0) \
|
|
|
|
return -1; \
|
|
|
|
name->string[sizeof(name->string)-1]= 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-05-19 14:19:37 +02:00
|
|
|
int uname(name)
|
|
|
|
struct utsname *name;
|
|
|
|
{
|
|
|
|
int hf, n, err;
|
|
|
|
char *nl;
|
2005-04-21 16:53:53 +02:00
|
|
|
|
2006-05-19 14:19:37 +02:00
|
|
|
/* Get each of the strings with a sysuname call. Null terminate them,
|
|
|
|
* because the buffers in the kernel may grow before this and the
|
|
|
|
* programs are recompiled.
|
|
|
|
*/
|
|
|
|
uts_get(_UTS_SYSNAME, sysname);
|
|
|
|
uts_get(_UTS_NODENAME, nodename);
|
|
|
|
uts_get(_UTS_RELEASE, release);
|
|
|
|
uts_get(_UTS_VERSION, version);
|
|
|
|
uts_get(_UTS_MACHINE, machine);
|
|
|
|
uts_get(_UTS_ARCH, arch);
|
|
|
|
#if 0
|
|
|
|
uts_get(_UTS_KERNEL, kernel);
|
|
|
|
uts_get(_UTS_HOSTNAME, hostname);
|
|
|
|
uts_get(_UTS_BUS, bus);
|
2005-04-21 16:53:53 +02:00
|
|
|
#endif
|
2006-05-19 14:19:37 +02:00
|
|
|
|
|
|
|
/* Try to read the node name from /etc/hostname.file. This information
|
|
|
|
* should be stored in the kernel.
|
|
|
|
*/
|
|
|
|
if ((hf = open("/etc/hostname.file", O_RDONLY)) < 0) {
|
|
|
|
if (errno != ENOENT) return(-1);
|
|
|
|
} else {
|
|
|
|
n = read(hf, name->nodename, sizeof(name->nodename) - 1);
|
|
|
|
err = errno;
|
|
|
|
close(hf);
|
|
|
|
errno = err;
|
|
|
|
if (n < 0) return(-1);
|
|
|
|
name->nodename[n] = 0;
|
|
|
|
if ((nl = strchr(name->nodename, '\n')) != NULL) {
|
|
|
|
memset(nl, 0, (name->nodename +
|
|
|
|
sizeof(name->nodename)) - nl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2005-04-21 16:53:53 +02:00
|
|
|
}
|
2006-05-19 14:19:37 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* $PchId: _uname.c,v 1.4 1995/11/27 20:09:08 philip Exp $
|
|
|
|
*/
|