Actual source code: fdate.c

  1: #define PETSC_DLL

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

 21: */
 24: /*@C
 25:     PetscGetDate - Gets the current date.

 27:    Not collective

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

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

 35:   Level: beginner

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

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

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