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.
- Parameters
-
[out] | dest | pointer to a user-provided buffer. |
[in] | dmax | restricted maximum length of dest |
[in] | errnum | integer 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
-
EOK | on success |
ESNULLP | when dest is a NULL pointer |
ESZEROL | when dmax = 0 |
ESLEMAX | when dmax > RSIZE_MAX_STR |
ESLEMIN | when the result would be longer than 4 and dmax < 4 |
- See also
- strerrorlen_s()