Lines Matching +full:out +full:-
1 /* SPDX-License-Identifier: LGPL-2.1+ */
25 * everything to the kernel log buffer, and then those pretty-printers can be
33 * will be done with GFP_NOWAIT if printbuf->atomic is nonzero.
40 * memory allocation failure we usually don't want to bail out and unwind - we
41 * want to print what we've got, on a best-effort basis. But code that does want
42 * to return -ENOMEM may check printbuf.allocation_failure.
46 * To aid is writing multi-line pretty printers spread across multiple
52 * To use tabstops, set printbuf->tabstops[]; they are in units of spaces, from
56 * next tabstop - right justifying it.
61 * Output units: printbuf->units exists to tell pretty-printers how to output
105 __printf(2, 3) void bch2_prt_printf(struct printbuf *out, const char *fmt, ...);
106 __printf(2, 0) void bch2_prt_vprintf(struct printbuf *out, const char *fmt, va_list);
145 static inline unsigned printbuf_remaining_size(struct printbuf *out) in printbuf_remaining_size() argument
147 if (WARN_ON(out->size && out->pos >= out->size)) in printbuf_remaining_size()
148 out->pos = out->size - 1; in printbuf_remaining_size()
149 return out->size - out->pos; in printbuf_remaining_size()
153 * Returns number of characters we can print to the output buffer - i.e.
156 static inline unsigned printbuf_remaining(struct printbuf *out) in printbuf_remaining() argument
158 return out->size ? printbuf_remaining_size(out) - 1 : 0; in printbuf_remaining()
161 static inline unsigned printbuf_written(struct printbuf *out) in printbuf_written() argument
163 return out->size ? min(out->pos, out->size - 1) : 0; in printbuf_written()
166 static inline void printbuf_nul_terminate_reserved(struct printbuf *out) in printbuf_nul_terminate_reserved() argument
168 if (WARN_ON(out->size && out->pos >= out->size)) in printbuf_nul_terminate_reserved()
169 out->pos = out->size - 1; in printbuf_nul_terminate_reserved()
170 if (out->size) in printbuf_nul_terminate_reserved()
171 out->buf[out->pos] = 0; in printbuf_nul_terminate_reserved()
174 static inline void printbuf_nul_terminate(struct printbuf *out) in printbuf_nul_terminate() argument
176 bch2_printbuf_make_room(out, 1); in printbuf_nul_terminate()
177 printbuf_nul_terminate_reserved(out); in printbuf_nul_terminate()
181 static inline void __prt_char_reserved(struct printbuf *out, char c) in __prt_char_reserved() argument
183 if (printbuf_remaining(out)) in __prt_char_reserved()
184 out->buf[out->pos++] = c; in __prt_char_reserved()
188 static inline void __prt_char(struct printbuf *out, char c) in __prt_char() argument
190 bch2_printbuf_make_room(out, 1); in __prt_char()
191 __prt_char_reserved(out, c); in __prt_char()
194 static inline void prt_char(struct printbuf *out, char c) in prt_char() argument
196 bch2_printbuf_make_room(out, 2); in prt_char()
197 __prt_char_reserved(out, c); in prt_char()
198 printbuf_nul_terminate_reserved(out); in prt_char()
201 static inline void __prt_chars_reserved(struct printbuf *out, char c, unsigned n) in __prt_chars_reserved() argument
203 unsigned can_print = min(n, printbuf_remaining(out)); in __prt_chars_reserved()
206 out->buf[out->pos++] = c; in __prt_chars_reserved()
209 static inline void prt_chars(struct printbuf *out, char c, unsigned n) in prt_chars() argument
211 bch2_printbuf_make_room(out, n); in prt_chars()
212 __prt_chars_reserved(out, c, n); in prt_chars()
213 printbuf_nul_terminate_reserved(out); in prt_chars()
216 static inline void prt_bytes(struct printbuf *out, const void *b, unsigned n) in prt_bytes() argument
218 bch2_printbuf_make_room(out, n); in prt_bytes()
220 unsigned can_print = min(n, printbuf_remaining(out)); in prt_bytes()
223 out->buf[out->pos++] = ((char *) b)[i]; in prt_bytes()
225 printbuf_nul_terminate(out); in prt_bytes()
228 static inline void prt_str(struct printbuf *out, const char *str) in prt_str() argument
230 prt_bytes(out, str, strlen(str)); in prt_str()
233 static inline void prt_str_indented(struct printbuf *out, const char *str) in prt_str_indented() argument
235 bch2_prt_bytes_indented(out, str, strlen(str)); in prt_str_indented()
238 static inline void prt_hex_byte(struct printbuf *out, u8 byte) in prt_hex_byte() argument
240 bch2_printbuf_make_room(out, 3); in prt_hex_byte()
241 __prt_char_reserved(out, hex_asc_hi(byte)); in prt_hex_byte()
242 __prt_char_reserved(out, hex_asc_lo(byte)); in prt_hex_byte()
243 printbuf_nul_terminate_reserved(out); in prt_hex_byte()
246 static inline void prt_hex_byte_upper(struct printbuf *out, u8 byte) in prt_hex_byte_upper() argument
248 bch2_printbuf_make_room(out, 3); in prt_hex_byte_upper()
249 __prt_char_reserved(out, hex_asc_upper_hi(byte)); in prt_hex_byte_upper()
250 __prt_char_reserved(out, hex_asc_upper_lo(byte)); in prt_hex_byte_upper()
251 printbuf_nul_terminate_reserved(out); in prt_hex_byte_upper()
255 * printbuf_reset - re-use a printbuf without freeing and re-initializing it:
259 buf->pos = 0; in printbuf_reset()
260 buf->allocation_failure = 0; in printbuf_reset()
261 buf->indent = 0; in printbuf_reset()
262 buf->nr_tabstops = 0; in printbuf_reset()
263 buf->cur_tabstop = 0; in printbuf_reset()
267 * printbuf_atomic_inc - mark as entering an atomic section
271 buf->atomic++; in printbuf_atomic_inc()
275 * printbuf_atomic_inc - mark as leaving an atomic section
279 buf->atomic--; in printbuf_atomic_dec()