rd_util.h 1006 B

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