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

Functions

EXPORT errno_t asctime_s (char *dest, rsize_t dmax, const struct tm *tm)
 The asctime_s function converts the given calendar time tm to a textual representation of the following fixed 25-character form: "Www Mmm dd hh:mm:ss yyyy\n", as with asctime. More...
 

Function Documentation

◆ asctime_s()

EXPORT errno_t asctime_s ( char *  dest,
rsize_t  dmax,
const struct tm *  tm 
)

The asctime_s function converts the given calendar time tm to a textual representation of the following fixed 25-character form: "Www Mmm dd hh:mm:ss yyyy\n", as with asctime.

The message is copied into 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. Uses the re-entrant asctime_r() if available.

Remarks
SPECIFIED IN
  • C11 standard (ISO/IEC 9899:2011): K.3.8.2.1 The asctime_s function (p: 624-625) http://en.cppreference.com/w/c/chrono/asctime
  • 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]tmpointer to a tm object specifying the time to print
Precondition
dest and tm shall not be a null pointer.
dmax shall not be less than 26 and greater than RSIZE_MAX_STR.
not all members of *tm are within their normal ranges, the year indicated by tm->tm_year is between 0-8099.
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 or a tm member is too large
ESLEMINwhen dmax < 26 or a tm member is too small
ESNOSPCwhen dmax is too small for the result buffer
-1when asctime_r or asctime returned NULL
Note
This function returns a pointer to static data and is not thread-safe. POSIX marks this function obsolete and recommends strftime instead. The C standard also recommends strftime instead of asctime and asctime_s because strftime is more flexible and locale-sensitive. POSIX limits undefined behaviors only to when the output string would be longer than 25 characters, when tm->tm_wday or tm->tm_mon are not within the expected ranges, or when tm->tm_year exceeds INT_MAX-1990. Some implementations handle tm->tm_mday==0 as meaning the last day of the preceding month.
See also
ctime_s()