Next: daddl
, Previous: ctime
, Up: ISO C and POSIX Function Substitutes [Contents][Index]
ctime_r
POSIX specification:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctime_r.html
Future POSIX removal:
https://www.austingroupbugs.net/view.php?id=1410
Gnulib module: extensions
Portability problems fixed by Gnulib:
_POSIX_PTHREAD_SEMANTICS
is not defined).
Portability problems not fixed by Gnulib:
localtime_r
and strftime
(or even sprintf
) instead.
ctime_r
takes a pre-allocated buffer and length of the buffer,
and returns NULL
on errors.
The input buffer should be at least 26 bytes in size. The output
string is locale-independent. However, years can have more than 4
digits if time_t
is sufficiently wide, so the length of the
required output buffer is not easy to determine. Increasing the
buffer size when ctime_r
returns NULL
is not necessarily
sufficient. The NULL
return value could mean some other error
condition, which will not go away by increasing the buffer size.
A more flexible function is strftime
. However, note that it is
locale dependent.