util.c
changeset 325 58c09c533d3f
parent 317 45af6a8a0cbf
child 338 06438e022f9a
equal deleted inserted replaced
324:6b535e908636 325:58c09c533d3f
     7 #include <stdio.h>
     7 #include <stdio.h>
     8 #include <stdlib.h>
     8 #include <stdlib.h>
     9 #include <sys/wait.h>
     9 #include <sys/wait.h>
    10 #include <unistd.h>
    10 #include <unistd.h>
    11 
    11 
    12 /* static */
       
    13 
       
    14 static void
       
    15 badmalloc(unsigned int size)
       
    16 {
       
    17 	eprint("fatal: could not malloc() %u bytes\n", size);
       
    18 }
       
    19 
       
    20 /* extern */
    12 /* extern */
    21 
    13 
    22 void *
    14 void *
    23 emallocz(unsigned int size)
    15 emallocz(unsigned int size)
    24 {
    16 {
    25 	void *res = calloc(1, size);
    17 	void *res = calloc(1, size);
    26 
    18 
    27 	if(!res)
    19 	if(!res)
    28 		badmalloc(size);
    20 		eprint("fatal: could not malloc() %u bytes\n", size);
    29 	return res;
    21 	return res;
    30 }
    22 }
    31 
    23 
    32 void
    24 void
    33 eprint(const char *errstr, ...)
    25 eprint(const char *errstr, ...)
    43 void *
    35 void *
    44 erealloc(void *ptr, unsigned int size)
    36 erealloc(void *ptr, unsigned int size)
    45 {
    37 {
    46 	void *res = realloc(ptr, size);
    38 	void *res = realloc(ptr, size);
    47 	if(!res)
    39 	if(!res)
    48 		badmalloc(size);
    40 		eprint("fatal: could not malloc() %u bytes\n", size);
    49 	return res;
    41 	return res;
    50 }
    42 }
    51 
    43 
    52 void
    44 void
    53 spawn(Arg *arg)
    45 spawn(Arg *arg)