[BACK]Return to misc.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / m4

Diff for /src/usr.bin/m4/misc.c between version 1.29 and 1.30

version 1.29, 2003/06/03 02:56:10 version 1.30, 2003/11/17 17:12:10
Line 44 
Line 44 
 #include <sys/types.h>  #include <sys/types.h>
 #include <errno.h>  #include <errno.h>
 #include <unistd.h>  #include <unistd.h>
   #include <stdarg.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <stddef.h>  #include <stddef.h>
Line 147 
Line 148 
 {  {
         int i;          int i;
   
         strspace = xalloc(strsize+1);          strspace = xalloc(strsize+1, NULL);
         ep = strspace;          ep = strspace;
         endest = strspace+strsize;          endest = strspace+strsize;
         buf = (char *)xalloc(bufsize);          buf = (char *)xalloc(bufsize, NULL);
         bufbase = buf;          bufbase = buf;
         bp = buf;          bp = buf;
         endpbb = buf + bufsize;          endpbb = buf + bufsize;
Line 185 
Line 186 
         char *newbuf;          char *newbuf;
         int i;          int i;
   
         bufsize *= 2;          bufsize += bufsize/2;
         newbuf = realloc(buf, bufsize);          newbuf = xrealloc(buf, bufsize, "too many characters pushed back");
         if (!newbuf)  
                 errx(1, "too many characters pushed back");  
         for (i = 0; i < MAXINP; i++)          for (i = 0; i < MAXINP; i++)
                 bbase[i] = (bbase[i]-buf)+newbuf;                  bbase[i] = (bbase[i]-buf)+newbuf;
         bp = (bp-buf)+newbuf;          bp = (bp-buf)+newbuf;
Line 254 
Line 253 
 {  {
         int i;          int i;
   
         outfile = (FILE **)realloc(outfile, sizeof(FILE *) * n);          outfile = (FILE **)xrealloc(outfile, sizeof(FILE *) * n,
         if (outfile == NULL)              "too many diverts %d", n);
                     errx(1, "too many diverts %d", n);  
         for (i = maxout; i < n; i++)          for (i = maxout; i < n; i++)
                 outfile[i] = NULL;                  outfile[i] = NULL;
         maxout = n;          maxout = n;
 }  }
   
 void *  void *
 xalloc(size_t n)  xalloc(size_t n, const char *fmt, ...)
 {  {
         char *p = malloc(n);          void *p = malloc(n);
   
         if (p == NULL)          if (p == NULL) {
                 err(1, "malloc");                  if (fmt == NULL)
                           err(1, "malloc");
                   else {
                           va_list va;
   
                           va_start(va, fmt);
                           verr(1, fmt, va);
                           va_end(va);
                   }
           }
           return p;
   }
   
   void *
   xrealloc(void *old, size_t n, const char *fmt, ...)
   {
           char *p = realloc(old, n);
   
           if (p == NULL) {
                   free(old);
                   if (fmt == NULL)
                           err(1, "realloc");
                   else {
                           va_list va;
   
                           va_start(va, fmt);
                           verr(1, fmt, va);
                           va_end(va);
                   }
           }
         return p;          return p;
 }  }
   

Legend:
Removed from v.1.29  
changed lines
  Added in v.1.30