sbase/uname.c

72 lines
1.1 KiB
C
Raw Normal View History

2011-06-02 19:32:05 +00:00
/* See LICENSE file for copyright and license details. */
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/utsname.h>
#include "util.h"
2011-06-08 23:40:23 +00:00
static void print(const char *);
2011-06-02 19:32:05 +00:00
int
main(int argc, char *argv[])
{
bool mflag = false;
bool nflag = false;
bool rflag = false;
bool sflag = false;
bool vflag = false;
char c;
struct utsname u;
while((c = getopt(argc, argv, "amnrsv")) != -1)
switch(c) {
case 'a':
mflag = nflag = rflag = sflag = vflag = true;
break;
case 'm':
mflag = true;
break;
case 'n':
nflag = true;
break;
case 'r':
rflag = true;
break;
case 's':
sflag = true;
break;
case 'v':
vflag = true;
break;
default:
exit(EXIT_FAILURE);
}
2011-06-04 11:20:41 +00:00
if(uname(&u) == -1)
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-08 23:40:23 +00:00
print(u.sysname);
2011-06-02 19:32:05 +00:00
if(nflag)
2011-06-08 23:40:23 +00:00
print(u.nodename);
2011-06-02 19:32:05 +00:00
if(rflag)
2011-06-08 23:40:23 +00:00
print(u.release);
2011-06-02 19:32:05 +00:00
if(vflag)
2011-06-08 23:40:23 +00:00
print(u.version);
2011-06-02 19:32:05 +00:00
if(mflag)
2011-06-08 23:40:23 +00:00
print(u.machine);
2011-06-02 19:32:05 +00:00
putchar('\n');
return EXIT_SUCCESS;
}
2011-06-08 23:40:23 +00:00
void
print(const char *s)
{
static bool first = true;
if(!first)
putchar(' ');
fputs(s, stdout);
first = false;
}