1 /* `uname.c` - return system name
2 Copyright (c) 2022, Alan Potteiger
3 See `LICENSE` for copyright and license details */
5 #define _POSIX_C_SOURCE 200809L
9 #include <sys/utsname.h>
11 static const char *usage
= {
12 "usage: uname [-amnrsv]\n"
16 main(int argc
, char *argv
[])
22 m
= n
= r
= s
= v
= 0;
24 while ((ch
= getopt(argc
, argv
, "amnrsv")) != -1) {
27 m
= n
= r
= s
= v
= 1;
51 if (uname(&name
) == -1) {
56 if (!(m
|| n
|| r
|| s
|| v
))
59 if (m
&& n
&& r
&& s
&& v
) {
62 name
.sysname
, name
.nodename
, name
.release
,
63 name
.version
, name
.machine
69 /* I think this could be done better or more efficiently. I'm tired
70 as hell though. I'll revisit this at some point */
72 printf("%s ", name
.sysname
);
74 printf("%s ", name
.nodename
);
76 printf("%s ", name
.release
);
78 printf("%s ", name
.version
);
80 printf("%s ", name
.machine
);