X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=util.c;h=6b666e0f4fd4a59c549f547e41e7878cc12be6eb;hb=994914430a9d31e91f3ba7f46998670879b75792;hp=77dd842f426fccc1fe3a667d8c71d35385fe7be8;hpb=3aeabbed7742629accd365cc24e3608278252b86;p=p5sagit%2Fp5-mst-13.2.git diff --git a/util.c b/util.c index 77dd842..6b666e0 100644 --- a/util.c +++ b/util.c @@ -1,6 +1,6 @@ /* util.c * - * Copyright (c) 1991-1997, Larry Wall + * Copyright (c) 1991-1999, 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. @@ -62,9 +62,7 @@ long lastxycount[MAXXCOUNT][MAXYCOUNT]; #endif -#ifndef MYMALLOC - -/* paranoid version of malloc */ +/* paranoid version of system's malloc() */ /* NOTE: Do not call the next three routines directly. Use the macros * in handy.h, so that we can easily redefine everything to do tracking of @@ -73,7 +71,7 @@ long lastxycount[MAXXCOUNT][MAXYCOUNT]; */ Malloc_t -safemalloc(MEM_SIZE size) +safesysmalloc(MEM_SIZE size) { Malloc_t ptr; #ifdef HAS_64K_LIMIT @@ -104,10 +102,10 @@ safemalloc(MEM_SIZE size) /*NOTREACHED*/ } -/* paranoid version of realloc */ +/* paranoid version of system's realloc() */ Malloc_t -saferealloc(Malloc_t where,MEM_SIZE size) +safesysrealloc(Malloc_t where,MEM_SIZE size) { Malloc_t ptr; #if !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE) @@ -122,12 +120,12 @@ saferealloc(Malloc_t where,MEM_SIZE size) } #endif /* HAS_64K_LIMIT */ if (!size) { - safefree(where); + safesysfree(where); return NULL; } if (!where) - return safemalloc(size); + return safesysmalloc(size); #ifdef DEBUGGING if ((long)size < 0) croak("panic: realloc"); @@ -158,10 +156,10 @@ saferealloc(Malloc_t where,MEM_SIZE size) /*NOTREACHED*/ } -/* safe version of free */ +/* safe version of system's free() */ Free_t -safefree(Malloc_t where) +safesysfree(Malloc_t where) { #if !(defined(I286) || defined(atarist)) DEBUG_m( PerlIO_printf(Perl_debug_log, "0x%x: (%05d) free\n",(char *) where,PL_an++)); @@ -174,10 +172,10 @@ safefree(Malloc_t where) } } -/* safe version of calloc */ +/* safe version of system's calloc() */ Malloc_t -safecalloc(MEM_SIZE count, MEM_SIZE size) +safesyscalloc(MEM_SIZE count, MEM_SIZE size) { Malloc_t ptr; @@ -213,8 +211,6 @@ safecalloc(MEM_SIZE count, MEM_SIZE size) /*NOTREACHED*/ } -#endif /* !MYMALLOC */ - #ifdef LEAKTEST struct mem_test_strut { @@ -389,16 +385,16 @@ delimcpy(register char *to, register char *toend, register char *from, register /* This routine was donated by Corey Satten. */ char * -instr(register char *big, register char *little) +instr(register const char *big, register const char *little) { - register char *s, *x; + register const char *s, *x; register I32 first; if (!little) - return big; + return (char*)big; first = *little++; if (!first) - return big; + return (char*)big; while (*big) { if (*big++ != first) continue; @@ -411,7 +407,7 @@ instr(register char *big, register char *little) } } if (!*s) - return big-1; + return (char*)(big-1); } return Nullch; } @@ -419,14 +415,14 @@ instr(register char *big, register char *little) /* same as instr but allow embedded nulls */ char * -ninstr(register char *big, register char *bigend, char *little, char *lend) +ninstr(register const char *big, register const char *bigend, const char *little, const char *lend) { - register char *s, *x; + register const char *s, *x; register I32 first = *little; - register char *littleend = lend; + register const char *littleend = lend; if (!first && little >= littleend) - return big; + return (char*)big; if (bigend - big < littleend - little) return Nullch; bigend -= littleend - little++; @@ -440,7 +436,7 @@ ninstr(register char *big, register char *bigend, char *little, char *lend) } } if (s >= littleend) - return big-1; + return (char*)(big-1); } return Nullch; } @@ -448,15 +444,15 @@ ninstr(register char *big, register char *bigend, char *little, char *lend) /* reverse of the above--find last substring */ char * -rninstr(register char *big, char *bigend, char *little, char *lend) +rninstr(register const char *big, const char *bigend, const char *little, const char *lend) { - register char *bigbeg; - register char *s, *x; + register const char *bigbeg; + register const char *s, *x; register I32 first = *little; - register char *littleend = lend; + register const char *littleend = lend; if (!first && little >= littleend) - return bigend; + return (char*)bigend; bigbeg = big; big = bigend - (littleend - little++); while (big >= bigbeg) { @@ -469,7 +465,7 @@ rninstr(register char *big, char *bigend, char *little, char *lend) } } if (s >= littleend) - return big+1; + return (char*)(big+1); } return Nullch; } @@ -478,7 +474,7 @@ rninstr(register char *big, char *bigend, char *little, char *lend) * Set up for a new ctype locale. */ void -perl_new_ctype(char *newctype) +perl_new_ctype(const char *newctype) { #ifdef USE_LOCALE_CTYPE @@ -500,7 +496,7 @@ perl_new_ctype(char *newctype) * Set up for a new collation locale. */ void -perl_new_collate(char *newcoll) +perl_new_collate(const char *newcoll) { #ifdef USE_LOCALE_COLLATE @@ -544,7 +540,7 @@ perl_new_collate(char *newcoll) * Set up for a new numeric locale. */ void -perl_new_numeric(char *newnum) +perl_new_numeric(const char *newnum) { #ifdef USE_LOCALE_NUMERIC @@ -1131,7 +1127,7 @@ screaminstr(SV *bigstr, SV *littlestr, I32 start_shift, I32 end_shift, I32 *old_ } I32 -ibcmp(char *s1, char *s2, register I32 len) +ibcmp(const char *s1, const char *s2, register I32 len) { register U8 *a = (U8 *)s1; register U8 *b = (U8 *)s2; @@ -1144,7 +1140,7 @@ ibcmp(char *s1, char *s2, register I32 len) } I32 -ibcmp_locale(char *s1, char *s2, register I32 len) +ibcmp_locale(const char *s1, const char *s2, register I32 len) { register U8 *a = (U8 *)s1; register U8 *b = (U8 *)s2; @@ -1159,7 +1155,7 @@ ibcmp_locale(char *s1, char *s2, register I32 len) /* copy a string to a safe spot */ char * -savepv(char *sv) +savepv(const char *sv) { register char *newaddr; @@ -1171,7 +1167,7 @@ savepv(char *sv) /* same thing but with a known length */ char * -savepvn(char *sv, register I32 len) +savepvn(const char *sv, register I32 len) { register char *newaddr; @@ -1504,6 +1500,8 @@ warner(U32 err, const char* pat,...) void my_setenv(char *nam, char *val) { +#ifndef PERL_USE_SAFE_PUTENV + /* most putenv()s leak, so we manipulate environ directly */ register I32 i=setenv_getix(nam); /* where does it go? */ if (environ == PL_origenviron) { /* need we copy environment? */ @@ -1513,14 +1511,16 @@ my_setenv(char *nam, char *val) /*SUPPRESS 530*/ for (max = i; environ[max]; max++) ; - New(901,tmpenv, max+2, char*); - for (j=0; j 0) *to++ = c; return;