| 1 |
// Copyright (c) 1993-2011 PrBoom developers (see AUTHORS) |
| 2 |
// Licence: GPLv2 or later (see COPYING) |
| 3 |
|
| 4 |
#ifndef RD_UTIL_H |
| 5 |
#define RD_UTIL_H |
| 6 |
|
| 7 |
#include <stddef.h> |
| 8 |
|
| 9 |
// Useful utility functions |
| 10 |
|
| 11 |
#ifdef __GNUC__ |
| 12 |
#define ATTR(x) __attribute__(x) |
| 13 |
#else |
| 14 |
#define ATTR(x) |
| 15 |
#endif |
| 16 |
|
| 17 |
#if RD_IS_BIG_ENDIAN |
| 18 |
# ifdef __GNUC__ |
| 19 |
#define LONG(x) __builtin_bswap32((x)) |
| 20 |
#define SHORT(x) (__builtin_bswap32((x))>>16) |
| 21 |
# else |
| 22 |
#define LONG(x) ( (((x) & 0x000000FF) << 24) \ |
| 23 |
+(((x) & 0x0000FF00) << 8) \ |
| 24 |
+(((x) & 0x00FF0000) >> 8) \ |
| 25 |
+(((x) & 0xFF000000) >> 24) ) |
| 26 |
#define SHORT(x) ( (((x) & 0x00FF) << 8) \ |
| 27 |
+(((x) & 0xFF00) >> 8) ) |
| 28 |
# endif |
| 29 |
#else |
| 30 |
#define LONG(x) (x) |
| 31 |
#define SHORT(x) (x) |
| 32 |
#endif |
| 33 |
|
| 34 |
void ATTR((noreturn)) die(const char *error, ...); |
| 35 |
|
| 36 |
void *xmalloc(size_t size); |
| 37 |
void *xrealloc(void *ptr, size_t size); |
| 38 |
void *xcalloc(size_t n, size_t size); |
| 39 |
char *xstrdup(const char *s); |
| 40 |
|
| 41 |
// slurp an entire file into memory or kill yourself |
| 42 |
size_t read_or_die(void **ptr, const char *file); |
| 43 |
void search_path(const char *path); |
| 44 |
|
| 45 |
#endif /* RD_UTIL_H */ |