root/src/noit_defines.h

Revision 9bdec91148b07bbc700fee57405676759c52fe29, 4.5 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 4 years ago)

move this UUID_LEN to some place more accessible

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007-2009, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *     * Redistributions of source code must retain the above copyright
10  *       notice, this list of conditions and the following disclaimer.
11  *     * Redistributions in binary form must reproduce the above
12  *       copyright notice, this list of conditions and the following
13  *       disclaimer in the documentation and/or other materials provided
14  *       with the distribution.
15  *     * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *       of its contributors may be used to endorse or promote products
17  *       derived from this software without specific prior written
18  *       permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _NOIT_DEFINES_H
34 #define _NOIT_DEFINES_H
35
36 #include "noit_config.h"
37
38 #ifndef __FUNCTION__
39 #define __FUNCTION__ __func__
40 #endif
41
42 #define API_EXPORT(type) extern type
43
44 static inline int compare_timeval(struct timeval a, struct timeval b) {
45   if (a.tv_sec < b.tv_sec) return -1;
46   if (a.tv_sec > b.tv_sec) return 1;
47   if (a.tv_usec < b.tv_usec) return -1;
48   if (a.tv_usec > b.tv_usec) return 1;
49   return 0;
50 }
51
52 static inline void sub_timeval(struct timeval a, struct timeval b,
53                                struct timeval *out)
54 {
55   out->tv_usec = a.tv_usec - b.tv_usec;
56   if (out->tv_usec < 0L) {
57     a.tv_sec--;
58     out->tv_usec += 1000000L;
59   }
60   out->tv_sec = a.tv_sec - b.tv_sec;
61   if (out->tv_sec < 0L) {
62     out->tv_sec++;
63     out->tv_usec -= 1000000L;
64   }
65 }
66
67 static inline void add_timeval(struct timeval a, struct timeval b,
68                                struct timeval *out)
69 {
70   out->tv_usec = a.tv_usec + b.tv_usec;
71   if (out->tv_usec > 1000000L) {
72     a.tv_sec++;
73     out->tv_usec -= 1000000L;
74   }
75   out->tv_sec = a.tv_sec + b.tv_sec;
76 }
77
78 #undef UUID_STR_LEN
79 #define UUID_STR_LEN 36
80 #ifndef HAVE_UUID_UNPARSE_LOWER
81 /* Sigh, need to implement out own */
82 #include <uuid/uuid.h>
83 #include <ctype.h>
84 static inline void uuid_unparse_lower(uuid_t in, char *out) {
85   int i;
86   uuid_unparse(in, out);
87   for(i=0;i<36;i++) out[i] = tolower(out[i]);
88 }
89 #endif
90
91 #ifdef HAVE_TERMIO_H
92 #define USE_TERMIO
93 #endif
94
95 #ifndef MIN
96 #define MIN(x,y)  ((x) < (y) ? (x) : (y))
97 #endif
98 #ifndef MAX
99 #define MAX(x,y)  ((x) > (y) ? (x) : (y))
100 #endif
101 #ifndef SUN_LEN
102 #define SUN_LEN(ptr) (sizeof(*(ptr)) - sizeof((ptr)->sun_path) + strlen((ptr)->sun_path))
103 #endif
104
105 /* This is for udns */
106 #ifdef HAVE_INET_PTON
107 #ifdef HAVE_INET_NTOP
108 #define HAVE_INET_PTON_NTOP 1
109 #endif
110 #endif
111 /* udns checks for IPv6, noit doesn't work without it */
112 #define HAVE_IPv6
113
114 #include <stdio.h>
115
116 static inline int noit_build_version(char *buff, int len) {
117   const char *v = NOIT_HEADURL;
118   const char *start, *end, *ns;
119   if(NULL != (start = strstr(v, "reconnoiter/"))) {
120     start += strlen("reconnoiter/");
121     if(NULL != (end = strstr(start, "/src"))) {
122       ns = strchr(start, '/'); /* necessarily non-NULL */
123       ns++;
124       if(!strncmp(start, "trunk/", 6))
125         return snprintf(buff, len, "trunk.%s", NOIT_SVNVERSION);
126       if(!strncmp(start, "branches/", 9))
127         return snprintf(buff, len, "b_%.*s.%s", (int)(end - ns), ns, NOIT_SVNVERSION);
128       if(!strncmp(start, "tags/", 5))
129         return snprintf(buff, len, "%.*s.%s", (int)(end - ns), ns, NOIT_SVNVERSION);
130     }
131   }
132   return snprintf(buff, len, "unknown.%s", NOIT_SVNVERSION);
133 }
134
135 #if defined(__sun) && !defined(HAVE_POSIX_READDIR_R)
136 #define portable_readdir_r(a,b,c) (((*c) = readdir_r(a,b)) != NULL)
137 #else
138 #define portable_readdir_r readdir_r
139 #endif
140 #include "noitedit/strlcpy.h"
141
142 #define UUID_REGEX "[0-9a-fA-F]{4}(?:[0-9a-fA-F]{4}-){4}[0-9a-fA-F]{12}"
143 #include <uuid/uuid.h>
144 struct uuid_dummy { uuid_t foo; };
145 #define UUID_SIZE sizeof(struct uuid_dummy)
146
147 #endif
Note: See TracBrowser for help on using the browser.