1 /*****************************************************************************/
2 /* Software Testing Automation Framework (STAF) */
3 /* (C) Copyright IBM Corp. 2001 */
4 /* */
5 /* This software is licensed under the Eclipse Public License (EPL) V1.0. */
6 /*****************************************************************************/
7
8 #include "STAF.h"
9 #include "STAFTimestamp.h"
10 #include "STAFMutexSem.h"
11
12 static STAFMutexSem sMutexSem;
13
STAFThreadSafeLocalTimeString(char * buffer,unsigned int bufSize,const char * format,time_t theTime,unsigned int * osRC)14 STAFRC_t STAFThreadSafeLocalTimeString(char *buffer, unsigned int bufSize,
15 const char *format, time_t theTime,
16 unsigned int *osRC)
17 {
18 try
19 {
20 STAFMutexSemLock semLock(sMutexSem);
21
22 int numChars = strftime(buffer, bufSize, format, localtime(&theTime));
23
24 if ((numChars == 0) && (osRC)) *osRC = errno;
25
26 return (numChars == 0) ? kSTAFBaseOSError : kSTAFOk;
27 }
28 catch (STAFException &se)
29 {
30 if (osRC) *osRC = se.getErrorCode();
31 return kSTAFUnknownError;
32 }
33 catch (...)
34 {
35 return kSTAFUnknownError;
36 }
37 }
38
39
STAFThreadSafeLocalTime(struct tm * theTM,time_t theTime,unsigned int * osRC)40 STAFRC_t STAFThreadSafeLocalTime(struct tm *theTM, time_t theTime,
41 unsigned int *osRC)
42 {
43 try
44 {
45 STAFMutexSemLock semLock(sMutexSem);
46
47 *theTM = *localtime(&theTime);
48 }
49 catch (STAFException &se)
50 {
51 if (osRC) *osRC = se.getErrorCode();
52 return kSTAFUnknownError;
53 }
54 catch (...)
55 {
56 return kSTAFUnknownError;
57 }
58
59 return kSTAFOk;
60 }
61