X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;ds=sidebyside;f=lib.c;h=e36382927e158d007eed9bdbb13a3246c73f8f97;hb=99ff52b783574342c2859359aa6c39229bd5dcda;hp=4af9b804dae2a26a22885eb29735025b97564953;hpb=703b99b834625829d6b285e5bca619475ef54511;p=userv.git diff --git a/lib.c b/lib.c index 4af9b80..e363829 100644 --- a/lib.c +++ b/lib.c @@ -25,11 +25,13 @@ #include #include #include +#include #include "config.h" +#include "common.h" #include "lib.h" -char *xmstrcat3save(const char *a, const char *b, const char *c) { +char *xstrcat3save(const char *a, const char *b, const char *c) { char *r; r= xmalloc(strlen(a)+strlen(b)+strlen(c)+1); @@ -39,7 +41,7 @@ char *xmstrcat3save(const char *a, const char *b, const char *c) { return r; } -char *xmstrsave(const char *s) { +char *xstrsave(const char *s) { char *r; r= xmalloc(strlen(s)+1); @@ -47,7 +49,7 @@ char *xmstrsave(const char *s) { return r; } -char *xmstrsubsave(const char *begin, int len) { +char *xstrsubsave(const char *begin, int len) { char *r; r= xmalloc(len+1); @@ -67,16 +69,12 @@ void *xrealloc(void *p, size_t s) { return p; } -char *xstrdup(const char *str) { - char *r; - r= xmalloc(strlen(str)+1); - strcpy(r,str); return r; -} - -void makeroom(char **buffer, int *size, int needed) { - if (*size >= needed) return; +int makeroom(char **buffer, int *size, int needed) { + if (needed > MAX_GENERAL_STRING) return -1; + if (*size >= needed) return 0; *buffer= xrealloc(*buffer,needed); *size= needed; + return 0; } void vsnyprintf(char *buffer, size_t size, const char *fmt, va_list al) {