-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.h
62 lines (49 loc) · 1.81 KB
/
util.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
/* util.h
Various utility functions
Copyright (c) 2010-2012 Matthias Kramm <[email protected]>
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 2 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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef __util_h__
#define __util_h__
#include <stdbool.h>
#include <sys/select.h>
#undef assert // defined by sys/select.h
#ifdef __cplusplus
extern "C" {
#endif
//#define DEBUG
extern void stdout_printf(const char*format, ...);
#ifdef DEBUG
#include <assert.h>
#define log_dbg stdout_printf
#define log_msg stdout_printf
#define log_warn stdout_printf
#define log_err stdout_printf
#else
#define assert(b) do {} while(0)
#define log_dbg(f,...) do {} while(0)
#define log_msg(f,...) do {} while(0)
#define log_warn(f,...) stdout_printf
#define log_err(f,...) stdout_printf
#endif
void*memdup(const void*ptr, size_t size);
char*escape_string(const char*str);
char* allocprintf(const char*format, ...);
char* concat_paths(const char*base, const char*add);
void mkdir_p(const char*path);
char*read_file(const char*filename);
bool read_with_retry(int fd, void* data, int len);
bool read_with_timeout(int fd, void* data, int len, struct timeval* timeout);
#ifdef __cplusplus
}
#endif
#endif