X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=x2p%2Futil.c;h=519fae5a8ab4c37ca70d9b337172d5c1606cf930;hb=1fd81fbbe87d964ad1f7dbdce41e36f3781dcf82;hp=07f19a37157094213f9c502dc0bb0ddd21d3a459;hpb=20188a906a3fc8fea4839293454a6ca32aa362cc;p=p5sagit%2Fp5-mst-13.2.git diff --git a/x2p/util.c b/x2p/util.c index 07f19a3..519fae5 100644 --- a/x2p/util.c +++ b/x2p/util.c @@ -1,44 +1,36 @@ -/* $Header: util.c,v 3.0.1.1 90/10/16 11:34:06 lwall Locked $ +/* $RCSfile: util.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:29 $ * - * Copyright (c) 1989, Larry Wall + * Copyright (c) 1991, Larry Wall * - * You may distribute under the terms of the GNU General Public License - * as specified in the README file that comes with the perl 3.0 kit. + * 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 3.0.1.1 90/10/16 11:34:06 lwall - * patch29: removed #ifdef undef - * - * Revision 3.0 89/10/18 15:35:35 lwall - * 3.0 baseline - * */ -#include - -#include "handy.h" #include "EXTERN.h" #include "a2p.h" #include "INTERN.h" #include "util.h" +#ifdef I_STDARG +# include +#endif #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 ptr; - ptr = malloc(size?size:1); /* malloc(0) is NASTY on our system */ + /* malloc(0) is NASTY on some systems */ + ptr = malloc(size ? size : 1); #ifdef DEBUGGING if (debug & 128) fprintf(stderr,"0x%x: (%05d) malloc %d bytes\n",ptr,an++,size); @@ -54,15 +46,15 @@ MEM_SIZE size; /* paranoid version of realloc */ -char * +Malloc_t saferealloc(where,size) -char *where; +Malloc_t where; MEM_SIZE size; { - char *ptr; - char *realloc(); + Malloc_t ptr; - ptr = realloc(where,size?size:1); /* realloc(0) is NASTY on our system */ + /* realloc(0) is NASTY on some systems */ + ptr = realloc(where, size ? size : 1); #ifdef DEBUGGING if (debug & 128) { fprintf(stderr,"0x%x: (%05d) rfree\n",where,an++); @@ -80,8 +72,9 @@ MEM_SIZE size; /* safe version of free */ +Free_t safefree(where) -char *where; +Malloc_t where; { #ifdef DEBUGGING if (debug & 128) @@ -198,68 +191,65 @@ int newlen; } } +void +#if defined(I_STDARG) && defined(HAS_VPRINTF) +croak(char *pat,...) +#else /* I_STDARG */ /*VARARGS1*/ -fatal(pat,a1,a2,a3,a4) -char *pat; +croak(pat,a1,a2,a3,a4) + char *pat; + int a1,a2,a3,a4; +#endif /* I_STDARG */ { +#if defined(I_STDARG) && defined(HAS_VPRINTF) + va_list args; + + va_start(args, pat); + vfprintf(stderr,pat,args); +#else fprintf(stderr,pat,a1,a2,a3,a4); +#endif exit(1); } +void +#if defined(I_STDARG) && defined(HAS_VPRINTF) +fatal(char *pat,...) +#else /* I_STDARG */ /*VARARGS1*/ -warn(pat,a1,a2,a3,a4) -char *pat; +fatal(pat,a1,a2,a3,a4) + char *pat; + int a1,a2,a3,a4; +#endif /* I_STDARG */ { +#if defined(I_STDARG) && defined(HAS_VPRINTF) + va_list args; + + va_start(args, pat); + vfprintf(stderr,pat,args); +#else fprintf(stderr,pat,a1,a2,a3,a4); +#endif + exit(1); } -static bool firstsetenv = TRUE; -extern char **environ; - void -setenv(nam,val) -char *nam, *val; +#if defined(I_STDARG) && defined(HAS_VPRINTF) +warn(char *pat,...) +#else /* I_STDARG */ +/*VARARGS1*/ +warn(pat,a1,a2,a3,a4) + char *pat; + int a1,a2,a3,a4; +#endif /* I_STDARG */ { - 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*)); +#if defined(I_STDARG) && defined(HAS_VPRINTF) + va_list args; + + va_start(args, pat); + vfprintf(stderr,pat,args); #else - char **tmpenv = Null(char **); -#endif /* lint */ - - firstsetenv = FALSE; - for (j=0; j