perl 5.003_01: lib/Carp.pm
[p5sagit/p5-mst-13.2.git] / x2p / util.c
index 225812a..5c3554b 100644 (file)
@@ -20,14 +20,14 @@ static char nomem[] = "Out of memory!\n";
 /* paranoid version of malloc */
 
 
-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);
@@ -43,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++);
@@ -189,7 +190,7 @@ int newlen;
 }
 
 /*VARARGS1*/
-int
+void
 croak(pat,a1,a2,a3,a4)
 char *pat;
 int a1,a2,a3,a4;
@@ -199,7 +200,7 @@ int a1,a2,a3,a4;
 }
 
 /*VARARGS1*/
-int
+void
 fatal(pat,a1,a2,a3,a4)
 char *pat;
 int a1,a2,a3,a4;
@@ -217,53 +218,3 @@ int a1,a2,a3,a4;
     fprintf(stderr,pat,a1,a2,a3,a4);
 }
 
-static bool firstsetenv = TRUE;
-extern char **environ;
-
-void
-setenv(nam,val)
-char *nam, *val;
-{
-    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<i; j++)         /* copy environment */
-               tmpenv[j] = environ[j];
-           environ = tmpenv;           /* tell exec where it is now */
-       }
-#ifndef lint
-       else
-           environ = (char**) saferealloc((char*) environ,
-               (i+2) * sizeof(char*));
-                                       /* just expand it a bit */
-#endif /* lint */
-       environ[i+1] = Nullch;  /* make sure it's null terminated */
-    }
-    environ[i] = safemalloc(strlen(nam) + strlen(val) + 2);
-                                       /* this may or may not be in */
-                                       /* the old environ structure */
-    sprintf(environ[i],"%s=%s",nam,val);/* all that work just for this */
-}
-
-int
-envix(nam)
-char *nam;
-{
-    register int i, len = strlen(nam);
-
-    for (i = 0; environ[i]; i++) {
-       if (strnEQ(environ[i],nam,len) && environ[i][len] == '=')
-           break;                      /* strnEQ must come first to avoid */
-    }                                  /* potential SEGV's */
-    return i;
-}