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

21
uname.c
View File

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