Lines Matching refs:d
8 void data_free(struct data d) in data_free() argument
12 m = d.markers; in data_free()
20 if (d.val) in data_free()
21 free(d.val); in data_free()
24 struct data data_grow_for(struct data d, unsigned int xlen) in data_grow_for() argument
30 return d; in data_grow_for()
32 nd = d; in data_grow_for()
36 while ((d.len + xlen) > newsize) in data_grow_for()
39 nd.val = xrealloc(d.val, newsize); in data_grow_for()
46 struct data d; in data_copy_mem() local
48 d = data_grow_for(empty_data, len); in data_copy_mem()
50 d.len = len; in data_copy_mem()
51 memcpy(d.val, mem, len); in data_copy_mem()
53 return d; in data_copy_mem()
59 struct data d; in data_copy_escape_string() local
62 d = data_add_marker(empty_data, TYPE_STRING, NULL); in data_copy_escape_string()
63 d = data_grow_for(d, len + 1); in data_copy_escape_string()
65 q = d.val; in data_copy_escape_string()
72 q[d.len++] = c; in data_copy_escape_string()
75 q[d.len++] = '\0'; in data_copy_escape_string()
76 return d; in data_copy_escape_string()
81 struct data d = empty_data; in data_copy_file() local
83 d = data_add_marker(d, TYPE_NONE, NULL); in data_copy_file()
84 while (!feof(f) && (d.len < maxlen)) { in data_copy_file()
90 chunksize = maxlen - d.len; in data_copy_file()
92 d = data_grow_for(d, chunksize); in data_copy_file()
93 ret = fread(d.val + d.len, 1, chunksize, f); in data_copy_file()
98 if (d.len + ret < d.len) in data_copy_file()
101 d.len += ret; in data_copy_file()
104 return d; in data_copy_file()
107 struct data data_append_data(struct data d, const void *p, int len) in data_append_data() argument
109 d = data_grow_for(d, len); in data_append_data()
110 memcpy(d.val + d.len, p, len); in data_append_data()
111 d.len += len; in data_append_data()
112 return d; in data_append_data()
115 struct data data_insert_at_marker(struct data d, struct marker *m, in data_insert_at_marker() argument
118 d = data_grow_for(d, len); in data_insert_at_marker()
119 memmove(d.val + m->offset + len, d.val + m->offset, d.len - m->offset); in data_insert_at_marker()
120 memcpy(d.val + m->offset, p, len); in data_insert_at_marker()
121 d.len += len; in data_insert_at_marker()
127 return d; in data_insert_at_marker()
130 static struct data data_append_markers(struct data d, struct marker *m) in data_append_markers() argument
132 struct marker **mp = &d.markers; in data_append_markers()
138 return d; in data_append_markers()
143 struct data d; in data_merge() local
146 d = data_append_markers(data_append_data(d1, d2.val, d2.len), m2); in data_merge()
155 return d; in data_merge()
158 struct data data_append_integer(struct data d, uint64_t value, int bits) in data_append_integer() argument
168 return data_append_data(d, &value_8, 1); in data_append_integer()
172 return data_append_data(d, &value_16, 2); in data_append_integer()
176 return data_append_data(d, &value_32, 4); in data_append_integer()
180 return data_append_data(d, &value_64, 8); in data_append_integer()
187 struct data data_append_re(struct data d, uint64_t address, uint64_t size) in data_append_re() argument
194 return data_append_data(d, &re, sizeof(re)); in data_append_re()
197 struct data data_append_cell(struct data d, cell_t word) in data_append_cell() argument
199 return data_append_integer(d, word, sizeof(word) * 8); in data_append_cell()
202 struct data data_append_addr(struct data d, uint64_t addr) in data_append_addr() argument
204 return data_append_integer(d, addr, sizeof(addr) * 8); in data_append_addr()
207 struct data data_append_byte(struct data d, uint8_t byte) in data_append_byte() argument
209 return data_append_data(d, &byte, 1); in data_append_byte()
212 struct data data_append_zeroes(struct data d, int len) in data_append_zeroes() argument
214 d = data_grow_for(d, len); in data_append_zeroes()
216 memset(d.val + d.len, 0, len); in data_append_zeroes()
217 d.len += len; in data_append_zeroes()
218 return d; in data_append_zeroes()
221 struct data data_append_align(struct data d, int align) in data_append_align() argument
223 int newlen = ALIGN(d.len, align); in data_append_align()
224 return data_append_zeroes(d, newlen - d.len); in data_append_align()
227 struct data data_add_marker(struct data d, enum markertype type, char *ref) in data_add_marker() argument
232 m->offset = d.len; in data_add_marker()
237 return data_append_markers(d, m); in data_add_marker()
240 bool data_is_one_string(struct data d) in data_is_one_string() argument
243 int len = d.len; in data_is_one_string()
249 if (d.val[i] == '\0') in data_is_one_string()
252 if (d.val[len-1] != '\0') in data_is_one_string()