-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.h
91 lines (79 loc) · 2.9 KB
/
common.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
* Project: udptunnel
* File: common.h
*
* Copyright (C) 2009 Daniel Meekins
* Contact: dmeekins - gmail
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef COMMON_H
#define COMMON_H
#include <stdio.h>
#include <ctype.h>
#define NO_DEBUG 0
#define DEBUG_LEVEL1 1
#define DEBUG_LEVEL2 2
#define DEBUG_LEVEL3 3
#ifdef WIN32
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
#endif
/* cl.exe has a different 'inline' keyword for some dumb reason */
#ifdef WIN32
#define _inline_ __inline
#else
#define _inline_ inline
#endif
#define PERROR_GOTO(cond,err,label){ \
if(cond) \
{ \
if(debug_level >= DEBUG_LEVEL1) \
perror(err) ; \
goto label; \
}}
#define ERROR_GOTO(cond,str,label){ \
if(cond) \
{ \
if(debug_level >= DEBUG_LEVEL2) \
fprintf(stderr, "Error: %s\n", str); \
goto label; \
}}
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#ifdef SOLARIS
/* Copied from sys/time.h on linux system since solaris system that I tried to
* compile on didn't have timeradd macro. */
#define timeradd(a, b, result) \
do { \
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
if ((result)->tv_usec >= 1000000) \
{ \
++(result)->tv_sec; \
(result)->tv_usec -= 1000000; \
} \
} while (0)
#endif /* SOLARIS */
static _inline_ int isnum(char *s)
{
for(; *s != '\0'; s++)
{
if(!isdigit((int)*s))
return 0;
}
return 1;
}
#endif /* COMMON_H */