X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=x2p%2Futil.c;h=5c3554b7e3e93581ae601d1066c44e33b3f7318f;hb=9c7d862108a3f02f3db65204f8154cdfe689040e;hp=0d98de807c8f2949a4464297048a916bc414f2d0;hpb=378cc40b38293ffc7298c6a7ed3cd740ad79be52;p=p5sagit%2Fp5-mst-13.2.git diff --git a/x2p/util.c b/x2p/util.c index 0d98de8..5c3554b 100644 --- a/x2p/util.c +++ b/x2p/util.c @@ -1,36 +1,33 @@ -/* $Header: util.c,v 2.0 88/06/05 00:16:07 root Exp $ +/* $RCSfile: util.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:29 $ + * + * Copyright (c) 1991, Larry Wall + * + * You may distribute under the terms of either the GNU General Public + * License or the Artistic License, as specified in the README file. * * $Log: util.c,v $ - * Revision 2.0 88/06/05 00:16:07 root - * Baseline version 2.0. - * */ -#include - -#include "handy.h" #include "EXTERN.h" #include "a2p.h" #include "INTERN.h" #include "util.h" #define FLUSH -#define MEM_SIZE unsigned int static char nomem[] = "Out of memory!\n"; /* paranoid version of malloc */ -static int an = 0; -char * +Malloc_t safemalloc(size) MEM_SIZE size; { char *ptr; - char *malloc(); + Malloc_t malloc(); - ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */ + ptr = (char *) malloc(size?size:1); /* malloc(0) is NASTY on our system */ #ifdef DEBUGGING if (debug & 128) fprintf(stderr,"0x%x: (%05d) malloc %d bytes\n",ptr,an++,size); @@ -46,15 +43,16 @@ MEM_SIZE size; /* paranoid version of realloc */ -char * +Malloc_t saferealloc(where,size) char *where; MEM_SIZE size; { char *ptr; - char *realloc(); + Malloc_t realloc(); - ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */ + ptr = (char *) + realloc(where,size?size:1); /* realloc(0) is NASTY on our system */ #ifdef DEBUGGING if (debug & 128) { fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++); @@ -72,6 +70,7 @@ MEM_SIZE size; /* safe version of free */ +void safefree(where) char *where; { @@ -98,36 +97,6 @@ register int len; return to; } -#ifdef undef -/* safe version of string concatenate, with \n deletion and space padding */ - -char * -safecat(to,from,len) -char *to; -register char *from; -register int len; -{ - register char *dest = to; - - len--; /* leave room for null */ - if (*dest) { - while (len && *dest++) len--; - if (len) { - len--; - *(dest-1) = ' '; - } - } - if (from != Nullch) - while (len && (*dest++ = *from++)) len--; - if (len) - dest--; - if (*(dest-1) == '\n') - dest--; - *dest = '\0'; - return to; -} -#endif - /* copy a string up to some (non-backslashed) delimiter, if any */ char * @@ -221,60 +190,31 @@ int newlen; } /*VARARGS1*/ -fatal(pat,a1,a2,a3,a4) +void +croak(pat,a1,a2,a3,a4) char *pat; +int a1,a2,a3,a4; { fprintf(stderr,pat,a1,a2,a3,a4); exit(1); } -static bool firstsetenv = TRUE; -extern char **environ; - +/*VARARGS1*/ void -setenv(nam,val) -char *nam, *val; +fatal(pat,a1,a2,a3,a4) +char *pat; +int a1,a2,a3,a4; { - register int i=envix(nam); /* where does it go? */ - - if (!environ[i]) { /* does not exist yet */ - if (firstsetenv) { /* need we copy environment? */ - int j; -#ifndef lint - char **tmpenv = (char**) /* point our wand at memory */ - safemalloc((i+2) * sizeof(char*)); -#else - char **tmpenv = Null(char **); -#endif /* lint */ - - firstsetenv = FALSE; - for (j=0; j