1 |
#ifndef _NOIT_DEFINES_H |
---|
2 |
#define _NOIT_DEFINES_H |
---|
3 |
|
---|
4 |
#include "noit_config.h" |
---|
5 |
|
---|
6 |
#define API_EXPORT(type) extern type |
---|
7 |
|
---|
8 |
static inline int compare_timeval(struct timeval a, struct timeval b) { |
---|
9 |
if (a.tv_sec < b.tv_sec) return -1; |
---|
10 |
if (a.tv_sec > b.tv_sec) return 1; |
---|
11 |
if (a.tv_usec < b.tv_usec) return -1; |
---|
12 |
if (a.tv_usec > b.tv_usec) return 1; |
---|
13 |
return 0; |
---|
14 |
} |
---|
15 |
|
---|
16 |
static inline void sub_timeval(struct timeval a, struct timeval b, |
---|
17 |
struct timeval *out) |
---|
18 |
{ |
---|
19 |
out->tv_usec = a.tv_usec - b.tv_usec; |
---|
20 |
if (out->tv_usec < 0L) { |
---|
21 |
a.tv_sec--; |
---|
22 |
out->tv_usec += 1000000L; |
---|
23 |
} |
---|
24 |
out->tv_sec = a.tv_sec - b.tv_sec; |
---|
25 |
if (out->tv_sec < 0L) { |
---|
26 |
out->tv_sec++; |
---|
27 |
out->tv_usec -= 1000000L; |
---|
28 |
} |
---|
29 |
} |
---|
30 |
|
---|
31 |
static inline void add_timeval(struct timeval a, struct timeval b, |
---|
32 |
struct timeval *out) |
---|
33 |
{ |
---|
34 |
out->tv_usec = a.tv_usec + b.tv_usec; |
---|
35 |
if (out->tv_usec > 1000000L) { |
---|
36 |
a.tv_sec++; |
---|
37 |
out->tv_usec -= 1000000L; |
---|
38 |
} |
---|
39 |
out->tv_sec = a.tv_sec + b.tv_sec; |
---|
40 |
} |
---|
41 |
|
---|
42 |
#undef UUID_STR_LEN |
---|
43 |
#define UUID_STR_LEN 36 |
---|
44 |
#ifndef HAVE_UUID_UNPARSE_LOWER |
---|
45 |
/* Sigh, need to implement out own */ |
---|
46 |
#include <uuid/uuid.h> |
---|
47 |
#include <ctype.h> |
---|
48 |
static inline void uuid_unparse_lower(uuid_t in, char *out) { |
---|
49 |
int i; |
---|
50 |
uuid_unparse(in, out); |
---|
51 |
for(i=0;i<36;i++) out[i] = tolower(out[i]); |
---|
52 |
} |
---|
53 |
#endif |
---|
54 |
|
---|
55 |
#ifdef HAVE_TERMIO_H |
---|
56 |
#define USE_TERMIO |
---|
57 |
#endif |
---|
58 |
|
---|
59 |
#ifndef MIN |
---|
60 |
#define MIN(x,y) ((x) < (y) ? (x) : (y)) |
---|
61 |
#endif |
---|
62 |
#ifndef MAX |
---|
63 |
#define MAX(x,y) ((x) > (y) ? (x) : (y)) |
---|
64 |
#endif |
---|
65 |
#ifndef SUN_LEN |
---|
66 |
#define SUN_LEN(ptr) (sizeof(*(ptr)) - sizeof((ptr)->sun_path) + strlen((ptr)->sun_path)) |
---|
67 |
#endif |
---|
68 |
|
---|
69 |
/* This is for udns */ |
---|
70 |
#ifdef HAVE_INET_PTON |
---|
71 |
#ifdef HAVE_INET_NTOP |
---|
72 |
#define HAVE_INET_PTON_NTOP 1 |
---|
73 |
#endif |
---|
74 |
#endif |
---|
75 |
/* udns checks for IPv6, noit doesn't work without it */ |
---|
76 |
#define HAVE_IPv6 |
---|
77 |
|
---|
78 |
#include <stdio.h> |
---|
79 |
|
---|
80 |
static inline int noit_build_version(char *buff, int len) { |
---|
81 |
const char *v = NOIT_HEADURL; |
---|
82 |
const char *start, *end, *ns; |
---|
83 |
if(NULL != (start = strstr(v, "reconnoiter/"))) { |
---|
84 |
start += strlen("reconnoiter/"); |
---|
85 |
if(NULL != (end = strstr(start, "/src"))) { |
---|
86 |
ns = strchr(start, '/'); /* necessarily non-NULL */ |
---|
87 |
ns++; |
---|
88 |
if(!strncmp(start, "trunk/", 6)) |
---|
89 |
return snprintf(buff, len, "trunk.%s", NOIT_SVNVERSION); |
---|
90 |
if(!strncmp(start, "branches/", 9)) |
---|
91 |
return snprintf(buff, len, "b_%.*s.%s", (int)(end - ns), ns, NOIT_SVNVERSION); |
---|
92 |
if(!strncmp(start, "tags/", 5)) |
---|
93 |
return snprintf(buff, len, "%.*s.%s", (int)(end - ns), ns, NOIT_SVNVERSION); |
---|
94 |
} |
---|
95 |
} |
---|
96 |
return snprintf(buff, len, "unknown.%s", NOIT_SVNVERSION); |
---|
97 |
} |
---|
98 |
|
---|
99 |
#include "noitedit/strlcpy.h" |
---|
100 |
|
---|
101 |
#endif |
---|