-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathshiva_util.c
More file actions
62 lines (51 loc) · 742 Bytes
/
shiva_util.c
File metadata and controls
62 lines (51 loc) · 742 Bytes
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
#include "shiva.h"
char *
shiva_strdup(const char *s)
{
char *p = strdup(s);
if (p == NULL) {
perror("strdup");
exit(EXIT_FAILURE);
}
return p;
}
char *
shiva_xfmtstrdup(char *fmt, ...)
{
char buf[512];
char *s;
va_list va;
va_start(va, fmt);
vsnprintf(buf, sizeof(buf), fmt, va);
s = shiva_strdup(buf);
return s;
}
void *
shiva_malloc(size_t len)
{
uint8_t *mem = malloc(len);
if (mem == NULL) {
perror("malloc");
exit(EXIT_FAILURE);
}
return mem;
}
char * shiva_itoa(long x, char *t)
{
int i;
int j;
i = 0;
do
{
t[i] = (x % 10) + '0';
x /= 10;
i++;
} while (x!=0);
t[i] = 0;
for (j=0; j < i / 2; j++) {
t[j] ^= t[i - j - 1];
t[i - j - 1] ^= t[j];
t[j] ^= t[i - j - 1];
}
return t;
}