hop-2012/cmsg_private.h

29 lines
999 B
C

#ifndef cmsg_private_h
#define cmsg_private_h
typedef struct cmsg_bytes_t {
size_t len;
unsigned char *bytes;
} cmsg_bytes_t;
#define CMSG_BYTES(length, bytes_ptr) ((cmsg_bytes_t) { \
.len = (length), \
.bytes = (unsigned char *) (bytes_ptr) \
})
#define EMPTY_BYTES CMSG_BYTES(0, NULL)
extern cmsg_bytes_t cmsg_cstring_bytes(char const *cstr);
extern cmsg_bytes_t cmsg_bytes_malloc_dup(cmsg_bytes_t src);
extern cmsg_bytes_t cmsg_bytes_malloc(size_t amount);
extern void cmsg_bytes_free(cmsg_bytes_t bytes);
#define ICHECK(result, message) do { if ((result) == -1) { perror(message); exit(2); } } while (0)
#define BCHECK(result, message) do { if ((result) == 0) { perror(message); exit(2); } } while (0)
#define PCHECK(result, message) do { if ((result) == NULL) { perror(message); exit(2); } } while (0)
extern __attribute__((noreturn)) void die(char const *format, ...);
extern void warn(char const *format, ...);
extern void info(char const *format, ...);
#endif