summaryrefslogblamecommitdiffstats
path: root/src/lib.c
blob: b6a5f3a8be4e72f81bc42283fdbd7c96e2968f84 (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);
	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);
	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;
}