/[ascend]/trunk/base/generic/utilities/ascMalloc.c
ViewVC logotype

Diff of /trunk/base/generic/utilities/ascMalloc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 99 by jds, Fri Dec 9 20:27:28 2005 UTC revision 100 by jds, Fri Dec 9 23:25:15 2005 UTC
# Line 51  Line 51 
51  #ifdef __WIN32__  #ifdef __WIN32__
52  #  define LOGFILE "memlg"  #  define LOGFILE "memlg"
53  #else  #else
54  #  define TEMPFILE_TEMPLATE "/tmp/asctmpXXXXXX"  #  define TEMPFILE_TEMPLATE "/tmp/ascmemlog_XXXXXX"
55  #endif  #endif
56    
57  #ifndef lint  #ifndef lint
# Line 264  static CONST VOIDPTR MemoryMean(void) Line 264  static CONST VOIDPTR MemoryMean(void)
264  /*  /*
265   *  Creates a temporary file for logging memory events.   *  Creates a temporary file for logging memory events.
266   *  The file is opened and header information is written to it.   *  The file is opened and header information is written to it.
267   *  Thereafter, the FILE* is available to other routines in   *  Thereafter, the FILE* is available to other routines in
268   *  f_memory_log_file, which should append to the file as needed.     *  f_memory_log_file, which should append to the file as needed.
269   *  This function may be called more than once - the file will only be   *  This function may be called more than once - the file will only be
270   *  created and header info written the first time it is called, or   *  created and header info written the first time it is called, or
271   *  after ascshutdown() has been called.   *  after ascshutdown() has been called.
272   */   */
273  static void OpenLogFile(void)  static void OpenLogFile(void)
274  {  {
   if (NULL == f_memory_log_file){  
275    time_t t;    time_t t;
276      int handle;
277    
278      if (NULL == f_memory_log_file) {
279    
280  #ifdef __WIN32__  #ifdef __WIN32__
281      /* Windows doesn't have mkstemp(), so need to use tempnam() */      /* Windows doesn't have mkstemp(), so need to use tempnam() */
     int handle;  
282      f_memlog_filename = tempnam(NULL, LOGFILE);      f_memlog_filename = tempnam(NULL, LOGFILE);
283      if (NULL == f_memlog_filename) {      if (NULL == f_memlog_filename) {
284        Asc_Panic(2, NULL, "Unable to create a unique memory log filename.\n");        Asc_Panic(2, NULL, "Unable to create a unique memory log filename.\n");
# Line 287  static void OpenLogFile(void) Line 289  static void OpenLogFile(void)
289      if ((-1 == handle) ||      if ((-1 == handle) ||
290          (NULL == (f_memory_log_file = fdopen(handle,"w")))) {          (NULL == (f_memory_log_file = fdopen(handle,"w")))) {
291        Asc_Panic(2, NULL, "Unable to open memory log file.\n");        Asc_Panic(2, NULL, "Unable to open memory log file.\n");
292      }        }
293  #else  #else
294      f_memory_log_file = (FILE *)mkstemp(TEMPFILE_TEMPLATE);      char temp_filename[] = TEMPFILE_TEMPLATE;
295      if (NULL == f_memory_log_file) {      handle = mkstemp(temp_filename);
296        if ((-1 == handle) ||
297            (NULL == (f_memory_log_file = fdopen(handle,"r+")))) {
298        Asc_Panic(2, NULL, "Unable to open memory log file.\n");        Asc_Panic(2, NULL, "Unable to open memory log file.\n");
299    }      }
300  #endif  /* __WIN32__ */  #endif  /* __WIN32__ */
301    t = time((time_t *)NULL);  
302        t = time((time_t *)NULL);
303      FPRINTF(f_memory_log_file,"Ascend memory log file opened %s",      FPRINTF(f_memory_log_file,"Ascend memory log file opened %s",
304                              asctime(localtime(&t)));                              asctime(localtime(&t)));
305      FPRINTF(f_memory_log_file,"%16s %13s %16s %13s %6s %s",      FPRINTF(f_memory_log_file,"%16s %13s %16s %13s %6s %s",
# Line 305  static void OpenLogFile(void) Line 310  static void OpenLogFile(void)
310                              "Line#",                              "Line#",
311                              "Source File\n");                              "Source File\n");
312      fflush(f_memory_log_file);      fflush(f_memory_log_file);
313  }    }
314  }  }
315    
316  static void WriteMemoryStatus(FILE *f, CONST char *msg)  static void WriteMemoryStatus(FILE *f, CONST char *msg)

Legend:
Removed from v.99  
changed lines
  Added in v.100

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22