1 题目
测试strerror函数。
2 代码:
执行环境:VC++6.0
#include <stdio.h> #include <string.h> #include <errno.h> void main() { int errnum; for(errnum = 1; errnum < 43; errnum++) printf("error %d : %s/n", errnum, strerror(errnum)); printf("/n"); }
执行结果:
error 1 : Operation not permitted
error 2 : No such file or directory
error 3 : No such process
error 4 : Interrupted function call
error 5 : Input/output error
error 6 : No such device or address
error 7 : Arg list too long
error 8 : Exec format error
error 9 : Bad file descriptor
error 10 : No child processes
error 11 : Resource temporarily unavailable
error 12 : Not enough space
error 13 : Permission denied
error 14 : Bad address
error 15 : Unknown error
error 16 : Resource device
error 17 : File exists
error 18 : Improper link
error 19 : No such device
error 20 : Not a directory
error 21 : Is a directory
error 22 : Invalid argument
error 23 : Too many open files in system
error 24 : Too many open files
error 25 : Inappropriate I/O control operation
error 26 : Unknown error
error 27 : File too large
error 28 : No space left on device
error 29 : Invalid seek
error 30 : Read-only file system
error 31 : Too many links
error 32 : Broken pipe
error 33 : Domain error
error 34 : Result too large
error 35 : Unknown error
error 36 : Resource deadlock avoided
error 37 : Unknown error
error 38 : Filename too long
error 39 : No locks available
error 40 : Function not implemented
error 41 : Directory not empty
error 42 : Illegal byte sequence
Press any key to continue
3 资料:
Errno.h中对error num 的定义:
/* Error Codes */
#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 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 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 36
#define ENAMETOOLONG 38
#define ENOLCK 39
#define ENOSYS 40
#define ENOTEMPTY 41
#define EILSEQ 42