safec  3.0
Safe C Library - ISO TR24731 Bounds Checking Interface
ctime_s.c File Reference
#include "safe_lib.h"
+ Include dependency graph for ctime_s.c:

Functions

EXPORT errno_t ctime_s (char *dest, rsize_t dmax, const time_t *timer)
 The ctime_s function converts the given time since epoch to a calendar local time and then to a textual representation, as if by calling asctime_s(buffer, bufsz, localtime_s(time, &(struct tm){0})). More...
 

Function Documentation

◆ ctime_s()

EXPORT errno_t ctime_s ( char *  dest,
rsize_t  dmax,
const time_t *  timer 
)

The ctime_s function converts the given time since epoch to a calendar local time and then to a textual representation, as if by calling asctime_s(buffer, bufsz, localtime_s(time, &(struct tm){0})).

The message is copied into the user-provided dest buffer, which is guaranteed to be null-terminated.

No more than dmax-1 bytes are written, the buffer is always null-terminated. The function does not support localization. Uses the re-entrant ctime_r() if available.

Remarks
SPECIFIED IN
  • C11 standard (ISO/IEC 9899:2011): K.3.8.2.2 The ctime_s function (p: 624-625) http://en.cppreference.com/w/c/chrono/ctime
  • ISO/IEC TR 24731, Programming languages, environments and system software interfaces, Extensions to the C Library, Part I: Bounds-checking interfaces
Parameters
[out]destpointer to a user-provided buffer.
[in]dmaxrestricted maximum length of dest
[in]timerpointer to a epoch (long, seconds since 1970)
Precondition
dest and timer shall not be a null pointer.
dmax shall not be less than 26 and greater than RSIZE_MAX_STR.
Returns
Zero if the entire message was successfully stored in dest, non-zero otherwise.
Return values
EOKon success
ESNULLPwhen dest or tm is a NULL pointer
ESLEMAXwhen dmax > RSIZE_MAX_STR
ESLEMINwhen dmax < 26 or *timer < 0
ESLEMAXwhen *timer > 313360441200L, the year 10000, resp. LONG_MAX on 32bit systems
ESNOSPCwhen dmax is too small for the result buffer
-1when ctime_r or ctime returned NULL
Note
ctime returns a pointer to static data and is not thread-safe. In addition, it modifies the static tm object which may be shared with gmtime and localtime. POSIX marks this function obsolete and recommends strftime instead. The C standard also recommends strftime instead of ctime and ctime_s because strftime is more flexible and locale-sensitive. The behavior of ctime may be undefined for the values of time_t that result in the string longer than 25 characters (e.g. year 10000).
See also
asctime_s()