C Standard Library 简明教程

C Library - <errno.h>

C 标准库的 errno.h 头文件定义整型变量 errno ,由系统调用和一些库函数在出现错误时设置,以指示出了什么问题。此宏扩展为 int 类型的可修改左值,因此它既可以被程序读取,也可以被程序修改。

The errno.h header file of the C Standard Library defines the integer variable errno, which is set by system calls and some library functions in the event of an error to indicate what went wrong. This macro expands to a modifiable lvalue of type int, therefore it can be both read and modified by a program.

errno 在程序启动时被设置为零。标准 C 库的某些函数将其值修改为非零以表示某些类型的错误。您还可以根据需要修改其值或将其重置为零。

The errno is set to zero at program startup. Certain functions of the standard C library modify its value to other than zero to signal some types of error. You can also modify its value or reset to zero at your convenience.

errno.h 头文件还定义了一个列出不同错误代码的宏列表,它将扩展为具有类型 int 的整数常量表达式。

The errno.h header file also defines a list of macros indicating different error codes, which will expand to integer constant expressions with type int.

Library Macros

以下是 头 errno.h 中定义的宏 −

Following are the macros defined in the header errno.h −

Sr.No.

Macro & Description

1

extern int errnoThis is the macro set by system calls and some library functions in the event of an error to indicate what went wrong.

2

EDOM Domain ErrorThis macro represents a domain error, which occurs if an input argument is outside the domain, over which the mathematical function is defined and errno is set to EDOM.

3

ERANGE Range ErrorThis macro represents a range error, which occurs if an input argument is outside the range, over which the mathematical function is defined and errno is set to ERANGE.