sbase/uname.c

64 lines
924 B
C
Raw Normal View History

2011-06-02 19:32:05 +00:00
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
#include <unistd.h>
2011-06-02 19:32:05 +00:00
#include "util.h"
2013-06-14 18:20:47 +00:00
static void
usage(void)
{
eprintf("usage: %s [-amnrsv]\n", argv0);
}
2011-06-02 19:32:05 +00:00
int
main(int argc, char *argv[])
{
int mflag = 0;
int nflag = 0;
int rflag = 0;
int sflag = 0;
int vflag = 0;
2011-06-02 19:32:05 +00:00
struct utsname u;
2013-06-14 18:20:47 +00:00
ARGBEGIN {
case 'a':
mflag = nflag = rflag = sflag = vflag = 1;
2013-06-14 18:20:47 +00:00
break;
case 'm':
mflag = 1;
2013-06-14 18:20:47 +00:00
break;
case 'n':
nflag = 1;
2013-06-14 18:20:47 +00:00
break;
case 'r':
rflag = 1;
2013-06-14 18:20:47 +00:00
break;
case 's':
sflag = 1;
2013-06-14 18:20:47 +00:00
break;
case 'v':
vflag = 1;
2013-06-14 18:20:47 +00:00
break;
default:
usage();
} ARGEND;
if (uname(&u) < 0)
2011-06-02 20:15:35 +00:00
eprintf("uname:");
2011-06-02 19:32:05 +00:00
if (sflag || !(nflag || rflag || vflag || mflag))
2011-06-10 01:56:13 +00:00
putword(u.sysname);
if (nflag)
2011-06-10 01:56:13 +00:00
putword(u.nodename);
if (rflag)
2011-06-10 01:56:13 +00:00
putword(u.release);
if (vflag)
2011-06-10 01:56:13 +00:00
putword(u.version);
if (mflag)
2011-06-10 01:56:13 +00:00
putword(u.machine);
2011-06-02 19:32:05 +00:00
putchar('\n');
2013-06-14 18:20:47 +00:00
2014-10-02 22:46:04 +00:00
return 0;
2011-06-02 19:32:05 +00:00
}