X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=x2p%2Futil.c;h=6994e873f753e8be9add4a1ac1c834feae7c2d85;hb=102b13d314016f7ec14c00406088a88475fe52db;hp=e8b666f39356f41aab61cd3f369fc6be0cc4f816;hpb=68dc074516a6859e3424b48d1647bcb08b1a1a7d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/x2p/util.c b/x2p/util.c index e8b666f..6994e87 100644 --- a/x2p/util.c +++ b/x2p/util.c @@ -1,11 +1,10 @@ -/* $RCSfile: util.c,v $$Revision: 4.1 $$Date: 92/08/07 18:29:29 $ +/* util.c * - * Copyright (c) 1991-1997, Larry Wall + * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1999, + * 2000, 2001, 2005 by Larry Wall and others * * 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 $ */ #include "EXTERN.h" @@ -13,19 +12,16 @@ #include "INTERN.h" #include "util.h" -#ifdef I_STDARG -# include -#endif +#include #define FLUSH -static char nomem[] = "Out of memory!\n"; +static const char nomem[] = "Out of memory!\n"; /* paranoid version of malloc */ Malloc_t -safemalloc(size) -MEM_SIZE size; +safemalloc(MEM_SIZE size) { Malloc_t ptr; @@ -33,8 +29,8 @@ MEM_SIZE size; ptr = malloc(size ? size : 1); #ifdef DEBUGGING if (debug & 128) - fprintf(stderr,"0x%lx: (%05d) malloc %d bytes\n",(unsigned long)ptr, - an++,size); + fprintf(stderr,"0x%lx: (%05d) malloc %ld bytes\n",(unsigned long)ptr, + an++,(long)size); #endif if (ptr != Nullch) return ptr; @@ -43,14 +39,13 @@ MEM_SIZE size; exit(1); } /*NOTREACHED*/ + return 0; } /* paranoid version of realloc */ Malloc_t -saferealloc(where,size) -Malloc_t where; -MEM_SIZE size; +saferealloc(Malloc_t where, MEM_SIZE size) { Malloc_t ptr; @@ -59,7 +54,7 @@ MEM_SIZE size; #ifdef DEBUGGING if (debug & 128) { fprintf(stderr,"0x%lx: (%05d) rfree\n",(unsigned long)where,an++); - fprintf(stderr,"0x%lx: (%05d) realloc %d bytes\n",(unsigned long)ptr,an++,size); + fprintf(stderr,"0x%lx: (%05d) realloc %ld bytes\n",(unsigned long)ptr,an++,(long)size); } #endif if (ptr != Nullch) @@ -69,13 +64,13 @@ MEM_SIZE size; exit(1); } /*NOTREACHED*/ + return 0; } /* safe version of free */ Free_t -safefree(where) -Malloc_t where; +safefree(Malloc_t where) { #ifdef DEBUGGING if (debug & 128) @@ -84,28 +79,10 @@ Malloc_t where; free(where); } -/* safe version of string copy */ - -char * -safecpy(to,from,len) -char *to; -register char *from; -register int len; -{ - register char *dest = to; - - if (from != Nullch) - for (len--; len && (*dest++ = *from++); len--) ; - *dest = '\0'; - return to; -} - /* copy a string up to some (non-backslashed) delimiter, if any */ char * -cpytill(to,from,delim) -register char *to, *from; -register int delim; +cpytill(register char *to, register char *from, register int delim) { for (; *from; from++,to++) { if (*from == '\\') { @@ -124,9 +101,7 @@ register int delim; char * -cpy2(to,from,delim) -register char *to, *from; -register int delim; +cpy2(register char *to, register char *from, register int delim) { for (; *from; from++,to++) { if (*from == '\\') @@ -144,9 +119,7 @@ register int delim; /* return ptr to little string in big string, NULL if not found */ char * -instr(big, little) -char *big, *little; - +instr(char *big, char *little) { register char *t, *s, *x; @@ -166,10 +139,9 @@ char *big, *little; /* copy a string to a safe spot */ char * -savestr(str) -char *str; +savestr(char *str) { - register char *newaddr = safemalloc((MEM_SIZE)(strlen(str)+1)); + register char * const newaddr = (char *) safemalloc((MEM_SIZE)(strlen(str)+1)); (void)strcpy(newaddr,str); return newaddr; @@ -178,77 +150,44 @@ char *str; /* grow a static string to at least a certain length */ void -growstr(strptr,curlen,newlen) -char **strptr; -int *curlen; -int newlen; +growstr(char **strptr, int *curlen, int newlen) { if (newlen > *curlen) { /* need more room? */ if (*curlen) - *strptr = saferealloc(*strptr,(MEM_SIZE)newlen); + *strptr = (char *) saferealloc(*strptr,(MEM_SIZE)newlen); else - *strptr = safemalloc((MEM_SIZE)newlen); + *strptr = (char *) safemalloc((MEM_SIZE)newlen); *curlen = newlen; } } void -#if defined(I_STDARG) && defined(HAS_VPRINTF) -croak(char *pat,...) -#else /* I_STDARG */ -/*VARARGS1*/ -croak(pat,a1,a2,a3,a4) - char *pat; - int a1,a2,a3,a4; -#endif /* I_STDARG */ +fatal(const char *pat,...) { -#if defined(I_STDARG) && defined(HAS_VPRINTF) +#if defined(HAS_VPRINTF) va_list args; va_start(args, pat); vfprintf(stderr,pat,args); + va_end(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*/ -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); +#if defined(DARWIN) +__private_extern__ /* warn() conflicts with libc */ #endif - exit(1); -} - void -#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 */ +warn(const char *pat,...) { -#if defined(I_STDARG) && defined(HAS_VPRINTF) +#if defined(HAS_VPRINTF) va_list args; va_start(args, pat); vfprintf(stderr,pat,args); + va_end(args); #else fprintf(stderr,pat,a1,a2,a3,a4); #endif