加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

errno.h头文件介绍

(2018-08-19 20:03:30)
标签:

linux

errno

分类: Linux人生
当 linux C api 函数发生异常时,一般会将 errno 变量(需 include "errno.h" )赋一个整数值,不同的值表示不同的含义,可以通过查看该值推测出错的原因。

以下来自linux 2.4.20-18的内核代码中的/usr/includem/errno.h
#ifndef _I386_ERRNO_H
#define _I386_ERRNO_H

#define EPERM                        1
#define ENOENT                      2
#define ESRCH                         3
#define EINTR                          4
#define EIO                              5
#define ENXIO                         6
#define E2BIG                          7
#define ENOEXEC                    8
#define EBADF                         9
#define ECHILD                       10
#define EAGAIN                      11
#define ENOMEM                   12
#define EACCES                      13
#define EFAULT                       14
#define ENOTBLK                    15
#define EBUSY                         16
#define EEXIST                        17
#define EXDEV                        18
#define ENODEV                     19
#define ENOTDIR                    20
#define EISDIR                        21
#define EINVAL                       22
#define ENFILE                        23
#define EMFILE                       24
#define ENOTTY                      25
#define ETXTBSY                     26
#define EFBIG                          27
#define ENOSPC                     28
#define ESPIPE                       29
#define EROFS                        30
#define EMLINK                     31
#define EPIPE                         32
#define EDOM                        33
#define ERANGE                     34
#define EDEADLK                   35
#define ENAMETOOLONG     36
#define ENOLCK                     37
#define ENOSYS                     38
#define ENOTEMPTY             39
#define ELOOP                       40
#define EWOULDBLOCK        EAGAIN
#define ENOMSG                   42
#define EIDRM                       43
#define ECHRNG                    44
#define EL2NSYNC                 45
#define EL3HLT                      46
#define EL3RST                      47
#define ELNRNG                    48
#define EUNATCH                 49
#define ENOCSI                    50
#define EL2HLT                     51
#define EBADE                      52
#define EBADR                     53
#define EXFULL                     54
#define ENOANO                  55
#define EBADRQC                56
#define EBADSLT                  57
#define EDEADLOCK            EDEADLK
#define EBFONT                   59
#define ENOSTR                   60
#define ENODATA               61
#define ETIME                      62
#define ENOSR                     63
#define ENONET                  64
#define ENOPKG                  65
#define EREMOTE                66
#define ENOLINK                 67
#define EADV                       68
#define ESRMNT                  69
#define ECOMM                  70
#define EPROTO                  71
#define EMULTIHOP           72
#define EDOTDOT               73
#define EBADMSG              74
#define EOVERFLOW           75
#define ENOTUNIQ             76
#define EBADFD                  77
#define EREMCHG               78
#define ELIBACC                  79
#define ELIBBAD                 80
#define ELIBSCN                  81
#define ELIBMAX                 82
#define ELIBEXEC                 83
#define EILSEQ                     84
#define ERESTART               85
#define ESTRPIPE                86
#define EUSERS                   87
#define ENOTSOCK             88
#define EDESTADDRREQ   89
#define EMSGSIZE              90
#define EPROTOTYPE         91
#define ENOPROTOOPT     92
#define EPROTONOSUPPORT 93
#define ESOCKTNOSUPPORT 94
#define EOPNOTSUPP       95
#define EPFNOSUPPORT   96
#define EAFNOSUPPORT   97
#define EADDRINUSE        98
#define EADDRNOTAVAIL 99
#define ENETDOWN          100
#define ENETUNREACH     101
#define ENETRESET            102
#define ECONNABORTED  103
#define ECONNRESET        104
#define ENOBUFS               105
#define EISCONN                106
#define ENOTCONN           107
#define ESHUTDOWN        108
#define ETOOMANYREFS   109
#define ETIMEDOUT           110
#define ECONNREFUSED    111
#define EHOSTDOWN        112
#define EHOSTUNREACH   113
#define EALREADY              114
#define EINPROGRESS        115
#define ESTALE                    116
#define EUCLEAN                117
#define ENOTNAM             118
#define ENAVAIL                 119
#define EISNAM                  120
#define EREMOTEIO            121
#define EDQUOT                 122
#define ENOMEDIUM         123
#define EMEDIUMTYPE      124

#endif  // #ifndef _I386_ERRNO_H


//================================================================================
#include
char *strerror(int errnum);

The strerror() function returns a pointer to a string that describes
the error code sed in the argument errnum, possibly using the
LC_MESSAGES part of the current locale to select the appropriate
language.

//================================================================================
#include
void perror(const char *s);

#include
const char * const sys_errlist[];
int sys_nerr;
int errno;      

The perror() function produces a message on standard error describing
the t error encountered during a call to a system or library
function.

First (if s is not NULL and *s is not a null byte ('\0')), the
argument string s is printed, followed by a colon and a blank.  Then
an error message corresponding to the current value of errno and a
new-line.

//================================================================================
#include
void error(int status, int errnum, const char *format, ...);

void error_at_line(int status, int errnum, const char *filename,
                   unsigned int linenum, const char *format, ...);
  
error() is a general error-reporting function.  It flushes stdout,
and then outputs to stderr the program name, a colon and a space, the
message specified by the printf(3)-style format string format, and,
if errnum is nonzero, a second colon and a space followed by the
string given by strerror(errnum).  Any arguments required for format
should follow format in the argument list.  The output is terminated
by a newline character.

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有