Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

errno, _doserrno, _sys_errlist, and _sys_nerr

Global variables that hold error codes used by the perror and strerror functions for printing error messages. We recommend that you use the more secure, functional versions instead of the global variables, as shown here:

Global Variable

Functional Equivalents

_doserrno

_get_doserrno , _set_doserrno

_errno

_get_errno , _set_errno

These variables are declared in STDLIB.H as

extern int _doserrno; 
extern int errno; 
extern char *_sys_errlist[ ];
extern int _sys_nerr;

errno and _errno are connected to the same variable. errno is defined by the preprocessor as #define errno (*_errno())

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 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, use _doserrno to access the operating-system error-code equivalents of errno codes. For most non-I/O operations, the value of _doserrno is undefined.

Each errno value is associated with an error message that can be printed by using perror or stored in a string by using strerror. perror and strerror use the _sys_errlist array and _sys_nerr—the number of elements in _sys_errlist—to process error information.

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.

Constant

System error message

Value

EPERM

Operation not permitted

1

ENOENT

No such file or directory

2

ESRCH

No such process

3

EINTR

Interrupted function

4

EIO

I/O error

5

ENXIO

No such device or address

6

E2BIG

Argument list too long

7

ENOEXEC

Exec format error

8

EBADF

Bad file number

9

ECHILD

No spawned processes

10

EAGAIN

No more processes or not enough memory or maximum nesting level reached

11

ENOMEM

Not enough memory

12

EACCES

Permission denied

13

EFAULT

Bad address

14

EBUSY

Device or resource busy

16

EEXIST

File exists

17

EXDEV

Cross-device link

18

ENODEV

No such device

19

ENOTDIR

Not a directory

20

EISDIR

Is a directory

21

EINVAL

Invalid argument

22

ENFILE

Too many files open in system

23

EMFILE

Too many open files

24

ENOTTY

Inappropriate I/O control operation

25

EFBIG

File too large

27

ENOSPC

No space left on device

28

ESPIPE

Invalid seek

29

EROFS

Read-only file system

30

EMLINK

Too many links

31

EPIPE

Broken pipe

32

EDOM

Math argument

33

ERANGE

Result too large

34

EDEADLK

Resource deadlock would occur

36

EDEADLOCK

Same as EDEADLK for compatibility with older Microsoft C versions

36

ENAMETOOLONG

Filename too long

38

ENOLCK

No locks available

39

ENOSYS

Function not supported

40

ENOTEMPTY

Directory not empty

41

EILSEQ

Illegal byte sequence

42

STRUNCATE

String was truncated

80

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.