From a9e7490a8756deb811ad4c1f41df3855010b8e45 Mon Sep 17 00:00:00 2001 From: Kat Richey Date: Sun, 9 Oct 2022 11:41:27 -0500 Subject: [PATCH] Documentation! --- tty.c | 1 + uname.c | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tty.c b/tty.c index 76ecf67..7334710 100755 --- a/tty.c +++ b/tty.c @@ -5,6 +5,7 @@ #include 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; diff --git a/uname.c b/uname.c index fe79578..41a2492 100644 --- a/uname.c +++ b/uname.c @@ -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); }