forked from inteos/pgsql-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
190 lines (168 loc) · 3.61 KB
/
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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
* Copyright (c) 2013 by Inteos sp. z o.o.
* All rights reserved. See LICENSE.Inteos for details.
*
* Common definitions and utility functions for Inteos utils.
* Functions defines a common framework used in our utilities and plugins
*/
#ifndef _UTIL_H_
#define _UTIL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#ifdef __WIN32__
#include <windef.h>
#endif
/* Assertions definitions */
/* check valid pointer if not simply return */
#ifndef ASSERT_NVAL_RET
#define ASSERT_NVAL_RET(value) \
if ( ! value ){ \
return; \
}
#endif
/* check an error if so return */
#ifndef ASSERT_VAL_RET
#define ASSERT_VAL_RET(value) \
if ( value ){ \
return; \
}
#endif
/* check valid pointer with Null return */
#ifndef ASSERT_NVAL_RET_NULL
#define ASSERT_NVAL_RET_NULL(value) \
if ( ! value ) \
{ \
return NULL; \
}
#endif
/* if value then Null return */
#ifndef ASSERT_VAL_RET_NULL
#define ASSERT_VAL_RET_NULL(value) \
if ( value ) \
{ \
return NULL; \
}
#endif
/* check valid pointer with int/err return */
#ifndef ASSERT_NVAL_RET_ONE
#define ASSERT_NVAL_RET_ONE(value) \
if ( ! value ) \
{ \
return 1; \
}
#endif
/* check valid pointer with int/err return */
#ifndef ASSERT_NVAL_RET_NONE
#define ASSERT_NVAL_RET_NONE(value) \
if ( ! value ) \
{ \
return -1; \
}
#endif
/* check error if not exit with error */
#ifndef ASSERT_NVAL_EXIT_ONE
#define ASSERT_NVAL_EXIT_ONE(value) \
if ( ! value ){ \
exit ( 1 ); \
}
#endif
/* check error if not return zero */
#ifndef ASSERT_NVAL_RET_ZERO
#define ASSERT_NVAL_RET_ZERO(value) \
if ( ! value ){ \
return 0; \
}
#endif
/* check error if not return value */
#ifndef ASSERT_NVAL_RET_V
#define ASSERT_NVAL_RET_V(value,rv) \
if ( ! value ){ \
return rv; \
}
#endif
/* checks error value then int/err return */
#ifndef ASSERT_VAL_RET_ONE
#define ASSERT_VAL_RET_ONE(value) \
if ( value ) \
{ \
return 1; \
}
#endif
/* checks error value then int/err return */
#ifndef ASSERT_VAL_RET_NONE
#define ASSERT_VAL_RET_NONE(value) \
if ( value ) \
{ \
return -1; \
}
#endif
/* checks error value then exit one */
#ifndef ASSERT_VAL_EXIT_ONE
#define ASSERT_VAL_EXIT_ONE(value) \
if ( value ) \
{ \
exit (1); \
}
#endif
/* check error if not return zero */
#ifndef ASSERT_VAL_RET_ZERO
#define ASSERT_VAL_RET_ZERO(value) \
if ( value ){ \
return 0; \
}
#endif
/* check error if not return value */
#ifndef ASSERT_VAL_RET_V
#define ASSERT_VAL_RET_V(value,rv) \
if ( value ){ \
return rv; \
}
#endif
#ifndef __WIN32__
/* uid/gid struct */
typedef struct _uugid_t uugid_t;
struct _uugid_t {
uid_t uid;
gid_t gid;
};
#endif
/*
* date/time verification function structs
*/
typedef struct _udtime_t udtime_t;
struct _udtime_t {
int y;
int m;
int d;
int h;
int mi;
int s;
};
/* utilities functions */
#ifndef __WIN32__
int check_program_is_running ( char * pidfile );
#endif
int readline ( int fd, char * buf, int size );
int freadline ( FILE * stream, char * buf, int size );
//char * format_btime ( const char * str );
int strisprintable ( char * str, int len );
#ifdef __sun__
int getgrouplist (const char *uname, gid_t agroup, gid_t *groups, int *grpcnt);
#endif
#ifdef __WIN32__
#define RTLD_LAZY 0
#ifndef PATH_MAX
#define PATH_MAX MAX_PATH
#endif
void *dlopen ( const char *file, int mode );
void *dlsym ( void *handle, const char *name );
int dlclose ( void *handle );
char *dlerror ( void );
char *realpath(const char *path, char resolved_path[PATH_MAX]);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _UTIL_H_ */