Actual source code: fdate.c

 2:  #include petsc.h
 3:  #include petscsys.h
  4: #include "petscfix.h"
  5: #if defined(PETSC_HAVE_SYS_TIME_H)
  6: #include <sys/types.h>
  7: #include <sys/time.h>
  8: #endif
  9: #include <time.h>
 10: #if defined(PETSC_NEEDS_GETTIMEOFDAY_PROTO)
 12: EXTERN int gettimeofday(struct timeval *,struct timezone *);
 14: #endif
 15: 
 16: /*
 17:   This function is called once during the initialize stage.
 18:   It stashes the timestamp, and uses it when needed. This is so that 
 19:   error handlers may report the date without generating possible
 20:   additional system errors during the call to get the date.

 22: */
 25: /*@C
 26:     PetscGetDate - Gets the current date.

 28:    Not collective

 30:   Input Parameter:
 31: .  len - length of string to hold date

 33:   Output Parameter:
 34: .  date - the date

 36:   Level: beginner

 38:     This function DOES make a system call and thus SHOULD NOT be called
 39:     from an error handler. 

 41: @*/
 42: PetscErrorCode PetscGetDate(char date[],size_t len)
 43: {
 44:   char           *str=PETSC_NULL;
 45: #if defined(PETSC_HAVE_TIME)
 46:   time_t         aclock;
 47: #else
 48:   struct timeval tp;
 49: #endif

 53: #if defined(PETSC_HAVE_TIME)
 54:   time(&aclock);
 55:   PetscStrncpy(date,asctime(localtime(&aclock)),len);
 56: #else
 57:   gettimeofday(&tp,(struct timezone *)0);
 58:   PetscStrncpy(date,asctime(localtime((time_t*)&tp.tv_sec)),len);
 59: #endif
 60:   /* now strip out the new-line chars at the end of the string */
 61:   PetscStrstr(date,"\n",&str);
 62:   if (str) str[0] = 0;
 63:   return(0);
 64: }