It works!!!

This commit is contained in:
Gitea 2020-12-11 07:19:04 -06:00
parent 33b2891adc
commit f510192587

79
uname.c Normal file
View file

@ -0,0 +1,79 @@
#include <stdio.h>
#include <sys/utsname.h>
#include <stdlib.h>
/*
Ah, yes. Stuff just to satisfy the GNU project.
I look forward to the day we can start doing
development on our own system with our own
C library. I should really work on that.
-Kat
*/
#ifdef __GLIBC__
#define __USE_POSIX2
#endif
#include <unistd.h>
int main(int argc, char * argv[]) {
/* The utsname struct has to be preallocated for uname() to work. */
struct utsname * sys_name = malloc(sizeof(*sys_name));
if(sys_name == NULL) {
fprintf(stderr, "%s: insufficient memory\n", argv[0]);
return 2;
}
int stuff_printed = 0;
char c;
/*
For stuff_print:
01: -m
02: -n
04: -r
010: -s
020: -v
037: -a
*/
int stuff_print = 0;
while((c = getopt(argc, argv, "amnrsv")) != -1) {
switch(c) {
case 'm': stuff_print |= 01; break;
case 'n': stuff_print |= 02; break;
case 'r': stuff_print |= 04; break;
case 's': stuff_print |= 010; break;
case 'v': stuff_print |= 020; break;
case 'a': stuff_print |= 037; break;
}
if(c == 'a') { break; }
}
if(stuff_print == 0) {
stuff_print = 010;
}
int got_uname = 0;
got_uname = uname(sys_name);
if(got_uname == -1) {
fprintf(stderr, "%s: could not get uname\n", argv[0]);
return 1;
}
if(stuff_print & 010) {
printf("%s ", sys_name->sysname);
}
if(stuff_print & 02) {
printf("%s ", sys_name->nodename);
}
if(stuff_print & 04) {
printf("%s ", sys_name->release);
}
if(stuff_print & 020) {
printf("%s ", sys_name->version);
}
if(stuff_print & 01) {
printf("%s", sys_name->machine);
}
printf("\n");
return 0;
}