Partilhar via


errno, _doserrno, _sys_errlist, and _sys_nerr

These global variables hold error codes used by the perror and strerror functions for printing error messages. The more secure functional versions listed in this table should be used in place of their global variable.

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;

Remarks

errno and _errno are connected to the same variable. errno is defined with the code #define errno (*_errno())

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. Always check errno immediately before and after a call that may set it.

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 using perror or stored in a string 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, defined as predefined constants in ERRNO.H, are UNIX-compatible and are listed below. Only ERANGE, EILSEQ and EDOM are specified in the ANSI 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

See Also

Reference

Global Variables

errno Constants

perror

strerror

_get_doserrno

_set_doserrno

_get_errno

_set_errno