Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / src / os / os_ctime.c
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2001, 2012 Oracle and/or its affiliates.  All rights reserved.
5  *
6  * $Id$
7  */
8
9 #include "db_config.h"
10
11 #include "db_int.h"
12
13 /*
14  * __os_ctime --
15  *      Format a time-stamp.
16  *
17  * PUBLIC: char *__os_ctime __P((const time_t *, char *));
18  */
19 char *
20 __os_ctime(tod, time_buf)
21         const time_t *tod;
22         char *time_buf;
23 {
24         time_buf[CTIME_BUFLEN - 1] = '\0';
25
26         /*
27          * The ctime_r interface is the POSIX standard, thread-safe version of
28          * ctime.  However, it was implemented in three different ways (with
29          * and without a buffer length argument, and where the buffer length
30          * argument was an int vs. a size_t *).  Also, you can't depend on a
31          * return of (char *) from ctime_r, HP-UX 10.XX's version returned an
32          * int.
33          */
34 #if defined(HAVE_VXWORKS)
35         {
36         size_t buflen = CTIME_BUFLEN;
37         (void)ctime_r(tod, time_buf, &buflen);
38         }
39 #elif defined(HAVE_CTIME_R_3ARG)
40         (void)ctime_r(tod, time_buf, CTIME_BUFLEN);
41 #elif defined(HAVE_CTIME_R)
42         (void)ctime_r(tod, time_buf);
43 #else
44         (void)strncpy(time_buf, ctime(tod), CTIME_BUFLEN - 1);
45 #endif
46         return (time_buf);
47 }