First working TIEARRAY and other misc tie fixes
[p5sagit/p5-mst-13.2.git] / x2p / util.c
index e8b666f..3d3b99a 100644 (file)
@@ -24,8 +24,7 @@ static char nomem[] = "Out of memory!\n";
 
 
 Malloc_t
-safemalloc(size)
-MEM_SIZE size;
+safemalloc(size_t size)
 {
     Malloc_t ptr;
 
@@ -33,8 +32,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;
@@ -48,9 +47,7 @@ MEM_SIZE size;
 /* paranoid version of realloc */
 
 Malloc_t
-saferealloc(where,size)
-Malloc_t where;
-MEM_SIZE size;
+saferealloc(void *where, size_t size)
 {
     Malloc_t ptr;
 
@@ -59,7 +56,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)
@@ -74,8 +71,7 @@ MEM_SIZE size;
 /* safe version of free */
 
 Free_t
-safefree(where)
-Malloc_t where;
+safefree(void *where)
 {
 #ifdef DEBUGGING
     if (debug & 128)
@@ -87,10 +83,7 @@ Malloc_t where;
 /* safe version of string copy */
 
 char *
-safecpy(to,from,len)
-char *to;
-register char *from;
-register int len;
+safecpy(char *to, register char *from, register int len)
 {
     register char *dest = to;
 
@@ -103,9 +96,7 @@ register int len;
 /* 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 +115,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 +133,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 +153,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 *newaddr = (char *) safemalloc((MEM_SIZE)(strlen(str)+1));
 
     (void)strcpy(newaddr,str);
     return newaddr;
@@ -178,16 +164,13 @@ 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;
     }
 }