The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
We recommend using Visual Studio 2017

errno, _doserrno, _sys_errlist, and _sys_nerr


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at errno, _doserrno, _sys_errlist, and _sys_nerr.

Global macros that hold error codes that are set during program execution, and string equivalents of the error codes for display.

#define errno   (*_errno())  
#define _doserrno   (*__doserrno())  
#define _sys_errlist (__sys_errlist())  
#define _sys_nerr (*__sys_nerr())  

Both errno and _doserrno are set to 0 by the runtime during program startup. errno is set on an error in a system-level call. Because errno holds the value for the last call that set it, this value may be changed by succeeding calls. Run-time library calls that set errno on an error do not clear errno on success. Always clear errno by calling _set_errno(0) immediately before a call that may set it, and check it immediately after the call.

On an error, errno is not necessarily set to the same value as the error code returned by a system call. For I/O operations, _doserrno stores the operating-system error-code equivalents of errno codes. For most non-I/O operations, the value of _doserrno is not set.

Each errno value is associated with an error message in _sys_errlist that can be printed by using one of the perror functions, or stored in a string by using one of the strerror or strerror_s functions. The perror and strerror functions use the _sys_errlist array and _sys_nerr—the number of elements in _sys_errlist—to process error information. Direct access to _sys_errlist and _sys_nerr is deprecated for code-security reasons. We recommend that you use the more secure, functional versions instead of the global macros, as shown here:

Global MacroFunctional Equivalents
_doserrno_get_doserrno, _set_doserrno
errno_get_errno, _set_errno
_sys_errlist, _sys_nerrstrerror_s, _strerror_s, _wcserror_s, __wcserror_s

Library math routines set errno by calling _matherr. To handle math errors differently, write your own routine according to the _matherr reference description and name it _matherr.

All errno values in the following table are predefined constants in <errno.h>, and are UNIX-compatible. Only ERANGE, EILSEQ, and EDOM are specified in the ISO C99 standard.

ConstantSystem error messageValue
EPERMOperation not permitted1
ENOENTNo such file or directory2
ESRCHNo such process3
EINTRInterrupted function4
EIOI/O error5
ENXIONo such device or address6
E2BIGArgument list too long7
ENOEXECExec format error8
EBADFBad file number9
ECHILDNo spawned processes10
EAGAINNo more processes or not enough memory or maximum nesting level reached11
ENOMEMNot enough memory12
EACCESPermission denied13
EFAULTBad address14
EBUSYDevice or resource busy16
EEXISTFile exists17
EXDEVCross-device link18
ENODEVNo such device19
ENOTDIRNot a directory20
EISDIRIs a directory21
EINVALInvalid argument22
ENFILEToo many files open in system23
EMFILEToo many open files24
ENOTTYInappropriate I/O control operation25
EFBIGFile too large27
ENOSPCNo space left on device28
ESPIPEInvalid seek29
EROFSRead-only file system30
EMLINKToo many links31
EPIPEBroken pipe32
EDOMMath argument33
ERANGEResult too large34
EDEADLKResource deadlock would occur36
EDEADLOCKSame as EDEADLK for compatibility with older Microsoft C versions36
ENAMETOOLONGFilename too long38
ENOLCKNo locks available39
ENOSYSFunction not supported40
ENOTEMPTYDirectory not empty41
EILSEQIllegal byte sequence42
STRUNCATEString was truncated80
Global macroRequired headerOptional header
errno<errno.h> or <stdlib.h>, <cerrno> or <cstdlib> (C++)
_doserrno, _sys_errlist, _sys_nerr<stdlib.h>, <cstdlib> (C++)<errno.h>, <cerrno> (C++)

The _doserrno, _sys_errlist, and _sys_nerr macros are Microsoft extensions. For more compatibility information, see Compatibility.

Global Variables
errno Constants
perror, _wperror
strerror, _strerror, _wcserror, __wcserror
strerror_s, _strerror_s, _wcserror_s, __wcserror_s