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