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

Functions

EXPORT errno_t strerror_s (char *dest, rsize_t dmax, errno_t errnum)
 The strerror_s function returns a pointer to the textual description of the system error code errnum, identical to the description that would be printed by perror(). More...
 
EXPORT size_t strerrorlen_s (errno_t errnum)
 The strerrorlen_s function returns the untruncated length of the textual description of the system error code errnum, identical to the description that would be printed by perror(). More...
 

Function Documentation

◆ strerror_s()

EXPORT errno_t strerror_s ( char *  dest,
rsize_t  dmax,
errno_t  errnum 
)

The strerror_s function returns a pointer to the textual description of the system error code errnum, identical to the description that would be printed by perror().

In addition to strerror() it adds the size of the destination array in order to prevent buffer overflow, and it truncates overlong error messages with "...".

No more than bufsz-1 bytes are written, the buffer is always null-terminated. If the message had to be truncated to fit the buffer and bufsz is greater than 3, then only bufsz-4 bytes are written, and the characters "..." are appended before the null terminator. The behavior is undefined if writing to dest occurs past the end of the array, which can happen when the size of the buffer pointed to by dest is less than the number of characters in the error message which in turn is less than dmax.

Remarks
SPECIFIED IN
  • C11 standard (ISO/IEC 9899:2011): K.3.7.4.2 The strerror_s function (p: 622) http://en.cppreference.com/w/c/byte/strerror
  • 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]errnuminteger value referring to an error code
Precondition
dest shall not be a null pointer.
dmax shall not be greater than RSIZE_MAX_STR.
dmax shall not equal zero.
Returns
Zero if the entire message was successfully stored in dest, non-zero otherwise.
Return values
EOKon success
ESNULLPwhen dest is a NULL pointer
ESZEROLwhen dmax = 0
ESLEMAXwhen dmax > RSIZE_MAX_STR
ESLEMINwhen the result would be longer than 4 and dmax < 4
See also
strerrorlen_s()

◆ strerrorlen_s()

EXPORT size_t strerrorlen_s ( errno_t  errnum)

The strerrorlen_s function returns the untruncated length of the textual description of the system error code errnum, identical to the description that would be printed by perror().

Remarks
SPECIFIED IN
  • C11 standard (ISO/IEC 9899:2011): K.3.7.4.2 The strerrorlen_s function (p: 622) http://en.cppreference.com/w/c/byte/strerror
  • ISO/IEC TR 24731, Programming languages, environments and system software interfaces, Extensions to the C Library, Part I: Bounds-checking interfaces
Parameters
[in]errnuminteger value referring to an error code
Returns
The length of the error message or 0
See also
strerror_s()