首先看下 perror 的栗子,好有个感官上的认识:
由于打开的是个不存在的文件,一定会有个系统错误,上面程序会输出:
perror : No such file or directory
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int fd;
fd = open("/dev/really_no_exists", O_RDWR);
if(fd<0)
{
perror("perror");
}
}
由于打开的是个不存在的文件,一定会有个系统错误,上面程序会输出:
perror : No such file or directory