Lines Matching refs:blob
44 grow_to_fit(struct blob *blob, size_t additional) in grow_to_fit() argument
49 if (blob->out_of_memory) in grow_to_fit()
52 if (blob->size + additional <= blob->allocated) in grow_to_fit()
55 if (blob->fixed_allocation) { in grow_to_fit()
56 blob->out_of_memory = true; in grow_to_fit()
60 if (blob->allocated == 0) in grow_to_fit()
63 to_allocate = blob->allocated * 2; in grow_to_fit()
65 to_allocate = MAX2(to_allocate, blob->allocated + additional); in grow_to_fit()
67 new_data = realloc(blob->data, to_allocate); in grow_to_fit()
69 blob->out_of_memory = true; in grow_to_fit()
73 blob->data = new_data; in grow_to_fit()
74 blob->allocated = to_allocate; in grow_to_fit()
86 align_blob(struct blob *blob, size_t alignment) in align_blob() argument
88 const size_t new_size = align64(blob->size, alignment); in align_blob()
90 if (blob->size < new_size) { in align_blob()
91 if (!grow_to_fit(blob, new_size - blob->size)) in align_blob()
94 if (blob->data) in align_blob()
95 memset(blob->data + blob->size, 0, new_size - blob->size); in align_blob()
96 blob->size = new_size; in align_blob()
103 align_blob_reader(struct blob_reader *blob, size_t alignment) in align_blob_reader() argument
105 blob->current = blob->data + align64(blob->current - blob->data, alignment); in align_blob_reader()
109 blob_init(struct blob *blob) in blob_init() argument
111 blob->data = NULL; in blob_init()
112 blob->allocated = 0; in blob_init()
113 blob->size = 0; in blob_init()
114 blob->fixed_allocation = false; in blob_init()
115 blob->out_of_memory = false; in blob_init()
119 blob_init_fixed(struct blob *blob, void *data, size_t size) in blob_init_fixed() argument
121 blob->data = data; in blob_init_fixed()
122 blob->allocated = size; in blob_init_fixed()
123 blob->size = 0; in blob_init_fixed()
124 blob->fixed_allocation = true; in blob_init_fixed()
125 blob->out_of_memory = false; in blob_init_fixed()
129 blob_finish_get_buffer(struct blob *blob, void **buffer, size_t *size) in blob_finish_get_buffer() argument
131 *buffer = blob->data; in blob_finish_get_buffer()
132 *size = blob->size; in blob_finish_get_buffer()
133 blob->data = NULL; in blob_finish_get_buffer()
140 blob_overwrite_bytes(struct blob *blob, in blob_overwrite_bytes() argument
146 if (offset + to_write < offset || blob->size < offset + to_write) in blob_overwrite_bytes()
151 if (blob->data) in blob_overwrite_bytes()
152 memcpy(blob->data + offset, bytes, to_write); in blob_overwrite_bytes()
158 blob_write_bytes(struct blob *blob, const void *bytes, size_t to_write) in blob_write_bytes() argument
160 if (! grow_to_fit(blob, to_write)) in blob_write_bytes()
165 if (blob->data && to_write > 0) in blob_write_bytes()
166 memcpy(blob->data + blob->size, bytes, to_write); in blob_write_bytes()
167 blob->size += to_write; in blob_write_bytes()
173 blob_reserve_bytes(struct blob *blob, size_t to_write) in blob_reserve_bytes() argument
177 if (! grow_to_fit (blob, to_write)) in blob_reserve_bytes()
180 ret = blob->size; in blob_reserve_bytes()
181 blob->size += to_write; in blob_reserve_bytes()
187 blob_reserve_uint32(struct blob *blob) in blob_reserve_uint32() argument
189 align_blob(blob, sizeof(uint32_t)); in blob_reserve_uint32()
190 return blob_reserve_bytes(blob, sizeof(uint32_t)); in blob_reserve_uint32()
194 blob_reserve_intptr(struct blob *blob) in blob_reserve_intptr() argument
196 align_blob(blob, sizeof(intptr_t)); in blob_reserve_intptr()
197 return blob_reserve_bytes(blob, sizeof(intptr_t)); in blob_reserve_intptr()
202 name(struct blob *blob, type value) \
204 align_blob(blob, sizeof(value)); \
205 return blob_write_bytes(blob, &value, sizeof(value)); \
218 blob_overwrite_uint8 (struct blob *blob, in BLOB_WRITE_TYPE()
223 return blob_overwrite_bytes(blob, offset, &value, sizeof(value)); in BLOB_WRITE_TYPE()
227 blob_overwrite_uint32 (struct blob *blob, in blob_overwrite_uint32() argument
232 return blob_overwrite_bytes(blob, offset, &value, sizeof(value)); in blob_overwrite_uint32()
236 blob_overwrite_intptr (struct blob *blob, in blob_overwrite_intptr() argument
241 return blob_overwrite_bytes(blob, offset, &value, sizeof(value)); in blob_overwrite_intptr()
245 blob_write_string(struct blob *blob, const char *str) in blob_write_string() argument
247 return blob_write_bytes(blob, str, strlen(str) + 1); in blob_write_string()
251 blob_reader_init(struct blob_reader *blob, const void *data, size_t size) in blob_reader_init() argument
253 blob->data = data; in blob_reader_init()
254 blob->end = blob->data + size; in blob_reader_init()
255 blob->current = data; in blob_reader_init()
256 blob->overrun = false; in blob_reader_init()
264 ensure_can_read(struct blob_reader *blob, size_t size) in ensure_can_read() argument
266 if (blob->overrun) in ensure_can_read()
269 if (blob->current <= blob->end && blob->end - blob->current >= size) in ensure_can_read()
272 blob->overrun = true; in ensure_can_read()
278 blob_read_bytes(struct blob_reader *blob, size_t size) in blob_read_bytes() argument
282 if (! ensure_can_read (blob, size)) in blob_read_bytes()
285 ret = blob->current; in blob_read_bytes()
287 blob->current += size; in blob_read_bytes()
293 blob_copy_bytes(struct blob_reader *blob, void *dest, size_t size) in blob_copy_bytes() argument
297 bytes = blob_read_bytes(blob, size); in blob_copy_bytes()
305 blob_skip_bytes(struct blob_reader *blob, size_t size) in blob_skip_bytes() argument
307 if (ensure_can_read (blob, size)) in blob_skip_bytes()
308 blob->current += size; in blob_skip_bytes()
318 name(struct blob_reader *blob) \
322 align_blob_reader(blob, size); \
323 if (! ensure_can_read(blob, size)) \
325 ret = *((type*) blob->current); \
326 blob->current += size; \
337 blob_read_string(struct blob_reader *blob) in BLOB_READ_TYPE()
344 if (blob->current >= blob->end) { in BLOB_READ_TYPE()
345 blob->overrun = true; in BLOB_READ_TYPE()
352 nul = memchr(blob->current, 0, blob->end - blob->current); in BLOB_READ_TYPE()
355 blob->overrun = true; in BLOB_READ_TYPE()
359 size = nul - blob->current + 1; in BLOB_READ_TYPE()
361 assert(ensure_can_read(blob, size)); in BLOB_READ_TYPE()
363 ret = (char *) blob->current; in BLOB_READ_TYPE()
365 blob->current += size; in BLOB_READ_TYPE()