-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.h
75 lines (58 loc) · 1.59 KB
/
system.h
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
69
70
71
72
73
74
75
/**
* Tony Givargis
* Copyright (C), 2023
* University of California, Irvine
*
* CS 238P - Operating Systems
* system.h
*/
#ifndef _SYSTEM_H_
#define _SYSTEM_H_
#include <time.h>
#include <errno.h>
#include <ctype.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <assert.h>
#define MIN(x, y) ( ((x) < (y)) ? (x) : (y) )
#define MAX(x, y) ( ((x) > (y)) ? (x) : (y) )
#define ARRAY_SIZE(a) ( (sizeof (a)) / (sizeof (a[0])) )
#define RESTORE_FROM_FILE 1
#define UNUSED(s) \
do { \
(void)(s); \
} while (0)
#define TRACE(s) \
do { \
fprintf(stderr, \
"error: %s:%d: %s\n", \
__FILE__, \
__LINE__, \
safe_strlen(s) ? \
(s) : "^"); \
} while (0)
#define EXIT(s) \
do { \
TRACE((s)); \
assert( 0 ); \
exit(-1); \
} while (0)
#define FREE(p) \
do { \
if ((p)) { \
free((void *)(p)); \
(p) = NULL; \
} \
} while (0)
uint64_t ref_time(void);
void us_sleep(uint64_t us);
void file_delete(const char *pathname);
void safe_sprintf(char *buf, size_t len, const char *format, ...);
size_t safe_strlen(const char *s);
size_t page_size(void);
void *memory_align(void *p, size_t n);
#endif /* _SYSTEM_H_ */