diff options
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/.gitignore | 1 | ||||
-rw-r--r-- | Userland/Makefile | 9 | ||||
-rw-r--r-- | Userland/sh.cpp | 5 | ||||
-rw-r--r-- | Userland/tty.cpp | 13 |
4 files changed, 25 insertions, 3 deletions
diff --git a/Userland/.gitignore b/Userland/.gitignore index 7207e83cfc..77d7e70b48 100644 --- a/Userland/.gitignore +++ b/Userland/.gitignore @@ -15,3 +15,4 @@ clear tst mm kill +tty diff --git a/Userland/Makefile b/Userland/Makefile index 87d1e0809f..c94558e2d6 100644 --- a/Userland/Makefile +++ b/Userland/Makefile @@ -13,7 +13,8 @@ OBJS = \ clear.o \ tst.o \ mm.o \ - kill.o + kill.o \ + tty.o APPS = \ id \ @@ -30,7 +31,8 @@ APPS = \ clear \ tst \ mm \ - kill + kill \ + tty ARCH_FLAGS = STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc @@ -95,6 +97,9 @@ mm: mm.o kill: kill.o $(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a +tty: tty.o + $(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a + .cpp.o: @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< diff --git a/Userland/sh.cpp b/Userland/sh.cpp index 3a660c0d01..f218ae7290 100644 --- a/Userland/sh.cpp +++ b/Userland/sh.cpp @@ -11,6 +11,7 @@ struct GlobalState { String cwd; String username; + const char* ttyname_short { nullptr }; char ttyname[32]; char hostname[32]; }; @@ -160,7 +161,7 @@ static void greeting() perror("uname"); return; } - printf("\n%s/%s on %s\n\n", uts.sysname, uts.machine, g->ttyname); + printf("\n%s/%s on %s\n\n", uts.sysname, uts.machine, g->ttyname_short); } int main(int, char**) @@ -172,6 +173,8 @@ int main(int, char**) rc = ttyname_r(0, g->ttyname, sizeof(g->ttyname)); if (rc < 0) perror("ttyname_r"); + else + g->ttyname_short = strrchr(g->ttyname, '/') + 1; { auto* pw = getpwuid(getuid()); if (pw) diff --git a/Userland/tty.cpp b/Userland/tty.cpp new file mode 100644 index 0000000000..a675893917 --- /dev/null +++ b/Userland/tty.cpp @@ -0,0 +1,13 @@ +#include <LibC/stdio.h> +#include <LibC/unistd.h> + +int main(int, char**) +{ + char* tty = ttyname(0); + if (!tty) { + perror("Error"); + return 1; + } + printf("%s\n", tty); + return 0; +} |