/* * vstring.c - Variable-length strings * * Copyright 2012 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. */ #include #include #include "vstring.h" void append_n(char **res, int *res_len, const char *s, int len) { if (!len) return; if (!*res) *res_len = 0; *res = realloc(*res, *res_len+len+1); if (!*res) abort(); memcpy(*res+*res_len, s, len); *res_len += len; (*res)[*res_len] = 0; } void append(char **res, int *res_len, const char *s) { append_n(res, res_len, s, strlen(s)); }