Date: 2021-03-03T22:25:43+00:00

Actual source code: fdate.c
petsc-3.14.5 2021-03-03
Report Typos and Errors

      2: #include <petscsys.h>
      3: #if defined(PETSC_HAVE_SYS_TIME_H)
      4: #include <sys/time.h>
      5: #endif
      6: #include <time.h>
      7: #if defined(PETSC_NEEDS_GETTIMEOFDAY_PROTO)
      8: PETSC_EXTERN int gettimeofday(struct timeval*,struct timezone*);
      9: #endif

     11: /*
     12:   This function is called once during the initialize stage.
     13:   It stashes the timestamp, and uses it when needed. This is so that
     14:   error handlers may report the date without generating possible
     15:   additional system errors during the call to get the date.

     17: */
     18: /*@C
     19:     PetscGetDate - Gets the current date.

     21:    Not collective

     23:   Input Parameter:
     24: .  len - length of string to hold date

     26:   Output Parameter:
     27: .  date - the date

     29:   Level: beginner

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

     34: @*/
     35: PetscErrorCode  PetscGetDate(char date[],size_t len)
     36: {
     37:   char           *str=NULL;
     38: #if defined(PETSC_HAVE_TIME)
     39:   time_t         aclock;
     40: #else
     41:   struct timeval tp;
     42: #endif

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