summaryrefslogtreecommitdiff
path: root/src/utils.h
blob: 92ff61d144c9d66a30b413afa3f0152dd6305471 (plain)
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
#ifndef    __UTILS_H
#define    __UTILS_H

#include <stdint.h>
#include <stdlib.h>

#ifdef __cplusplus
extern "C" {
#endif

#define MAX_ERROR_MSG_SIZE  PATH_MAX


extern void *xmalloc( size_t );
extern void *xrealloc( void *, size_t );

extern char *dupstr( char *s );

static inline void freep(void **p)
{
    if (*p)
        free(*p);
}

#define DEFINE_TRIVIAL_CLEANUP_FUNC(type, func) \
    static inline void func##p(type *p)         \
    {                                           \
        if (*p)                                 \
            *p = func(*p);                      \
    }

#define _cleanup_(_some_) __attribute__((__cleanup__(_some_)))
#define _cleanup_bus_unref_ _cleanup_(sd_bus_unrefp)
#define _cleanup_bus_close_unref_ _cleanup_(sd_bus_close_unrefp)
#define _cleanup_bus_slot_unref_ _cleanup_(sd_bus_slot_unrefp)
#define _cleanup_bus_message_unref_ _cleanup_(sd_bus_message_unrefp)
#define _cleanup_bus_creds_unref_ _cleanup_(sd_bus_creds_unrefp)
#define _cleanup_bus_track_unref_ _cleanup_(sd_bus_slot_unrefp)
#define _cleanup_bus_error_free_ _cleanup_(sd_bus_error_free)
#define _cleanup_free_ _cleanup_(freep)

#ifdef __cplusplus
}
#endif

#endif  /* __UTILS_H */