This is allocate.c in view mode; [Download] [Up]
#include <stdlib.h> #include <stdarg.h> #include <string.h> #include <mach/mach.h> #include "allocate.h" #include "fatals.h" /* * allocate() is just a wrapper around malloc that prints an error message and * exits if the malloc fails. */ void * allocate( unsigned long size) { void *p; if(size == 0) return(NULL); if((p = malloc(size)) == NULL) system_fatal("virtual memory exhausted (malloc failed)"); return(p); } /* * Makestr() creates a string that is the concatenation of a variable number of * strings. It is pass a variable number of pointers to strings and the last * pointer is NULL. It returns the pointer to the string it created. The * storage for the string is malloc()'ed can be free()'ed when nolonger needed. */ char * makestr( const char *args, ...) { va_list ap; char *s, *p; long size; size = 0; if(args != NULL){ size += strlen(args); va_start(ap, args); p = (char *)va_arg(ap, char *); while(p != NULL){ size += strlen(p); p = (char *)va_arg(ap, char *); } } s = allocate(size + 1); *s = '\0'; if(args != NULL){ (void)strcat(s, args); va_start(ap, args); p = (char *)va_arg(ap, char *); while(p != NULL){ (void)strcat(s, p); p = (char *)va_arg(ap, char *); } va_end(ap); } return(s); }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.