blob: 5a611a35541ed9eb0cdcc8ee11d939fd814b109a (
plain) (
tree)
|
|
struct writefunc_string {
char *ptr;
size_t len;
};
void init_writefunc_string(struct writefunc_string *s) {
s->len = 0;
s->ptr = malloc(s->len+1+250);
if (s->ptr == NULL) {
fprintf(stderr, "malloc() " DC_I18N_FAILED "\n");
exit(EXIT_FAILURE);
}
s->ptr[0] = '\0';
}
size_t writefunc(void *ptr, size_t size, size_t nmemb, struct writefunc_string *s) {
size_t new_len = s->len + size*nmemb;
s->ptr = realloc(s->ptr, new_len+1+250);
if (s->ptr == NULL) {
fprintf(stderr, "realloc() " DC_I18N_FAILED "\n");
exit(EXIT_FAILURE);
}
memcpy(s->ptr+s->len, ptr, size*nmemb);
s->ptr[new_len] = '\0';
s->len = new_len;
return size*nmemb;
}
|