util.h 933 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef _UTIL_H
  2. #define _UTIL_H
  3. #include <stdint.h>
  4. #include <stddef.h>
  5. #define __unused __attribute__((__unused__))
  6. #define typeof_field(S, F) __typeof__(((S *)0)->F)
  7. #define OR(X, Y) ((X) ? (X) : (Y))
  8. /*
  9. * #define X SOMETHING
  10. * STR(X)
  11. * => "SOMETHING"
  12. */
  13. #define STRINGIFY_AUX(X) #X
  14. #define STR(X) STRINGIFY_AUX(X)
  15. #define WITH_STR(X) X, #X
  16. #define STR_SIZE(S) (LEN(S) - 1) /* minus null byte */
  17. #define WITH_SSIZE(S) S, STR_SIZE(S)
  18. #define QUOTED(S) "\"" S "\""
  19. #define LEN(S) (sizeof(S) / sizeof *(S))
  20. #define WITH_LEN(S) S, LEN(S)
  21. #define SAFE_ASSIGN(TO, FROM) ((TO) = (__typeof__((TO)))(FROM))
  22. /* funcs */
  23. void fiter_null(char *argv[], size_t size);
  24. void print_escaped(const char *str);
  25. uint8_t match_ext(const char *file, const char *ext);
  26. int raw_dryrun_or_exec(uint8_t nl, uint8_t dry_run, char *const argv[]);
  27. #define dryrun_or_exec(...) raw_dryrun_or_exec(!0, __VA_ARGS__)
  28. #endif /* _UTIL_H */