Lines Matching refs:buf
13 static inline unsigned __printbuf_linelen(struct printbuf *buf, unsigned pos) in __printbuf_linelen() argument
15 return pos - buf->last_newline; in __printbuf_linelen()
18 static inline unsigned printbuf_linelen(struct printbuf *buf) in printbuf_linelen() argument
20 return __printbuf_linelen(buf, buf->pos); in printbuf_linelen()
26 static inline unsigned cur_tabstop(struct printbuf *buf) in cur_tabstop() argument
28 return buf->cur_tabstop < buf->nr_tabstops in cur_tabstop()
29 ? buf->_tabstops[buf->cur_tabstop] in cur_tabstop()
59 char *buf = krealloc(out->buf, new_size, !out->atomic ? GFP_KERNEL : GFP_NOWAIT); in bch2_printbuf_make_room() local
61 if (!buf) { in bch2_printbuf_make_room()
67 out->buf = buf; in bch2_printbuf_make_room()
84 memmove(out->buf + pos + nr, in printbuf_insert_spaces()
85 out->buf + pos, in printbuf_insert_spaces()
89 memset(out->buf + pos, ' ', min(nr, out->size - pos)); in printbuf_insert_spaces()
100 char *p = out->buf + pos; in __printbuf_do_indent()
107 pos = n - out->buf; in __printbuf_do_indent()
166 len = vsnprintf(out->buf + out->pos, printbuf_remaining_size(out), fmt, args2); in bch2_prt_vprintf()
183 len = vsnprintf(out->buf + out->pos, printbuf_remaining_size(out), fmt, args); in bch2_prt_printf()
199 const char *bch2_printbuf_str(const struct printbuf *buf) in bch2_printbuf_str() argument
206 return buf->pos in bch2_printbuf_str()
207 ? buf->buf in bch2_printbuf_str()
216 void bch2_printbuf_exit(struct printbuf *buf) in bch2_printbuf_exit() argument
218 if (buf->heap_allocated) { in bch2_printbuf_exit()
219 kfree(buf->buf); in bch2_printbuf_exit()
220 buf->buf = ERR_PTR(-EINTR); /* poison value */ in bch2_printbuf_exit()
224 void bch2_printbuf_tabstops_reset(struct printbuf *buf) in bch2_printbuf_tabstops_reset() argument
226 buf->nr_tabstops = 0; in bch2_printbuf_tabstops_reset()
229 void bch2_printbuf_tabstop_pop(struct printbuf *buf) in bch2_printbuf_tabstop_pop() argument
231 if (buf->nr_tabstops) in bch2_printbuf_tabstop_pop()
232 --buf->nr_tabstops; in bch2_printbuf_tabstop_pop()
245 int bch2_printbuf_tabstop_push(struct printbuf *buf, unsigned spaces) in bch2_printbuf_tabstop_push() argument
247 unsigned prev_tabstop = buf->nr_tabstops in bch2_printbuf_tabstop_push()
248 ? buf->_tabstops[buf->nr_tabstops - 1] in bch2_printbuf_tabstop_push()
251 if (WARN_ON(buf->nr_tabstops >= ARRAY_SIZE(buf->_tabstops))) in bch2_printbuf_tabstop_push()
254 buf->_tabstops[buf->nr_tabstops++] = prev_tabstop + spaces; in bch2_printbuf_tabstop_push()
255 buf->has_indent_or_tabstops = true; in bch2_printbuf_tabstop_push()
268 void bch2_printbuf_indent_add(struct printbuf *buf, unsigned spaces) in bch2_printbuf_indent_add() argument
270 if (WARN_ON_ONCE(buf->indent + spaces < buf->indent)) in bch2_printbuf_indent_add()
273 buf->indent += spaces; in bch2_printbuf_indent_add()
274 prt_chars(buf, ' ', spaces); in bch2_printbuf_indent_add()
276 buf->has_indent_or_tabstops = true; in bch2_printbuf_indent_add()
288 void bch2_printbuf_indent_sub(struct printbuf *buf, unsigned spaces) in bch2_printbuf_indent_sub() argument
290 if (WARN_ON_ONCE(spaces > buf->indent)) in bch2_printbuf_indent_sub()
291 spaces = buf->indent; in bch2_printbuf_indent_sub()
293 if (buf->last_newline + buf->indent == buf->pos) { in bch2_printbuf_indent_sub()
294 buf->pos -= spaces; in bch2_printbuf_indent_sub()
295 printbuf_nul_terminate(buf); in bch2_printbuf_indent_sub()
297 buf->indent -= spaces; in bch2_printbuf_indent_sub()
299 if (!buf->indent && !buf->nr_tabstops) in bch2_printbuf_indent_sub()
300 buf->has_indent_or_tabstops = false; in bch2_printbuf_indent_sub()
303 void bch2_prt_newline(struct printbuf *buf) in bch2_prt_newline() argument
305 bch2_printbuf_make_room(buf, 1 + buf->indent); in bch2_prt_newline()
307 __prt_char_reserved(buf, '\n'); in bch2_prt_newline()
309 buf->last_newline = buf->pos; in bch2_prt_newline()
311 __prt_chars_reserved(buf, ' ', buf->indent); in bch2_prt_newline()
313 printbuf_nul_terminate_reserved(buf); in bch2_prt_newline()
315 buf->last_field = buf->pos; in bch2_prt_newline()
316 buf->cur_tabstop = 0; in bch2_prt_newline()
322 if (out->buf[p] == '\n') { in bch2_printbuf_strip_trailing_newline()
326 if (out->buf[p] != ' ') in bch2_printbuf_strip_trailing_newline()
357 static void __prt_tab_rjust(struct printbuf *buf) in __prt_tab_rjust() argument
359 int pad = (int) cur_tabstop(buf) - (int) printbuf_linelen(buf); in __prt_tab_rjust()
361 printbuf_insert_spaces(buf, buf->last_field, pad); in __prt_tab_rjust()
363 buf->last_field = buf->pos; in __prt_tab_rjust()
364 buf->cur_tabstop++; in __prt_tab_rjust()
376 void bch2_prt_tab_rjust(struct printbuf *buf) in bch2_prt_tab_rjust() argument
378 if (WARN_ON(!cur_tabstop(buf))) in bch2_prt_tab_rjust()
381 __prt_tab_rjust(buf); in bch2_prt_tab_rjust()
414 out->buf + out->pos, in bch2_prt_human_readable_u64()