Lines Matching refs:buf

22 static struct wpabuf_trace * wpabuf_get_trace(const struct wpabuf *buf)  in wpabuf_get_trace()  argument
25 ((const u8 *) buf - sizeof(struct wpabuf_trace)); in wpabuf_get_trace()
30 static void wpabuf_overflow(const struct wpabuf *buf, size_t len) in wpabuf_overflow() argument
33 struct wpabuf_trace *trace = wpabuf_get_trace(buf); in wpabuf_overflow()
40 buf, (unsigned long) buf->size, (unsigned long) buf->used, in wpabuf_overflow()
49 struct wpabuf *buf = *_buf; in wpabuf_resize() local
54 if (buf == NULL) { in wpabuf_resize()
60 trace = wpabuf_get_trace(buf); in wpabuf_resize()
69 if (buf->used + add_len > buf->size) { in wpabuf_resize()
71 if (buf->flags & WPABUF_FLAG_EXT_DATA) { in wpabuf_resize()
72 nbuf = os_realloc(buf->buf, buf->used + add_len); in wpabuf_resize()
75 os_memset(nbuf + buf->used, 0, add_len); in wpabuf_resize()
76 buf->buf = nbuf; in wpabuf_resize()
81 buf->used + add_len); in wpabuf_resize()
85 buf = (struct wpabuf *) (trace + 1); in wpabuf_resize()
87 sizeof(struct wpabuf) + buf->used, 0, in wpabuf_resize()
90 nbuf = os_realloc(buf, sizeof(struct wpabuf) + in wpabuf_resize()
91 buf->used + add_len); in wpabuf_resize()
94 buf = (struct wpabuf *) nbuf; in wpabuf_resize()
95 os_memset(nbuf + sizeof(struct wpabuf) + buf->used, 0, in wpabuf_resize()
98 buf->buf = (u8 *) (buf + 1); in wpabuf_resize()
99 *_buf = buf; in wpabuf_resize()
101 buf->size = buf->used + add_len; in wpabuf_resize()
118 struct wpabuf *buf; in wpabuf_alloc() local
122 buf = (struct wpabuf *) (trace + 1); in wpabuf_alloc()
124 struct wpabuf *buf = os_zalloc(sizeof(struct wpabuf) + len); in wpabuf_alloc()
125 if (buf == NULL) in wpabuf_alloc()
129 buf->size = len; in wpabuf_alloc()
130 buf->buf = (u8 *) (buf + 1); in wpabuf_alloc()
131 return buf; in wpabuf_alloc()
140 struct wpabuf *buf; in wpabuf_alloc_ext_data() local
144 buf = (struct wpabuf *) (trace + 1); in wpabuf_alloc_ext_data()
146 struct wpabuf *buf = os_zalloc(sizeof(struct wpabuf)); in wpabuf_alloc_ext_data()
147 if (buf == NULL) in wpabuf_alloc_ext_data()
151 buf->size = len; in wpabuf_alloc_ext_data()
152 buf->used = len; in wpabuf_alloc_ext_data()
153 buf->buf = data; in wpabuf_alloc_ext_data()
154 buf->flags |= WPABUF_FLAG_EXT_DATA; in wpabuf_alloc_ext_data()
156 return buf; in wpabuf_alloc_ext_data()
162 struct wpabuf *buf = wpabuf_alloc(len); in wpabuf_alloc_copy() local
163 if (buf) in wpabuf_alloc_copy()
164 wpabuf_put_data(buf, data, len); in wpabuf_alloc_copy()
165 return buf; in wpabuf_alloc_copy()
171 struct wpabuf *buf = wpabuf_alloc(wpabuf_len(src)); in wpabuf_dup() local
172 if (buf) in wpabuf_dup()
173 wpabuf_put_data(buf, wpabuf_head(src), wpabuf_len(src)); in wpabuf_dup()
174 return buf; in wpabuf_dup()
182 void wpabuf_free(struct wpabuf *buf) in wpabuf_free() argument
186 if (buf == NULL) in wpabuf_free()
188 trace = wpabuf_get_trace(buf); in wpabuf_free()
195 if (buf->flags & WPABUF_FLAG_EXT_DATA) in wpabuf_free()
196 os_free(buf->buf); in wpabuf_free()
199 if (buf == NULL) in wpabuf_free()
201 if (buf->flags & WPABUF_FLAG_EXT_DATA) in wpabuf_free()
202 os_free(buf->buf); in wpabuf_free()
203 os_free(buf); in wpabuf_free()
208 void wpabuf_clear_free(struct wpabuf *buf) in wpabuf_clear_free() argument
210 if (buf) { in wpabuf_clear_free()
211 os_memset(wpabuf_mhead(buf), 0, wpabuf_len(buf)); in wpabuf_clear_free()
212 wpabuf_free(buf); in wpabuf_clear_free()
217 void * wpabuf_put(struct wpabuf *buf, size_t len) in wpabuf_put() argument
219 void *tmp = wpabuf_mhead_u8(buf) + wpabuf_len(buf); in wpabuf_put()
220 buf->used += len; in wpabuf_put()
221 if (buf->used > buf->size) { in wpabuf_put()
222 wpabuf_overflow(buf, len); in wpabuf_put()
277 struct wpabuf * wpabuf_zeropad(struct wpabuf *buf, size_t len) in wpabuf_zeropad() argument
282 if (buf == NULL) in wpabuf_zeropad()
285 blen = wpabuf_len(buf); in wpabuf_zeropad()
287 return buf; in wpabuf_zeropad()
292 wpabuf_put_buf(ret, buf); in wpabuf_zeropad()
294 wpabuf_free(buf); in wpabuf_zeropad()
300 void wpabuf_printf(struct wpabuf *buf, char *fmt, ...) in wpabuf_printf() argument
303 void *tmp = wpabuf_mhead_u8(buf) + wpabuf_len(buf); in wpabuf_printf()
307 res = vsnprintf(tmp, buf->size - buf->used, fmt, ap); in wpabuf_printf()
309 if (res < 0 || (size_t) res >= buf->size - buf->used) in wpabuf_printf()
310 wpabuf_overflow(buf, res); in wpabuf_printf()
311 buf->used += res; in wpabuf_printf()