12345678910111213141516171819202122232425262728293031323334353637383940 |
- #ifndef _UTIL_H
- #define _UTIL_H
- #include <stdint.h>
- #include <stddef.h>
- #define __unused __attribute__((__unused__))
- #define typeof_field(S, F) __typeof__(((S *)0)->F)
- #define OR(X, Y) ((X) ? (X) : (Y))
- /*
- * #define X SOMETHING
- * STR(X)
- * => "SOMETHING"
- */
- #define STRINGIFY_AUX(X) #X
- #define STR(X) STRINGIFY_AUX(X)
- #define WITH_STR(X) X, #X
- #define STR_SIZE(S) (LEN(S) - 1) /* minus null byte */
- #define WITH_SSIZE(S) S, STR_SIZE(S)
- #define QUOTED(S) "\"" S "\""
- #define LEN(S) (sizeof(S) / sizeof *(S))
- #define WITH_LEN(S) S, LEN(S)
- #define SAFE_ASSIGN(TO, FROM) ((TO) = (__typeof__((TO)))(FROM))
- /* funcs */
- void fiter_null(char *argv[], size_t size);
- void print_escaped(const char *str);
- uint8_t match_ext(const char *file, const char *ext);
- int raw_dryrun_or_exec(uint8_t nl, uint8_t dry_run, char *const argv[]);
- #define dryrun_or_exec(...) raw_dryrun_or_exec(!0, __VA_ARGS__)
- #endif /* _UTIL_H */
|