summaryrefslogtreecommitdiff
path: root/src/user/lib/stdlib.c
blob: 2d1f224d89ff11fc7af42be07f2923167701d344 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <_proc.h>
#include <camellia.h>
#include <camellia/syscalls.h>
#include <errno.h>
#include <string.h>
#include <bits/panic.h>

_Noreturn void abort(void) {
	_sys_exit(1);
}

static const char *progname;
const char *getprogname(void) {
	return progname;
}
void setprogname(const char *pg) {
	progname = pg;
}

void setproctitle(const char *fmt, ...) {
	if (!fmt) {
		strcpy(_libc_psdata, progname);
		return;
	}
	sprintf(_libc_psdata, "%s: ", progname);

	va_list argp;
	va_start(argp, fmt);
	vsnprintf(_libc_psdata + strlen(_libc_psdata), 128, fmt, argp);
	va_end(argp);
}

int mkstemp(char *template) {
	// TODO randomize template
	hid_t h = camellia_open(template, OPEN_CREATE | OPEN_RW);
	if (h < 0) {
		errno = -h;
		return -1;
	}
	// TODO truncate
	return h;
}

// TODO process env
char *getenv(const char *name) {
	(void)name;
	return NULL;
}

// TODO system()
int system(const char *cmd) {
	(void)cmd;
	errno = ENOSYS;
	return -1;
}

int abs(int i) {
	return i < 0 ? -i : i;
}

int atoi(const char *s) {
	return strtol(s, NULL, 10);
}

double atof(const char *s) {
	(void)s;
	__libc_panic("unimplemented");
}