Lines Matching defs:ad

45 resize(atf_dynstr_t *ad, size_t newsize)
50 PRE(newsize > ad->m_datasize);
56 strcpy(newdata, ad->m_data);
57 free(ad->m_data);
58 ad->m_data = newdata;
59 ad->m_datasize = newsize;
68 prepend_or_append(atf_dynstr_t *ad, const char *fmt, va_list ap,
81 newlen = ad->m_length + strlen(aux);
83 if (newlen + sizeof(char) > ad->m_datasize) {
84 err = resize(ad, newlen + sizeof(char));
90 memmove(ad->m_data + strlen(aux), ad->m_data, ad->m_length + 1);
91 memcpy(ad->m_data, aux, strlen(aux));
93 strcpy(ad->m_data + ad->m_length, aux);
94 ad->m_length = newlen;
118 atf_dynstr_init(atf_dynstr_t *ad)
122 ad->m_data = (char *)malloc(sizeof(char));
123 if (ad->m_data == NULL) {
128 ad->m_data[0] = '\0';
129 ad->m_datasize = 1;
130 ad->m_length = 0;
138 atf_dynstr_init_ap(atf_dynstr_t *ad, const char *fmt, va_list ap)
142 ad->m_datasize = strlen(fmt) + 1;
143 ad->m_length = 0;
149 ad->m_datasize *= 2;
150 ad->m_data = (char *)malloc(ad->m_datasize);
151 if (ad->m_data == NULL) {
157 ret = vsnprintf(ad->m_data, ad->m_datasize, fmt, ap2);
160 free(ad->m_data);
166 if ((size_t)ret >= ad->m_datasize) {
167 free(ad->m_data);
168 ad->m_data = NULL;
170 ad->m_length = ret;
171 } while (ad->m_length >= ad->m_datasize);
175 POST(atf_is_error(err) || ad->m_data != NULL);
180 atf_dynstr_init_fmt(atf_dynstr_t *ad, const char *fmt, ...)
186 err = atf_dynstr_init_ap(ad, fmt, ap);
193 atf_dynstr_init_raw(atf_dynstr_t *ad, const void *mem, size_t memlen)
202 ad->m_data = (char *)malloc(memlen + 1);
203 if (ad->m_data == NULL) {
208 ad->m_datasize = memlen + 1;
209 memcpy(ad->m_data, mem, memlen);
210 ad->m_data[memlen] = '\0';
211 ad->m_length = strlen(ad->m_data);
212 INV(ad->m_length <= memlen);
220 atf_dynstr_init_rep(atf_dynstr_t *ad, size_t len, char ch)
229 ad->m_datasize = (len + 1) * sizeof(char);
230 ad->m_data = (char *)malloc(ad->m_datasize);
231 if (ad->m_data == NULL) {
236 memset(ad->m_data, ch, len);
237 ad->m_data[len] = '\0';
238 ad->m_length = len;
246 atf_dynstr_init_substr(atf_dynstr_t *ad, const atf_dynstr_t *src,
255 return atf_dynstr_init_raw(ad, src->m_data + beg, end - beg);
277 atf_dynstr_fini(atf_dynstr_t *ad)
279 INV(ad->m_data != NULL);
280 free(ad->m_data);
284 atf_dynstr_fini_disown(atf_dynstr_t *ad)
286 INV(ad->m_data != NULL);
287 return ad->m_data;
295 atf_dynstr_cstring(const atf_dynstr_t *ad)
297 return ad->m_data;
301 atf_dynstr_length(const atf_dynstr_t *ad)
303 return ad->m_length;
307 atf_dynstr_rfind_ch(const atf_dynstr_t *ad, char ch)
311 for (pos = ad->m_length; pos > 0 && ad->m_data[pos - 1] != ch; pos--)
322 atf_dynstr_append_ap(atf_dynstr_t *ad, const char *fmt, va_list ap)
328 err = prepend_or_append(ad, fmt, ap2, false);
335 atf_dynstr_append_fmt(atf_dynstr_t *ad, const char *fmt, ...)
341 err = prepend_or_append(ad, fmt, ap, false);
348 atf_dynstr_clear(atf_dynstr_t *ad)
350 ad->m_data[0] = '\0';
351 ad->m_length = 0;
355 atf_dynstr_prepend_ap(atf_dynstr_t *ad, const char *fmt, va_list ap)
361 err = prepend_or_append(ad, fmt, ap2, true);
368 atf_dynstr_prepend_fmt(atf_dynstr_t *ad, const char *fmt, ...)
374 err = prepend_or_append(ad, fmt, ap, true);
385 atf_equal_dynstr_cstring(const atf_dynstr_t *ad, const char *str)
387 return strcmp(ad->m_data, str) == 0;