]>
git.proxmox.com Git - mirror_lxcfs.git/blob - src/macro.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #ifndef __LXCFS_MACRO_H
4 #define __LXCFS_MACRO_H
10 #ifndef FUSE_USE_VERSION
11 #define FUSE_USE_VERSION 26
14 #define _FILE_OFFSET_BITS 64
22 /* filesystem magic values */
23 #ifndef CGROUP_SUPER_MAGIC
24 #define CGROUP_SUPER_MAGIC 0x27e0eb
27 #ifndef CGROUP2_SUPER_MAGIC
28 #define CGROUP2_SUPER_MAGIC 0x63677270
31 #define lxcfs_debug_stream(stream, format, ...) \
33 fprintf(stream, "%s: %d: %s: " format "\n", __FILE__, __LINE__, \
34 __func__, ##__VA_ARGS__); \
37 #define lxcfs_error(format, ...) lxcfs_debug_stream(stderr, format, ##__VA_ARGS__)
40 #define lxcfs_debug(format, ...) lxcfs_error(format, ##__VA_ARGS__)
42 #define lxcfs_debug(format, ...)
46 #define lxcfs_v(format, ...) lxcfs_error(format, ##__VA_ARGS__);
48 #define lxcfs_v(format, ...)
51 #define lxcfs_info(format, ...) \
53 fprintf(stderr, format "\n", ##__VA_ARGS__); \
56 #define log_error_errno(__ret__, __errno__, format, ...) \
59 lxcfs_error(format, ##__VA_ARGS__); \
63 #define log_error(__ret__, format, ...) \
65 lxcfs_error(format, ##__VA_ARGS__); \
69 #define STRLITERALLEN(x) (sizeof(""x"") - 1)
71 /* Calculate the number of chars needed to represent a given integer as a C
72 * string. Include room for '-' to indicate negative numbers and the \0 byte.
73 * This is based on systemd.
75 #define INTTYPE_TO_STRLEN(type) \
76 (2 + (sizeof(type) <= 1 \
84 : sizeof(int[-2 * (sizeof(type) > 8)])))
86 #define ret_errno(__errno__) \
92 #define ret_set_errno(__ret__, __errno__) \
98 #define lxc_iterate_parts(__iterator, __splitme, __separators) \
99 for (char *__p = NULL, *__it = strtok_r(__splitme, __separators, &__p); \
100 (__iterator = __it); \
101 __iterator = __it = strtok_r(NULL, __separators, &__p))
103 #define log_exit(format, ...) \
105 fprintf(stderr, format, ##__VA_ARGS__); \
106 _exit(EXIT_FAILURE); \
110 #define log_debug(__ret__, format, ...) \
112 lxcfs_debug_stream(format, ##__VA_ARGS__); \
116 #define log_debug(__ret__, format, ...) ({ __ret__; })
119 #define PTR_TO_INT(p) ((int)((intptr_t)(p)))
120 #define INT_TO_PTR(u) ((void *)((intptr_t)(u)))
121 #define PTR_TO_UINT64(p) ((uint64_t)((intptr_t)(p)))
122 #define INTTYPE_TO_PTR(u) ((void *)((intptr_t)(u)))
124 #define __visible __attribute__((visibility("default")))
126 #endif /* __LXCFS_MACRO_H */