1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-23 22:21:08 +02:00
eda-tools/b2/vstring.c

38 lines
760 B
C
Raw Normal View History

/*
* 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 <stdlib.h>
#include <string.h>
#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));
}