-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.c
More file actions
35 lines (31 loc) · 732 Bytes
/
utils.c
File metadata and controls
35 lines (31 loc) · 732 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void *dmalloc(size_t size) {
void *result = malloc(size);
if (result == NULL) {
puts("allocation failed");
exit(1);
}
return result;
}
void *dzmalloc(size_t size) {
void *result = calloc(size, 1);
if (result == NULL) {
puts("allocation failed");
exit(1);
}
return result;
}
void writeLong(char *buffer, unsigned long num, size_t bytes) {
for (int i = 0; i < bytes; i++) {
buffer[i] = num & 0xFF;
num = num >> 8;
}
}
void writeInt(char *buffer, unsigned long num, size_t bytes) {
for (int i = 0; i < bytes; i++) {
buffer[i] = num & 0xFF;
num = num >> 8;
}
}