errno和錯誤号
1.函數調用出錯時,Linux系統使用錯誤編号(整型)來标記具體出錯原因,每個函數有很多錯誤号,沒個錯誤号代表一種錯誤
産生這個錯誤時,會自動将錯誤号指派給errno這個全局變量
errno是Linux系統定義的全局變量可直接使用,在errno.h裡定義
man errno
perror函數
perror可自動将錯誤号換成對應的文字資訊,并列印出來
調用perror時,它會自動去一張對照表,将errorno中儲存的錯誤号換成具體的文字資訊并列印出來
c庫函數
man 3 perror
#include <stdio.h>
void perror(const char *s);
#include <errno.h>
man strerror
#include <string.h>
char *strerror(int errnum);