utils.h 981 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #ifndef SSB_SPROMTOOL_UTILS_H_
  2. #define SSB_SPROMTOOL_UTILS_H_
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <stdint.h>
  6. #define ssb_stringify_1(x) #x
  7. #define ssb_stringify(x) ssb_stringify_1(x)
  8. #ifdef ATTRIBUTE_FORMAT
  9. # undef ATTRIBUTE_FORMAT
  10. #endif
  11. #ifdef __GNUC__
  12. # define ATTRIBUTE_FORMAT(t, a, b) __attribute__((format(t, a, b)))
  13. #else
  14. # define ATTRIBUTE_FORMAT(t, a, b) /* nothing */
  15. #endif
  16. int prinfo(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
  17. int prerror(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
  18. int prdata(const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 1, 2);
  19. void internal_error(const char *message);
  20. #define internal_error_on(condition) \
  21. do { \
  22. if (condition) \
  23. internal_error(ssb_stringify(condition)); \
  24. } while (0)
  25. void * malloce(size_t size);
  26. void * realloce(void *ptr, size_t newsize);
  27. /* CRC-8 with polynomial x^8+x^7+x^6+x^4+x^2+1 */
  28. uint8_t crc8(uint8_t crc, uint8_t data);
  29. #endif /* SSB_SPROMTOOL_UTILS_H_ */