errno
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <errno.h> 中定义
|
||
| #define errno /*implementation-defined*/ |
||
errno是一个宏,扩展到一个线程本地修改的左值的类型int。一些标准库函数表示的正整数写入errno的错误。通常,该值被设置为一个错误代码,errno中列出的作为宏常数开头的信<errno.h>,其次由大写字母或数字的E.原文:
errno is a preprocessor macro that expands to a thread-local modifiable lvalue of type int. Several standard library functions indicate errors by writing positive integers to errno. Typically, the value of errno is set to one the error codes, listed in <errno.h> as macro constants that begin with the letter E, followed by uppercase letters or digits.的价值
errno是0在程序启动时,,虽然库函数可以写正整数errno是否发生了错误,不会储存库函数0在errno.原文:
The value of
errno is 0 at program startup, and although library functions are allowed to write positive integers to errno whether or not an error occurred, library functions never store 0 in errno.[编辑] 示例
#include <stdio.h> #include <errno.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> int main (int argc, char **argv) { int fd = -1; fd = open ("/dev/zer0", O_RDONLY); if (errno) { perror ("Ouuupsss"); exit (EXIT_FAILURE); } close (fd); return EXIT_SUCCESS; }
输出:
Ouuupsss: No such file or directory
[编辑] 另请参阅
| 宏为标准的POSIX兼容的错误条件 原文: macros for standard POSIX-compatible error conditions (常量宏) | |
| 显示一个字符串相应的电流误差stderr 原文: displays a character string corresponding of the current error to stderr (函数) | |
| 返回一个给定的错误代码的文本版本 原文: returns a text version of a given error code (函数) | |