diff options
author | dzwdz | 2023-09-03 01:30:53 +0200 |
---|---|---|
committer | dzwdz | 2023-09-03 01:30:53 +0200 |
commit | a492c6ec119bd1151a6f2f7b70875ba173e9c036 (patch) | |
tree | a96f9d4ff4b120ecd58f8f41ab26b5a28fd368c0 /src/libc/stdlib/progname.c | |
parent | fd80c0b227336f4650d6b54d82469feb017aeded (diff) |
libc: split up large .c files, slimming down small binaries a bit
Diffstat (limited to 'src/libc/stdlib/progname.c')
-rw-r--r-- | src/libc/stdlib/progname.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libc/stdlib/progname.c b/src/libc/stdlib/progname.c new file mode 100644 index 0000000..4cc0fb2 --- /dev/null +++ b/src/libc/stdlib/progname.c @@ -0,0 +1,28 @@ +#include <_proc.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +static const char *progname; +const char *getprogname(void) { + return progname; +} +void setprogname(const char *pg) { + progname = pg; + setproctitle(NULL); +} + +void setproctitle(const char *fmt, ...) { + // TODO bounds checking + if (!fmt) { + strcpy(_psdata_loc->desc, progname); + return; + } + sprintf(_psdata_loc->desc, "%s: ", progname); + + va_list argp; + va_start(argp, fmt); + vsnprintf(_psdata_loc->desc + strlen(_psdata_loc->desc), 128, fmt, argp); + va_end(argp); +} + |