Share via


Gets the current value of the errno global variable.


errno_t _get_errno(
   int * pValue


A pointer to an integer to be filled with the current value of the errno variable.

Return value

Returns zero if successful; an error code on failure. If pValue is NULL, the invalid parameter handler is invoked as described in Parameter validation. If execution is allowed to continue, this function sets errno to EINVAL and returns EINVAL.


Possible values of errno are defined in Errno.h. Also, see errno constants.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.


// crt_get_errno.c
#include <errno.h>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <sys/stat.h>

int main()
   errno_t err;
   int pfh;
   _sopen_s(&pfh, "nonexistent.file", _O_WRONLY, _SH_DENYNO, _S_IWRITE);
   printf("errno = %d\n", err);
   printf("fyi, ENOENT = %d\n", ENOENT);
errno = 2
fyi, ENOENT = 2


Routine Required header Optional header
_get_errno <stdlib.h> <errno.h>

For more compatibility information, see Compatibility.

See also

errno, _doserrno, _sys_errlist, and _sys_nerr