/* SPDX-License-Identifier: GPL-2.0-or-later * Copyright Red Hat * Author: David Gibson * * Definitions used by both passt/pasta and other tools */ #ifndef COMMON_H #define COMMON_H #include #define VERSION_BLOB \ VERSION "\n" \ "Copyright Red Hat\n" \ "GNU General Public License, version 2 or later\n" \ " \n" \ "This is free software: you are free to change and redistribute it.\n" \ "There is NO WARRANTY, to the extent permitted by law.\n\n" /* FPRINTF() intentionally silences cert-err33-c clang-tidy warnings */ #define FPRINTF(f, ...) (void)fprintf(f, __VA_ARGS__) /* * Starting from glibc 2.40.9000 and commit 25a5eb4010df ("string: strerror, * strsignal cannot use buffer after dlmopen (bug 32026)"), strerror() needs * getrandom(2) and brk(2) as it allocates memory for the locale-translated * error description, but our seccomp profiles forbid both. * * Use the strerror_() wrapper instead, calling into strerrordesc_np() to get * a static untranslated string. It's a GNU implementation, but also defined by * bionic. * * If strerrordesc_np() is not defined (e.g. musl), call strerror(). C libraries * not defining strerrordesc_np() are expected to provide strerror() * implementations that are simple enough for us to call. */ __attribute__ ((weak)) const char *strerrordesc_np(int errnum); /** * strerror_() - strerror() wrapper calling strerrordesc_np() if available * @errnum: Error code * * Return: error description string */ static inline const char *strerror_(int errnum) { if (strerrordesc_np) return strerrordesc_np(errnum); return strerror(errnum); } #define strerror(x) @ "Don't call strerror() directly, use strerror_() instead" #define ARRAY_SIZE(a) ((int)(sizeof(a) / sizeof((a)[0]))) #endif /* _COMMON_H */