summaryrefslogtreecommitdiff
path: root/src/libc/stdlib/progname.c
blob: 4cc0fb290deb1e65ee60ffc7dade9ffa6d245f81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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);
}