Crinit -- Configurable Rootfs Init
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#ifndef __COMMON_H__
7#define __COMMON_H__
8
9#include <stddef.h>
10#include <stdint.h>
11
19#define CRINIT_PARAM_UNUSED(par) \
20 do { \
21 (void)(par); \
22 } while (0)
23
36#define crinitParamCheck(inputParam, cmpShort, cmpLong) \
37 ((strncmp(inputParam, cmpShort, sizeof(cmpShort)) == 0) || (strncmp(inputParam, cmpLong, sizeof(cmpLong)) == 0))
38
46#define crinitIsAbsPath(path) (((path) != NULL) && ((path)[0] == '/'))
47
51#define crinitNumElements(p) (sizeof(p) / sizeof(*(p)))
52
66#define crinitNullCheck(errcode, ...) \
67 do { \
68 _Pragma("GCC diagnostic push"); \
69 _Pragma("GCC diagnostic error \"-Wshadow\""); \
70 const void *_macroPtrsToCheck[] = {__VA_ARGS__}; \
71 for (size_t _macroI = 0; _macroI < crinitNumElements(_macroPtrsToCheck); _macroI++) { \
72 if (_macroPtrsToCheck[_macroI] == NULL) { \
73 crinitErrPrint("Input parameters must not be NULL."); \
74 return (errcode); \
75 } \
76 } \
77 _Pragma("GCC diagnostic pop"); \
78 } while (0)
79
86#define crinitStrtoGenericInteger(resType, str, endptr, base) \
87 _Generic((resType), \
88 int: strtol, \
89 long: strtol, \
90 long long: strtoll, \
91 unsigned int: strtoul, \
92 unsigned long: strtoul, \
93 unsigned long long: strtoull)((str), (endptr), (base))
94
100#define crinitNullify(ptr) \
101 do { \
102 free(ptr); \
103 (ptr) = NULL; \
104 } while (0)
105
117int crinitBinReadAll(uint8_t *buf, size_t n, const char *path);
118
119#endif /* __COMMON_H__ */
int crinitBinReadAll(uint8_t *buf, size_t n, const char *path)
Definition common.c:14