[CRT]
[reactos.git] / lib / sdk / crt / time / ctime.c
1 /*
2 * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
3 * PROJECT: ReactOS CRT library
4 * FILE: lib/sdk/crt/time/ctime.c
5 * PURPOSE: Implementation of ctime, _ctime_s
6 * PROGRAMERS: Timo Kreuzer
7 */
8 #define MINGW_HAS_SECURE_API 1
9
10 #define RC_INVOKED 1 // to prevent inline functions
11 #include <tchar.h>
12 #include <time.h>
13 #include "bitsfixup.h"
14
15 #define EINVAL -1
16
17 /* Doesn't really exist, but we need it here */
18 _CRTIMP errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time);
19
20 /******************************************************************************
21 * \name _tctime_s
22 * \brief Converts a time_t value into a string.
23 * \param buffer Buffer that receives the string (26 characters).
24 * \param numberOfElements Size of the buffer in characters.
25 * \param time Pointer to the UTC time.
26 */
27 errno_t
28 _tctime_s(_TCHAR *buffer, size_t numberOfElements, const time_t *time)
29 {
30 struct tm _tm;
31
32 if (localtime_s(&_tm, time) == EINVAL)
33 {
34 return EINVAL;
35 }
36 return _tasctime_s(buffer, numberOfElements, &_tm);
37 }
38
39 /******************************************************************************
40 * \name _tctime
41 * \brief Converts a time_t value into a string and returns a pointer to it.
42 * \param time Pointer to the UTC time.
43 * \remarks The string is stored in thread local buffer, shared between
44 * ctime, gmtime and localtime (both 32 and 64 bit versions).
45 */
46 _TCHAR *
47 _tctime(const time_t *ptime)
48 {
49 struct tm *ptm = localtime(ptime);
50 if (!ptm)
51 {
52 return 0;
53 }
54 return _tasctime(ptm);
55 }
56