1CTIME(3P) POSIX Programmer's Manual CTIME(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 ctime, ctime_r — convert a time value to a date and time string
13
15 #include <time.h>
16
17 char *ctime(const time_t *clock);
18 char *ctime_r(const time_t *clock, char *buf);
19
21 For ctime(): The functionality described on this reference page is
22 aligned with the ISO C standard. Any conflict between the requirements
23 described here and the ISO C standard is unintentional. This volume of
24 POSIX.1‐2017 defers to the ISO C standard.
25
26 The ctime() function shall convert the time pointed to by clock, repre‐
27 senting time in seconds since the Epoch, to local time in the form of a
28 string. It shall be equivalent to:
29
30
31 asctime(localtime(clock))
32
33 The asctime(), ctime(), gmtime(), and localtime() functions shall
34 return values in one of two static objects: a broken-down time struc‐
35 ture and an array of char. Execution of any of the functions may over‐
36 write the information returned in either of these objects by any of the
37 other functions.
38
39 The ctime() function need not be thread-safe.
40
41 The ctime_r() function shall convert the calendar time pointed to by
42 clock to local time in exactly the same form as ctime() and put the
43 string into the array pointed to by buf (which shall be at least 26
44 bytes in size) and return buf.
45
46 Unlike ctime(), the ctime_r() function is not required to set tzname.
47 If ctime_r() sets tzname, it shall also set daylight and timezone. If
48 ctime_r() does not set tzname, it shall not set daylight and shall not
49 set timezone.
50
52 The ctime() function shall return the pointer returned by asctime()
53 with that broken-down time as an argument.
54
55 Upon successful completion, ctime_r() shall return a pointer to the
56 string pointed to by buf. When an error is encountered, a null pointer
57 shall be returned.
58
60 No errors are defined.
61
62 The following sections are informative.
63
65 None.
66
68 These functions are included only for compatibility with older imple‐
69 mentations. They have undefined behavior if the resulting string would
70 be too long, so the use of these functions should be discouraged. On
71 implementations that do not detect output string length overflow, it is
72 possible to overflow the output buffers in such a way as to cause
73 applications to fail, or possible system security violations. Also,
74 these functions do not support localized date and time formats. To
75 avoid these problems, applications should use strftime() to generate
76 strings from broken-down times.
77
78 Values for the broken-down time structure can be obtained by calling
79 gmtime() or localtime().
80
81 The ctime_r() function is thread-safe and shall return values in a
82 user-supplied buffer instead of possibly using a static data area that
83 may be overwritten by each call.
84
85 Attempts to use ctime() or ctime_r() for times before the Epoch or for
86 times beyond the year 9999 produce undefined results. Refer to asc‐
87 time().
88
90 The standard developers decided to mark the ctime() and ctime_r() func‐
91 tions obsolescent even though they are in the ISO C standard due to the
92 possibility of buffer overflow. The ISO C standard also provides the
93 strftime() function which can be used to avoid these problems.
94
96 These functions may be removed in a future version.
97
99 asctime(), clock(), difftime(), gmtime(), localtime(), mktime(), strf‐
100 time(), strptime(), time(), utime()
101
102 The Base Definitions volume of POSIX.1‐2017, <time.h>
103
105 Portions of this text are reprinted and reproduced in electronic form
106 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
107 table Operating System Interface (POSIX), The Open Group Base Specifi‐
108 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
109 Electrical and Electronics Engineers, Inc and The Open Group. In the
110 event of any discrepancy between this version and the original IEEE and
111 The Open Group Standard, the original IEEE and The Open Group Standard
112 is the referee document. The original Standard can be obtained online
113 at http://www.opengroup.org/unix/online.html .
114
115 Any typographical or formatting errors that appear in this page are
116 most likely to have been introduced during the conversion of the source
117 files to man page format. To report such errors, see https://www.ker‐
118 nel.org/doc/man-pages/reporting_bugs.html .
119
120
121
122IEEE/The Open Group 2017 CTIME(3P)