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
|
/* Authors: Martin Nagy <mnagy@redhat.com>
*
* Copyright (C) 2009 Red Hat
* see file 'COPYING' for use and warranty information
*
* 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; version 2 only
*
* 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 _LD_UTIL_H_
#define _LD_UTIL_H_
#define CHECK(op) \
do { result = (op); \
if (result != ISC_R_SUCCESS) goto cleanup; \
} while (0)
#define CHECKED_MEM_GET(m, target_ptr, s) \
do { \
(target_ptr) = isc_mem_get((m), (s)); \
if ((target_ptr) == NULL) { \
result = ISC_R_NOMEMORY; \
goto cleanup; \
} \
} while (0)
#define CHECKED_MEM_GET_PTR(m, target_ptr) \
CHECKED_MEM_GET(m, target_ptr, sizeof(*(target_ptr)))
#define CHECKED_MEM_STRDUP(m, source, target) \
do { \
(target) = isc_mem_strdup((m), (source)); \
if ((target) == NULL) { \
result = ISC_R_NOMEMORY; \
goto cleanup; \
} \
} while (0)
#define ZERO_PTR(ptr) memset((ptr), 0, sizeof(*(ptr)))
#define SAFE_MEM_PUT(m, target_ptr, target_size) \
do { \
if ((target_ptr) != NULL) \
isc_mem_put((m), (target_ptr), \
(target_size)); \
} while (0)
#define SAFE_MEM_PUT_PTR(m, target_ptr) \
SAFE_MEM_PUT((m), (target_ptr), sizeof(*(target_ptr)))
#define MEM_PUT_AND_DETACH(target_ptr) \
isc_mem_putanddetach(&(target_ptr)->mctx, target_ptr, \
sizeof(*(target_ptr)))
#define DECLARE_BUFFERED_NAME(name) \
dns_name_t name; \
isc_buffer_t name##__buffer; \
unsigned char name##__base[DNS_NAME_MAXWIRE]
#define INIT_BUFFERED_NAME(name) \
do { \
isc_buffer_init(&name##__buffer, name##__base, \
sizeof(name##__base)); \
dns_name_init(&name, NULL); \
dns_name_setbuffer(&name, &name##__buffer); \
} while (0)
#endif /* !_LD_UTIL_H_ */
|