From cd970928a0779219655d5bdaf46cf32f8c865b23 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Wed, 26 May 2021 09:39:57 +0200 Subject: LibC: Implement getprogname and setprogname --- Userland/Libraries/LibC/stdlib.cpp | 19 +++++++++++++++++++ Userland/Libraries/LibC/stdlib.h | 2 ++ 2 files changed, 21 insertions(+) (limited to 'Userland/Libraries/LibC') diff --git a/Userland/Libraries/LibC/stdlib.cpp b/Userland/Libraries/LibC/stdlib.cpp index 5449b9814d..8c2e5545d5 100644 --- a/Userland/Libraries/LibC/stdlib.cpp +++ b/Userland/Libraries/LibC/stdlib.cpp @@ -373,6 +373,25 @@ int putenv(char* new_var) return 0; } +static const char* __progname = NULL; + +const char* getprogname() +{ + return __progname; +} + +void setprogname(const char* progname) +{ + for (int i = strlen(progname) - 1; i >= 0; i--) { + if (progname[i] == '/') { + __progname = progname + i + 1; + return; + } + } + + __progname = progname; +} + double strtod(const char* str, char** endptr) { // Parse spaces, sign, and base diff --git a/Userland/Libraries/LibC/stdlib.h b/Userland/Libraries/LibC/stdlib.h index c63e7eebc5..c9eae34db1 100644 --- a/Userland/Libraries/LibC/stdlib.h +++ b/Userland/Libraries/LibC/stdlib.h @@ -31,6 +31,8 @@ int putenv(char*); int unsetenv(const char*); int clearenv(void); int setenv(const char* name, const char* value, int overwrite); +const char* getprogname(); +void setprogname(const char*); int atoi(const char*); long atol(const char*); long long atoll(const char*); -- cgit v1.2.3