diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-10-26 14:56:21 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-10-26 14:57:26 +0200 |
commit | 1c45b28da6e74aeacace16817e6b7481a547a9e7 (patch) | |
tree | ce89a53c775f1497362314b9f7d606c160b336b6 /Userland | |
parent | 384e2f24d41aad4ad42aa6eff7783e924fea98fc (diff) | |
download | serenity-1c45b28da6e74aeacace16817e6b7481a547a9e7.zip |
Add sys$uname() and a /bin/uname utility.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/.gitignore | 1 | ||||
-rw-r--r-- | Userland/Makefile | 9 | ||||
-rw-r--r-- | Userland/uname.cpp | 46 |
3 files changed, 54 insertions, 2 deletions
diff --git a/Userland/.gitignore b/Userland/.gitignore index 2c52d710f8..fd9204f785 100644 --- a/Userland/.gitignore +++ b/Userland/.gitignore @@ -10,3 +10,4 @@ false true hostname cat +uname diff --git a/Userland/Makefile b/Userland/Makefile index d433c7422d..9798053d6d 100644 --- a/Userland/Makefile +++ b/Userland/Makefile @@ -9,7 +9,8 @@ OBJS = \ true.o \ false.o \ hostname.o \ - cat.o + cat.o \ + uname.o APPS = \ id \ @@ -22,7 +23,8 @@ APPS = \ true \ false \ hostname \ - cat + cat \ + uname ARCH_FLAGS = STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib @@ -75,6 +77,9 @@ hostname: hostname.o cat: cat.o $(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a +uname: uname.o + $(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a + .cpp.o: @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< diff --git a/Userland/uname.cpp b/Userland/uname.cpp new file mode 100644 index 0000000000..f74cd7d3a5 --- /dev/null +++ b/Userland/uname.cpp @@ -0,0 +1,46 @@ +#include <LibC/utsname.h> +#include <LibC/stdio.h> + +int main(int argc, char** argv) +{ + utsname uts; + int rc = uname(&uts); + if (rc < 0) { + perror("uname() failed"); + return 0; + } + bool flag_s = false; + bool flag_n = false; + bool flag_r = false; + bool flag_m = false; + if (argc == 1) { + flag_s = true; + } else { + for (int i = 1; i < argc; ++i) { + if (argv[i][0] == '-') { + for (const char* o = &argv[i][1]; *o; ++o) { + switch (*o) { + case 's': flag_s = true; break; + case 'n': flag_n = true; break; + case 'r': flag_r = true; break; + case 'm': flag_m = true; break; + case 'a': flag_s = flag_n = flag_r = flag_m = true; break; + } + } + } + } + } + if (!flag_s && !flag_n && !flag_r && !flag_m) + flag_s = true; + if (flag_s) + printf("%s ", uts.sysname); + if (flag_n) + printf("%s ", uts.nodename); + if (flag_r) + printf("%s ", uts.release); + if (flag_m) + printf("%s ", uts.machine); + printf("\n"); + return 0; +} + |