strerror, _strerror, _wcserror, __wcserror
Get a system error message (strerror, _wcserror) or prints a user-supplied error message (_strerror, __wcserror). More secure versions of these functions are available; see strerror_s, _strerror_s, _wcserror_s, __wcserror_s .
char *strerror(
int errnum
);
char *_strerror(
const char *strErrMsg
);
wchar_t * _wcserror(
int errnum
);
wchar_t * __wcserror(
const wchar_t *strErrMsg
);
Parameters
errnum
Error number.strErrMsg
User-supplied message.
Return Value
All these functions return a pointer to the error-message string. Subsequent calls can overwrite the string.
Remarks
The strerror function maps errnum to an error-message string, returning a pointer to the string. Neither strerror nor _strerror actually prints the message: For that, you need to call an output function such as fprintf:
if (( _access( "datafile",2 )) == -1 )
fprintf( stderr, _strerror(NULL) );
If strErrMsg is passed as NULL, _strerror returns a pointer to a string containing the system error message for the last library call that produced an error. The error-message string is terminated by the newline character ('\n'). If strErrMsg is not equal to NULL, then _strerror returns a pointer to a string containing (in order) your string message, a colon, a space, the system error message for the last library call producing an error, and a newline character. Your string message can be, at most, 94 characters long.
The actual error number for _strerror is stored in the variable errno. The system error messages are accessed through the variable _sys_errlist, which is an array of messages ordered by error number. _strerror accesses the appropriate error message by using the errno value as an index to the variable _sys_errlist. The value of the variable _sys_nerr is defined as the maximum number of elements in the _sys_errlist array. To produce accurate results, call _strerror immediately after a library routine returns with an error. Otherwise, subsequent calls to strerror or _strerror can overwrite the errno value.
_wcserrorand __wcserrorare wide-character versions of strerrorand _strerror, respectively.
_strerror, _wcserror, and __wcserrorare not part of the ANSI definition but are instead Microsoft extensions to it. Do not use them where portability is desired; for ANSI compatibility, use strerror instead.
Generic-Text Routine Mappings
TCHAR.H routine |
_UNICODE & _MBCS not defined |
_MBCS defined |
_UNICODE defined |
---|---|---|---|
_tcserror |
strerror |
strerror |
_wcserror |
Requirements
Routine |
Required header |
---|---|
strerror |
<string.h> |
_strerror |
<string.h> |
_wcserror, __wcserror |
<string.h> |
For additional compatibility information, see Compatibility in the Introduction.
Example
See the example for perror.