-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.c
54 lines (48 loc) · 853 Bytes
/
util.c
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
#include <u.h>
#include <libc.h>
#include <thread.h>
#include "dat.h"
#include "fns.h"
void *
emalloc(usize n)
{
void *p;
if((p = mallocz(n, 1)) == nil)
sysfatal("emalloc: %r");
setmalloctag(p, getcallerpc(&n));
return p;
}
void *
erealloc(void *p, usize n, usize oldn)
{
if((p = realloc(p, n)) == nil)
sysfatal("realloc: %r");
setrealloctag(p, getcallerpc(&p));
if(n > oldn)
memset((uchar *)p + oldn, 0, n - oldn);
return p;
}
char *
estrdup(char *s)
{
if((s = strdup(s)) == nil)
sysfatal("estrdup: %r");
setmalloctag(s, getcallerpc(&s));
return s;
}
int
setpri(int pri)
{
int n, fd, pid;
char path[32];
if((pid = getpid()) == 0)
return -1;
snprint(path, sizeof path, "/proc/%d/ctl", pid);
if((fd = open(path, OWRITE)) < 0)
return -1;
n = fprint(fd, "pri %d\n", pri);
close(fd);
if(n < 0)
return -1;
return 0;
}