1 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 EXTERN_C_BEGIN 9 extern int gettimeofday(struct timeval*,struct timezone*); 10 EXTERN_C_END 11 #endif 12 13 /* 14 This function is called once during the initialize stage. 15 It stashes the timestamp, and uses it when needed. This is so that 16 error handlers may report the date without generating possible 17 additional system errors during the call to get the date. 18 19 */ 20 #undef __FUNCT__ 21 #define __FUNCT__ "PetscGetDate" 22 /*@C 23 PetscGetDate - Gets the current date. 24 25 Not collective 26 27 Input Parameter: 28 . len - length of string to hold date 29 30 Output Parameter: 31 . date - the date 32 33 Level: beginner 34 35 This function DOES make a system call and thus SHOULD NOT be called 36 from an error handler. 37 38 @*/ 39 PetscErrorCode PetscGetDate(char date[],size_t len) 40 { 41 char *str=NULL; 42 #if defined(PETSC_HAVE_TIME) 43 time_t aclock; 44 #else 45 struct timeval tp; 46 #endif 47 PetscErrorCode ierr; 48 49 PetscFunctionBegin; 50 #if defined(PETSC_HAVE_TIME) 51 time(&aclock); 52 ierr = PetscStrncpy(date,asctime(localtime(&aclock)),len);CHKERRQ(ierr); 53 #else 54 gettimeofday(&tp,(struct timezone*)0); 55 ierr = PetscStrncpy(date,asctime(localtime((time_t*)&tp.tv_sec)),len);CHKERRQ(ierr); 56 #endif 57 /* now strip out the new-line chars at the end of the string */ 58 ierr = PetscStrstr(date,"\n",&str);CHKERRQ(ierr); 59 if (str) str[0] = 0; 60 PetscFunctionReturn(0); 61 } 62 63