-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.h
40 lines (33 loc) · 795 Bytes
/
utils.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
#ifndef UTILS_H_
#define UTILS_H_
#include <stdio.h>
#include <string.h>
#include <libgen.h> // basename
typedef enum bool_t {
FALSE = 0,
TRUE = 1
} bool_t;
// We need this because of some template shit when comparing Distance and uint64_t
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
//#define DEBUG_PRINTS 1
#ifdef DEBUG_PRINTS
#define DEBUG(fmt, ...) \
do { printf(fmt, __VA_ARGS__); } while (0)
#else
#define DEBUG(fmt, ...) \
do {} while (0)
#endif
static inline char *strclone(char *s)
{
char *result = (char *)malloc((strlen(s) + 1) * sizeof(char));
strcpy(result, s);
return result;
}
static inline char *my_basename(char *filename)
{
char *clone = strclone(filename);
char *result = basename(clone);
free(clone);
return strclone(result);
}
#endif