Actual source code: fdate.c
1: /* $Id: fdate.c,v 1.41 2001/03/23 23:20:44 balay Exp $*/
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)
12: EXTERN_C_BEGIN
13: EXTERN int gettimeofday(struct timeval *,struct timezone *);
14: EXTERN_C_END
15: #endif
17: static char starttime[256];
18:
19: /*
20: This function is called once during the initialize stage.
21: It stashes the timestamp, and uses it when needed. This is so that
22: error handlers may report the date without generating possible
23: additional system errors during the call to get the date.
25: */
26: #undef __FUNCT__
28: /*@C
29: PetscGetDate - Gets the current date.
31: Not collective
33: Input Parameter:
34: . len - length of string to hold date
36: Output Parameter:
37: . date - the date
39: Level: beginner
41: Notes:
42: This is Y2K compliant.
44: This function DOES make a system call and thus SHOULD NOT be called
45: from an error handler. Use PetscGetInitialDate() instead.
47: .seealso: PetscGetInitialDate()
49: @*/
50: int PetscGetDate(char date[],int len)
51: {
52: char *str=0;
53: #if defined (PARCH_win32)
54: time_t aclock;
55: int ierr;
56: #else
57: struct timeval tp;
58: int ierr;
59: #endif
62: #if defined (PARCH_win32)
63: time(&aclock);
64: PetscStrncpy(date,asctime(localtime(&aclock)),len);
65: #else
66: gettimeofday(&tp,(struct timezone *)0);
67: PetscStrncpy(date,asctime(localtime((time_t*)&tp.tv_sec)),len);
68: #endif
69: /* now strip out the new-line chars at the end of the string */
70: PetscStrstr(date,"n",&str);
71: if (str) str[0] = 0;
72: return(0);
73: }
75: #undef __FUNCT__
77: int PetscSetInitialDate(void)
78: {
81: PetscGetDate(starttime,256);
82: return(0);
83: }
85: #undef __FUNCT__
87: /*@C
88: PetscGetInitialDate - Gets the date the program was started
89: on.
91: Not collective
93: Input Parameter:
94: . len - length of string to hold date
96: Output Parameter:
97: . date - the date
99: Level: beginner
101: Notes:
102: This is Y2K compliant.
104: This function does not make a system call and thus may be called
105: from an error handler.
107: .seealso: PetscGetDate()
109: @*/
110: int PetscGetInitialDate(char date[],int len)
111: {
115: PetscStrncpy(date,starttime,len);
116: return(0);
117: }