xref: /reactos/sdk/lib/crt/time/ctime.c (revision 84ccccab)
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 #include <errno.h>
11 #define RC_INVOKED 1 // to prevent inline functions
12 #include <tchar.h>
13 #include <time.h>
14 #include "bitsfixup.h"
15 
16 /* Doesn't really exist, but we need it here */
17 _CRTIMP errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time);
18 
19 /******************************************************************************
20  * \name _tctime_s
21  * \brief Converts a time_t value into a string.
22  * \param buffer Buffer that receives the string (26 characters).
23  * \param numberOfElements Size of the buffer in characters.
24  * \param time Pointer to the UTC time.
25  */
26 errno_t
27 _tctime_s(_TCHAR *buffer, size_t numberOfElements, const time_t *time)
28 {
29     struct tm _tm;
30 
31     if (localtime_s(&_tm, time) == EINVAL)
32     {
33         return EINVAL;
34     }
35     return _tasctime_s(buffer, numberOfElements, &_tm);
36 }
37 
38 /******************************************************************************
39  * \name _tctime
40  * \brief Converts a time_t value into a string and returns a pointer to it.
41  * \param time Pointer to the UTC time.
42  * \remarks The string is stored in thread local buffer, shared between
43  *          ctime, gmtime and localtime (both 32 and 64 bit versions).
44  */
45 _TCHAR *
46 _tctime(const time_t *ptime)
47 {
48     struct tm *ptm = localtime(ptime);
49     if (!ptm)
50     {
51         return 0;
52     }
53     return _tasctime(ptm);
54 }
55 
56