]> git.sesse.net Git - bcachefs-tools-debian/blob - c_src/include/linux/printk.h
remove library from bcachefs-tools Rust package
[bcachefs-tools-debian] / c_src / include / linux / printk.h
1 #ifndef __TOOLS_LINUX_PRINTK_H
2 #define __TOOLS_LINUX_PRINTK_H
3
4 #ifndef pr_fmt
5 #define pr_fmt(fmt) fmt
6 #endif
7
8 #include <linux/compiler.h>
9 #include <stdarg.h>
10 #include <stdio.h>
11
12 #define KERN_EMERG      ""
13 #define KERN_ALERT      ""
14 #define KERN_CRIT       ""
15 #define KERN_ERR        ""
16 #define KERN_WARNING    ""
17 #define KERN_NOTICE     ""
18 #define KERN_INFO       ""
19 #define KERN_DEBUG      ""
20 #define KERN_DEFAULT    ""
21 #define KERN_CONT       ""
22 #define KERN_SOH        "\001"
23
24 static inline int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
25 {
26         int i;
27
28         i = vsnprintf(buf, size, fmt, args);
29
30         if (likely(i < size))
31                 return i;
32         if (size != 0)
33                 return size - 1;
34         return 0;
35 }
36
37 static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
38 {
39         va_list args;
40         int i;
41
42         va_start(args, fmt);
43         i = vscnprintf(buf, size, fmt, args);
44         va_end(args);
45
46         return i;
47 }
48
49 #define printk(...)     printf(__VA_ARGS__)
50 #define vprintk(...)    vprintf(__VA_ARGS__)
51
52 #define no_printk(fmt, ...)                             \
53 ({                                                      \
54         do {                                            \
55                 if (0)                                  \
56                         printk(fmt, ##__VA_ARGS__);     \
57         } while (0);                                    \
58         0;                                              \
59 })
60
61 #define pr_emerg(fmt, ...) \
62         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
63 #define pr_alert(fmt, ...) \
64         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
65 #define pr_crit(fmt, ...) \
66         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
67 #define pr_err(fmt, ...) \
68         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
69 #define pr_warning(fmt, ...) \
70         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
71 #define pr_warn pr_warning
72 #define pr_notice(fmt, ...) \
73         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
74 #define pr_info(fmt, ...) \
75         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
76 /*
77  * Like KERN_CONT, pr_cont() should only be used when continuing
78  * a line with no newline ('\n') enclosed. Otherwise it defaults
79  * back to KERN_DEFAULT.
80  */
81 #define pr_cont(fmt, ...) \
82         printk(KERN_CONT fmt, ##__VA_ARGS__)
83
84 /* pr_devel() should produce zero code unless DEBUG is defined */
85 #ifdef DEBUG
86 #define pr_devel(fmt, ...) \
87         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
88 #else
89 #define pr_devel(fmt, ...) \
90         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
91 #endif
92
93
94 /* If you are writing a driver, please use dev_dbg instead */
95 #if defined(CONFIG_DYNAMIC_DEBUG)
96 #include <linux/dynamic_debug.h>
97
98 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
99 #define pr_debug(fmt, ...) \
100         dynamic_pr_debug(fmt, ##__VA_ARGS__)
101 #elif defined(DEBUG)
102 #define pr_debug(fmt, ...) \
103         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
104 #else
105 #define pr_debug(fmt, ...) \
106         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
107 #endif
108
109 /*
110  * Print a one-time message (analogous to WARN_ONCE() et al):
111  */
112
113 #define printk_once(fmt, ...)                                   \
114 ({                                                              \
115         static bool __print_once __read_mostly;                 \
116         bool __ret_print_once = !__print_once;                  \
117                                                                 \
118         if (!__print_once) {                                    \
119                 __print_once = true;                            \
120                 printk(fmt, ##__VA_ARGS__);                     \
121         }                                                       \
122         unlikely(__ret_print_once);                             \
123 })
124 #define printk_deferred_once(fmt, ...)                          \
125 ({                                                              \
126         static bool __print_once __read_mostly;                 \
127         bool __ret_print_once = !__print_once;                  \
128                                                                 \
129         if (!__print_once) {                                    \
130                 __print_once = true;                            \
131                 printk_deferred(fmt, ##__VA_ARGS__);            \
132         }                                                       \
133         unlikely(__ret_print_once);                             \
134 })
135
136 #define pr_emerg_once(fmt, ...)                                 \
137         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
138 #define pr_alert_once(fmt, ...)                                 \
139         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
140 #define pr_crit_once(fmt, ...)                                  \
141         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
142 #define pr_err_once(fmt, ...)                                   \
143         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
144 #define pr_warn_once(fmt, ...)                                  \
145         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
146 #define pr_notice_once(fmt, ...)                                \
147         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
148 #define pr_info_once(fmt, ...)                                  \
149         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
150 #define pr_cont_once(fmt, ...)                                  \
151         printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
152
153 #if defined(DEBUG)
154 #define pr_devel_once(fmt, ...)                                 \
155         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
156 #else
157 #define pr_devel_once(fmt, ...)                                 \
158         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
159 #endif
160
161 /* If you are writing a driver, please use dev_dbg instead */
162 #if defined(DEBUG)
163 #define pr_debug_once(fmt, ...)                                 \
164         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
165 #else
166 #define pr_debug_once(fmt, ...)                                 \
167         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
168 #endif
169
170 /*
171  * ratelimited messages with local ratelimit_state,
172  * no local ratelimit_state used in the !PRINTK case
173  */
174 #define printk_ratelimited(fmt, ...)                                    \
175 ({                                                                      \
176         static DEFINE_RATELIMIT_STATE(_rs,                              \
177                                       DEFAULT_RATELIMIT_INTERVAL,       \
178                                       DEFAULT_RATELIMIT_BURST);         \
179                                                                         \
180         if (__ratelimit(&_rs))                                          \
181                 printk(fmt, ##__VA_ARGS__);                             \
182 })
183
184 #define pr_emerg_ratelimited(fmt, ...)                                  \
185         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
186 #define pr_alert_ratelimited(fmt, ...)                                  \
187         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
188 #define pr_crit_ratelimited(fmt, ...)                                   \
189         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
190 #define pr_err_ratelimited(fmt, ...)                                    \
191         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
192 #define pr_warn_ratelimited(fmt, ...)                                   \
193         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
194 #define pr_notice_ratelimited(fmt, ...)                                 \
195         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
196 #define pr_info_ratelimited(fmt, ...)                                   \
197         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
198 /* no pr_cont_ratelimited, don't do that... */
199
200 #if defined(DEBUG)
201 #define pr_devel_ratelimited(fmt, ...)                                  \
202         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
203 #else
204 #define pr_devel_ratelimited(fmt, ...)                                  \
205         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
206 #endif
207 #endif /* __TOOLS_LINUX_PRINTK_H */