Lines Matching refs:buf

13 static inline unsigned printbuf_linelen(struct printbuf *buf)
15 return buf->pos - buf->last_newline;
21 char *buf;
38 buf = krealloc(out->buf, new_size, !out->atomic ? GFP_KERNEL : GFP_NOWAIT);
40 if (!buf) {
45 out->buf = buf;
58 len = vsnprintf(out->buf + out->pos, printbuf_remaining(out), fmt, args2);
75 len = vsnprintf(out->buf + out->pos, printbuf_remaining(out), fmt, args);
86 * bch2_printbuf_str() - returns printbuf's buf as a C string, guaranteed to be
88 * @buf: printbuf to terminate
91 const char *bch2_printbuf_str(const struct printbuf *buf)
98 return buf->pos
99 ? buf->buf
106 * @buf: printbuf to exit
108 void bch2_printbuf_exit(struct printbuf *buf)
110 if (buf->heap_allocated) {
111 kfree(buf->buf);
112 buf->buf = ERR_PTR(-EINTR); /* poison value */
116 void bch2_printbuf_tabstops_reset(struct printbuf *buf)
118 buf->nr_tabstops = 0;
121 void bch2_printbuf_tabstop_pop(struct printbuf *buf)
123 if (buf->nr_tabstops)
124 --buf->nr_tabstops;
130 * @buf: printbuf to control
137 int bch2_printbuf_tabstop_push(struct printbuf *buf, unsigned spaces)
139 unsigned prev_tabstop = buf->nr_tabstops
140 ? buf->_tabstops[buf->nr_tabstops - 1]
143 if (WARN_ON(buf->nr_tabstops >= ARRAY_SIZE(buf->_tabstops)))
146 buf->_tabstops[buf->nr_tabstops++] = prev_tabstop + spaces;
147 buf->has_indent_or_tabstops = true;
154 * @buf: printbuf to control
160 void bch2_printbuf_indent_add(struct printbuf *buf, unsigned spaces)
162 if (WARN_ON_ONCE(buf->indent + spaces < buf->indent))
165 buf->indent += spaces;
166 prt_chars(buf, ' ', spaces);
168 buf->has_indent_or_tabstops = true;
174 * @buf: printbuf to control
180 void bch2_printbuf_indent_sub(struct printbuf *buf, unsigned spaces)
182 if (WARN_ON_ONCE(spaces > buf->indent))
183 spaces = buf->indent;
185 if (buf->last_newline + buf->indent == buf->pos) {
186 buf->pos -= spaces;
187 printbuf_nul_terminate(buf);
189 buf->indent -= spaces;
191 if (!buf->indent && !buf->nr_tabstops)
192 buf->has_indent_or_tabstops = false;
195 void bch2_prt_newline(struct printbuf *buf)
199 bch2_printbuf_make_room(buf, 1 + buf->indent);
201 __prt_char(buf, '\n');
203 buf->last_newline = buf->pos;
205 for (i = 0; i < buf->indent; i++)
206 __prt_char(buf, ' ');
208 printbuf_nul_terminate(buf);
210 buf->last_field = buf->pos;
211 buf->cur_tabstop = 0;
217 static inline unsigned cur_tabstop(struct printbuf *buf)
219 return buf->cur_tabstop < buf->nr_tabstops
220 ? buf->_tabstops[buf->cur_tabstop]
248 static void __prt_tab_rjust(struct printbuf *buf)
250 unsigned move = buf->pos - buf->last_field;
251 int pad = (int) cur_tabstop(buf) - (int) printbuf_linelen(buf);
254 bch2_printbuf_make_room(buf, pad);
256 if (buf->last_field + pad < buf->size)
257 memmove(buf->buf + buf->last_field + pad,
258 buf->buf + buf->last_field,
259 min(move, buf->size - 1 - buf->last_field - pad));
261 if (buf->last_field < buf->size)
262 memset(buf->buf + buf->last_field, ' ',
263 min((unsigned) pad, buf->size - buf->last_field));
265 buf->pos += pad;
266 printbuf_nul_terminate(buf);
269 buf->last_field = buf->pos;
270 buf->cur_tabstop++;
277 * @buf: printbuf to control
282 void bch2_prt_tab_rjust(struct printbuf *buf)
284 if (WARN_ON(!cur_tabstop(buf)))
287 __prt_tab_rjust(buf);
352 out->buf + out->pos,
376 * @buf->human_readable_units)
392 * @buf->human_readable_units)