Documentation!

This commit is contained in:
Kat R. 2022-10-09 11:41:27 -05:00
parent 4025416fd1
commit a9e7490a87
2 changed files with 14 additions and 8 deletions

1
tty.c
View File

@ -5,6 +5,7 @@
#include <stdio.h>
int main() {
/* Check if we're in a tty and, if so, print the devfile for it. */
if(isatty(fileno(stdin))) {
printf("%s\n", ttyname(0));
return 0;

21
uname.c
View File

@ -15,16 +15,18 @@ int main(int argc, char * argv[]) {
int stuff_printed = 0;
char c;
/*
For stuff_print:
01: -m
02: -n
04: -r
010: -s
020: -v
037: -a
This variable holds what all we need to print, corresponding
to the following options:
01: -m (Machine type)
02: -n (Hostname)
04: -r (Release)
010: -s (Operating system)
020: -v (Version)
037: -a (Everything)
*/
int stuff_print = 0;
/* Get options */
while((c = getopt(argc, argv, "amnrsv")) != -1) {
switch(c) {
case 'm': stuff_print |= 01; break;
@ -34,20 +36,23 @@ int main(int argc, char * argv[]) {
case 'v': stuff_print |= 020; break;
case 'a': stuff_print |= 037; break;
}
/* If we saw -a, then just leave, we're done here. */
if(c == 'a') { break; }
}
/* If no options specified, print OS name */
if(stuff_print == 0) {
stuff_print = 010;
}
int got_uname = 0;
got_uname = uname(sys_name);
got_uname = uname(sys_name); /* Try to get the utsname struct */
if(got_uname == -1) {
fprintf(stderr, "%s: could not get uname\n", argv[0]);
return 1;
}
/* Print everything and trailing newline */
if(stuff_print & 010) {
printf("%s ", sys_name->sysname);
}