]>
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
12 /* filesystem magic values */
13 #ifndef CGROUP_SUPER_MAGIC
14 #define CGROUP_SUPER_MAGIC 0x27e0eb
17 #ifndef CGROUP2_SUPER_MAGIC
18 #define CGROUP2_SUPER_MAGIC 0x63677270
21 #define lxcfs_debug_stream(stream, format, ...) \
23 fprintf(stream, "%s: %d: %s: " format "\n", __FILE__, \
24 __LINE__, __func__, ##__VA_ARGS__); \
27 #define lxcfs_error(format, ...) lxcfs_debug_stream(stderr, format, ##__VA_ARGS__)
30 #define lxcfs_debug(format, ...) lxcfs_error(format, ##__VA_ARGS__)
32 #define lxcfs_debug(format, ...) \
38 #define lxcfs_v(format, ...) lxcfs_error(format, ##__VA_ARGS__);
40 #define lxcfs_v(format, ...)
43 #define lxcfs_info(format, ...) \
45 fprintf(stderr, format "\n", ##__VA_ARGS__); \
48 #define log_error_errno(__ret__, __errno__, format, ...) \
51 lxcfs_error(format, ##__VA_ARGS__); \
55 #define log_error(__ret__, format, ...) \
57 lxcfs_error(format, ##__VA_ARGS__); \
61 #define STRLITERALLEN(x) (sizeof(""x"") - 1)
63 /* Calculate the number of chars needed to represent a given integer as a C
64 * string. Include room for '-' to indicate negative numbers and the \0 byte.
65 * This is based on systemd.
67 #define INTTYPE_TO_STRLEN(type) \
68 (2 + (sizeof(type) <= 1 \
76 : sizeof(int[-2 * (sizeof(type) > 8)])))
78 #define move_ptr(ptr) \
80 __typeof__(ptr) __internal_ptr__ = (ptr); \
87 int __internal_fd__ = (fd); \
92 #define ret_errno(__errno__) \
98 #define ret_set_errno(__ret__, __errno__) \
104 #define lxc_iterate_parts(__iterator, __splitme, __separators) \
105 for (char *__p = NULL, *__it = strtok_r(__splitme, __separators, &__p); \
106 (__iterator = __it); \
107 __iterator = __it = strtok_r(NULL, __separators, &__p))
109 #define log_exit(format, ...) \
111 fprintf(stderr, format, ##__VA_ARGS__); \
112 _exit(EXIT_FAILURE); \
116 #define log_debug(__ret__, format, ...) \
118 lxcfs_debug_stream(stderr, format, ##__VA_ARGS__); \
122 #define log_debug(__ret__, format, ...) ({ __ret__; })
125 #define PTR_TO_INT(p) ((int)((intptr_t)(p)))
126 #define INT_TO_PTR(u) ((void *)((intptr_t)(u)))
127 #define PTR_TO_UINT64(p) ((uint64_t)((intptr_t)(p)))
128 #define INTTYPE_TO_PTR(u) ((void *)((intptr_t)(u)))
130 #define __visible __attribute__((visibility("default")))
132 #define __lxcfs_fuse_ops
134 #ifndef __returns_twice
135 #define __returns_twice __attribute__((returns_twice))
138 #define STRINGIFY(a) __STRINGIFY(a)
139 #define __STRINGIFY(a) #a
141 #endif /* __LXCFS_MACRO_H */