1 /* 2 * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil). 3 * You may copy, distribute, and use this software as long as this 4 * copyright statement is not removed. 5 */ 6 #include <stdio.h> 7 #include "malloc.h" 8 9 /* 10 * Function: malloc_init() 11 * 12 * Purpose: to initialize the pointers and variables use by the 13 * malloc() debugging library 14 * 15 * Arguments: none 16 * 17 * Returns: nothing of any value 18 * 19 * Narrative: Just initialize all the needed variables. Use mallopt 20 * to set options taken from the environment. 21 * 22 */ 23 #ifndef lint 24 static 25 char rcs_hdr[] = "$Id: m_init.c,v 1.2 2006-07-25 10:08:07 rt Exp $"; 26 #endif 27 28 void malloc_init()29malloc_init() 30 { 31 char * cptr; 32 char * getenv(); 33 union malloptarg m; 34 extern char * malloc_data_end; 35 extern char * malloc_data_start; 36 extern struct mlist * malloc_end; 37 extern struct mlist malloc_start; 38 char * sbrk(); 39 40 /* 41 * If already initialized... 42 */ 43 if( malloc_data_start != (char *) 0) 44 { 45 return; 46 } 47 48 49 malloc_data_start = sbrk(0); 50 malloc_data_end = malloc_data_start; 51 malloc_start.s.size = 0; 52 malloc_end = &malloc_start; 53 54 if( (cptr=getenv("MALLOC_WARN")) != NULL ) 55 { 56 m.i = atoi(cptr); 57 (void) mallopt(MALLOC_WARN,m); 58 } 59 60 if( (cptr=getenv("MALLOC_FATAL")) != NULL) 61 { 62 m.i = atoi(cptr); 63 (void) mallopt(MALLOC_FATAL,m); 64 } 65 66 if( (cptr=getenv("MALLOC_CKCHAIN")) != NULL) 67 { 68 m.i = atoi(cptr); 69 (void) mallopt(MALLOC_CKCHAIN,m); 70 } 71 72 if( (cptr=getenv("MALLOC_ERRFILE")) != NULL) 73 { 74 m.str = cptr; 75 (void) mallopt(MALLOC_ERRFILE,m); 76 } 77 78 } 79 80