strerror, _strerror, _wcserror, __wcserror
Get a system error message (strerror, _wcserror) or prints a user-supplied error message (_strerror, __wcserror). These functions are deprecated because more secure versions 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.
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.
_wcserror and __wcserror are wide-character versions of strerror and _strerror, respectively.
_strerror, _wcserror, and __wcserror are 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.
| TCHAR.H routine | _UNICODE & _MBCS not defined | _MBCS defined | _UNICODE defined |
|---|---|---|---|
| _tcserror | strerror | strerror | _wcserror |
| Routine | Required header | Compatibility |
|---|---|---|
| strerror | <string.h> | ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| _strerror | <string.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
| _wcserror, __wcserror | <string.h> | Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 |
For additional compatibility information, see Compatibility in the Introduction.