X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv.git;a=blobdiff_plain;f=lib.c;h=1352afa24d74fedcf48c2f369ebda1187f5ec33e;hp=bd40ee08ab77376f74b1ce5715b9740a16c82e71;hb=1a6d1b28a51911483a6fb2b476028c3b3c1f48c8;hpb=78032a78185e751a0bf0b77863f23d005359205f diff --git a/lib.c b/lib.c index bd40ee0..1352afa 100644 --- a/lib.c +++ b/lib.c @@ -31,6 +31,7 @@ #include "config.h" #include "common.h" #include "lib.h" +#include "both.h" char *xstrcat3save(const char *a, const char *b, const char *c) { char *r; @@ -42,14 +43,6 @@ char *xstrcat3save(const char *a, const char *b, const char *c) { return r; } -char *xstrsave(const char *s) { - char *r; - - r= xmalloc(strlen(s)+1); - strcpy(r,s); - return r; -} - char *xstrsubsave(const char *begin, int len) { char *r; @@ -59,17 +52,6 @@ char *xstrsubsave(const char *begin, int len) { return r; } -void *xmalloc(size_t s) { - void *p; - p= malloc(s?s:1); if (!p) syscallerror("malloc"); - return p; -} - -void *xrealloc(void *p, size_t s) { - p= realloc(p,s); if (!p) syscallerror("realloc"); - return p; -} - int makeroom(char **buffer, int *size, int needed) { if (needed > MAX_GENERAL_STRING) return -1; if (*size >= needed) return 0; @@ -116,14 +98,10 @@ void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) { #ifndef HAVE_SETENV int setenv(const char *name, const char *value, int overwrite) { - static char *buffer= 0; - static int avail= 0; - - int r; + char *buffer= 0; assert(overwrite==1); - r= makeroom(&buffer,&avail,strlen(name)+strlen(value)+2); - if (r) { errno= EINVAL; return -1; } + buffer= xmalloc(strlen(name)+strlen(value)+2); sprintf(buffer,"%s=%s",name,value); return putenv(buffer);