ctime_r
=======

POSIX specification:
 http://www.opengroup.org/onlinepubs/9699919799/functions/ctime_r.html

Gnulib module: extensions

Portability problems fixed by Gnulib:

  * This function has an incompatible declaration on some platforms: Solaris 11 2011-11 (when _POSIX_PTHREAD_SEMANTICS is not defined).

Portability problems not fixed by Gnulib:

  * This function is missing on some platforms: mingw, MSVC 9.

  * This function may put more than 26 bytes into the argument buffer if an invalid year is passed.

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.