X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=userv.git;a=blobdiff_plain;f=lib.c;h=1352afa24d74fedcf48c2f369ebda1187f5ec33e;hp=e36382927e158d007eed9bdbb13a3246c73f8f97;hb=dc9e0a48601e4dc7b3060c1e816692f07e6be095;hpb=db59ee1476515a65cfcca10a3059d8ccb2d24d32 diff --git a/lib.c b/lib.c index e363829..1352afa 100644 --- a/lib.c +++ b/lib.c @@ -2,7 +2,7 @@ * userv - lib.c * useful utility routines, used in daemon, but not very dependent on it * - * Copyright (C)1996-1997 Ian Jackson + * Copyright (C)1996-1997,1999 Ian Jackson * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by @@ -25,11 +25,13 @@ #include #include #include +#include #include #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; @@ -41,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; @@ -58,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; @@ -112,3 +95,15 @@ void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) { vsnytprintfcat(buffer,size,fmt,al); va_end(al); } + +#ifndef HAVE_SETENV +int setenv(const char *name, const char *value, int overwrite) { + char *buffer= 0; + + assert(overwrite==1); + buffer= xmalloc(strlen(name)+strlen(value)+2); + + sprintf(buffer,"%s=%s",name,value); + return putenv(buffer); +} +#endif /* HAVE_SETENV */