update dev300-m58
[ooovba.git] / dmake / dbug / malloc / mallopt.c
blob13ef4d7b2a4777b6a3c3311de8a8608bc5875b64
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 <fcntl.h>
8 #include "malloc.h"
11 * Function: mallopt()
13 * Purpose: to set options for the malloc debugging library
15 * Arguments: none
17 * Returns: nothing of any value
19 * Narrative:
23 #ifndef lint
24 static
25 char rcs_hdr[] = "$Id: mallopt.c,v 1.2 2006-07-25 10:09:05 rt Exp $";
26 #endif
28 int
29 mallopt(cmd,value)
30 int cmd;
31 union malloptarg value;
33 int i;
34 extern int malloc_checking;
35 extern char * malloc_data_start;
36 extern int malloc_errfd;
37 extern int malloc_fatal_level;
38 void malloc_init();
39 extern int malloc_warn_level;
40 register char * s;
43 * If not initialized...
45 if( malloc_data_start == (char *) 0)
47 malloc_init();
51 switch(cmd)
53 case MALLOC_WARN:
54 malloc_warn_level = value.i;
55 break;
57 case MALLOC_FATAL:
58 malloc_fatal_level = value.i;
59 break;
61 case MALLOC_CKCHAIN:
62 malloc_checking = value.i;
63 break;
65 case MALLOC_ERRFILE:
67 i = open(value.str,O_CREAT|O_APPEND|O_WRONLY,0666);
68 if( i == -1 )
70 (void) write(2,
71 "Unable to open malloc error file: ",
72 (unsigned) 34);
73 for(s=value.str; *s; s++)
75 /* do nothing */;
77 (void) write(2,value.str,
78 (unsigned)(s-value.str));
79 (void) write(2,"\n",(unsigned)1);
81 else
83 if( malloc_errfd != 2 )
85 (void) close(malloc_errfd);
87 malloc_errfd = i;
90 break;
92 default:
93 return(1);
96 return(0);