Actual source code: fdate.c

      1: #define PETSC_DLL

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

     23: */
     26: /*@C
     27:     PetscGetDate - Gets the current date.

     29:    Not collective

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

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

     37:   Level: beginner

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

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

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