==C エラー==
[[Programming C]]
*system callが失敗すると、外部変数 errno に設定する。
*errnoの値は該当する関数を呼び出した直後に調べる必要がある。
===strerror===
#include <<string.h>>
char *strerror(int errnum);
*指定されたerror番号のerrorの種類を説明する文字列を返す。
===perror===
#include <<stdio.h>>
void perror(const char *s);
*errnoが示す現在のerrorの種類を説明する文字列を標準error出力に出力する。
*文字列sがNULLでなければ、sで指定された文字列に続いて、: と空白を出力してから、error種類をあらわす文字列を出力する。
----
#include <<string.h>> #include <<error.h>> #include <<stdint.h>> #include <<stdio.h>> #include <<stdlib.h>>
int main()
{
char *buf;
buf = (char *)malloc(sizeof(char) * 256);
for (i=0; i<<256; i++) {
buf = strerror(i);
printf("%d : %s\n", i,buf);