Importing usr.bin/uname
Change-Id: I4c316221e288edd839e26a2af4cb59f28bf722c1
This commit is contained in:
@@ -27,7 +27,7 @@ SUBDIR= add_route arp ash at backup btrace \
|
||||
stty svclog svrctl swifi synctree sysenv \
|
||||
syslogd tail tcpd tcpdp tcpstat telnet \
|
||||
telnetd term termcap tget time touch \
|
||||
truncate udpstat umount uname \
|
||||
truncate udpstat umount \
|
||||
unstack update uud uue version vol \
|
||||
whereis which writeisofs fetch \
|
||||
zdump zmodem pkgin_cd pkgin_all \
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
PROG= uname
|
||||
MAN=
|
||||
|
||||
LINKS+= ${BINDIR}/uname ${BINDIR}/arch
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
@@ -1,128 +0,0 @@
|
||||
/* uname - print system name Author: Earl Chew */
|
||||
|
||||
/* Print the following system information as returned by the uname()
|
||||
* function:
|
||||
*
|
||||
* system name Minix
|
||||
* node name 10.0.2.15
|
||||
* release name 3.2.1
|
||||
* version Minix 3.2.1 (GENERIC)
|
||||
* machine name i686
|
||||
* arch i386 (Minix specific)
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Define the uname components. */
|
||||
#define ALL ((unsigned) 0x1F)
|
||||
#define SYSNAME ((unsigned) 0x01)
|
||||
#define NODENAME ((unsigned) 0x02)
|
||||
#define RELEASE ((unsigned) 0x04)
|
||||
#define VERSION ((unsigned) 0x08)
|
||||
#define U_MACHINE ((unsigned) 0x10)
|
||||
#define ARCH ((unsigned) 0x20)
|
||||
|
||||
int main(int argc, char **argv );
|
||||
void print(int fd, ... );
|
||||
void usage(void );
|
||||
|
||||
#ifdef __STDC__
|
||||
void print(int fd, ...)
|
||||
#else
|
||||
void print(fd)
|
||||
int fd;
|
||||
#endif
|
||||
{
|
||||
/* Print a sequence of strings onto the named channel. */
|
||||
va_list argp;
|
||||
char *p;
|
||||
|
||||
va_start(argp, fd);
|
||||
while (1) {
|
||||
p = va_arg(argp, char *);
|
||||
if (p == (char *) NULL) break;
|
||||
write(fd, p, strlen(p));
|
||||
}
|
||||
va_end(argp);
|
||||
}
|
||||
|
||||
char *name;
|
||||
|
||||
void usage()
|
||||
{
|
||||
print(STDERR_FILENO, "Usage: ", name, " -snrvmpa\n", (char *) NULL);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
int info;
|
||||
char *p;
|
||||
struct utsname un;
|
||||
|
||||
name = strrchr(argv[0], '/');
|
||||
if (name == NULL) name = argv[0]; else name++;
|
||||
|
||||
for (info = 0; argc > 1; argc--, argv++) {
|
||||
if (argv[1][0] == '-') {
|
||||
for (p = &argv[1][1]; *p; p++) {
|
||||
switch (*p) {
|
||||
case 'a': info |= ALL; break;
|
||||
case 'm': info |= U_MACHINE; break;
|
||||
case 'n': info |= NODENAME; break;
|
||||
case 'r': info |= RELEASE; break;
|
||||
case 's': info |= SYSNAME; break;
|
||||
case 'v': info |= VERSION; break;
|
||||
case 'p': info |= ARCH; break;
|
||||
default: usage();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (info == 0) info = strcmp(name, "arch") == 0 ? ARCH : SYSNAME;
|
||||
|
||||
if (uname(&un) != 0) {
|
||||
print(STDERR_FILENO, "unable to determine uname values\n", (char *) NULL);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if ((info & SYSNAME) != 0)
|
||||
print(STDOUT_FILENO, un.sysname, (char *) NULL);
|
||||
if ((info & NODENAME) != 0) {
|
||||
if ((info & (SYSNAME)) != 0)
|
||||
print(STDOUT_FILENO, " ", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.nodename, (char *) NULL);
|
||||
}
|
||||
if ((info & RELEASE) != 0) {
|
||||
if ((info & (SYSNAME|NODENAME)) != 0)
|
||||
print(STDOUT_FILENO, " ", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.release, (char *) NULL);
|
||||
}
|
||||
if ((info & VERSION) != 0) {
|
||||
if ((info & (SYSNAME|NODENAME|RELEASE)) != 0)
|
||||
print(STDOUT_FILENO, " ", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.version, (char *) NULL);
|
||||
}
|
||||
if ((info & U_MACHINE) != 0) {
|
||||
if ((info & (SYSNAME|NODENAME|RELEASE|VERSION)) != 0)
|
||||
print(STDOUT_FILENO, " ", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.machine, (char *) NULL);
|
||||
}
|
||||
if ((info & ARCH) != 0) {
|
||||
if ((info & (SYSNAME|NODENAME|RELEASE|VERSION|U_MACHINE)) != 0)
|
||||
print(STDOUT_FILENO, " ", (char *) NULL);
|
||||
print(STDOUT_FILENO, un.arch, (char *) NULL);
|
||||
}
|
||||
print(STDOUT_FILENO, "\n", (char *) NULL);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user