-
Notifications
You must be signed in to change notification settings - Fork 4
/
lltop.h
51 lines (43 loc) · 1.03 KB
/
lltop.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
#ifndef _LLTOP_H_
#define _LLTOP_H_
#define _GNU_SOURCE
#include <errno.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXNAME 1024
#define DEFAULT_LLTOP_INTVL 10
#ifdef DEBUG
#include <sys/time.h>
#define ERROR(fmt,arg...) do { \
struct timeval _tv; \
gettimeofday(&_tv, NULL); \
fprintf(stderr, "%s:%s:%d:%s:%ld.%06ld: "fmt, program_invocation_short_name, \
__FILE__, __LINE__, __func__, _tv.tv_sec, (long) _tv.tv_usec, ##arg); \
} while (0)
#define TRACE ERROR
#else
#define ERROR(fmt,arg...) \
fprintf(stderr, "%s: "fmt, program_invocation_short_name, ##arg)
#define TRACE(fmt,arg...) ((void) 0)
#endif
#define FATAL(fmt,arg...) do { \
ERROR(fmt, ##arg); \
exit(1); \
} while (0)
static inline char *chop(char *s, int c)
{
char *p = strchr(s, c);
if (p != NULL)
*p = 0;
return s;
}
static inline void *alloc(size_t size)
{
void *addr = malloc(size);
if (size != 0 && addr == NULL)
FATAL("out of memory\n");
return addr;
}
#endif