Lines Matching +full:buffer +full:- +full:size
1 /* SPDX-License-Identifier: GPL-2.0 */
16 * struct seq_buf - seq buffer structure
17 * @buffer: pointer to the buffer
18 * @size: size of the buffer
19 * @len: the amount of data inside the buffer
22 char *buffer; member
23 size_t size; member
27 #define DECLARE_SEQ_BUF(NAME, SIZE) \ argument
29 .buffer = (char[SIZE]) { 0 }, \
30 .size = SIZE, \
35 s->len = 0; in seq_buf_clear()
36 if (s->size) in seq_buf_clear()
37 s->buffer[0] = '\0'; in seq_buf_clear()
41 seq_buf_init(struct seq_buf *s, char *buf, unsigned int size) in seq_buf_init() argument
43 s->buffer = buf; in seq_buf_init()
44 s->size = size; in seq_buf_init()
49 * seq_buf have a buffer that might overflow. When this happens
50 * len is set to be greater than size.
55 return s->len > s->size; in seq_buf_has_overflowed()
61 s->len = s->size + 1; in seq_buf_set_overflow()
65 * How much buffer is left on the seq_buf?
73 return s->size - s->len; in seq_buf_buffer_left()
76 /* How much buffer was written? */
79 return min(s->len, s->size); in seq_buf_used()
83 * seq_buf_str - get NUL-terminated C string from seq_buf
86 * This makes sure that the buffer in @s is NUL-terminated and
89 * Note, if this is called when the buffer has overflowed, then
90 * the last byte of the buffer is zeroed, and the len will still
93 * After this function is called, s->buffer is safe to use
96 * Returns: @s->buf after making sure it is terminated.
100 if (WARN_ON(s->size == 0)) in seq_buf_str()
104 s->buffer[s->len] = 0; in seq_buf_str()
106 s->buffer[s->size - 1] = 0; in seq_buf_str()
108 return s->buffer; in seq_buf_str()
112 * seq_buf_get_buf - get buffer to write arbitrary data to
114 * @bufp: the beginning of the buffer is stored here
116 * Returns: the number of bytes available in the buffer, or zero if
121 WARN_ON(s->len > s->size + 1); in seq_buf_get_buf()
123 if (s->len < s->size) { in seq_buf_get_buf()
124 *bufp = s->buffer + s->len; in seq_buf_get_buf()
125 return s->size - s->len; in seq_buf_get_buf()
133 * seq_buf_commit - commit data to the buffer
137 * Commit @num bytes of data written to a buffer previously acquired
147 BUG_ON(s->len + num > s->size); in seq_buf_commit()
148 s->len += num; in seq_buf_commit()