#ifndef __UTILS_H #define __UTILS_H #include #include #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); } static inline void string_freep(char **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_free_ _cleanup_(freep) #define _cleanup_string_ _cleanup_(string_freep) #ifdef __cplusplus } #endif #endif /* __UTILS_H */