#navi(contents-page-name): No such page: DEBUG

errnoエラー番号に対する説明を表示する方法・strerror

errno(エラー番号)が表示された時、エラー番号に対する説明を取得する方法を以下に記します。
(ヘッダーファイルを見て調べる方法もありますが、以下のようにプログラム内に記述しておけば簡単にエラー番号の意味を確認することができます。

c-top.html is not found or not readable.

関連記事

strerrorを使ってみる

strerrorを使ってエラー番号に対するエラー内容を表示させるCサンプルコードを以下に記します。

strerror書式

strerrorのCサンプルコード

&ref(): File not found: "strerror.c" at page "DEBUG/errnoエラー番号に対する説明を表示する方法・strerror"; (改行コードLF)

#include <stdio.h>
#include <string.h>

int main(void)
{
    int i;
    for(i=0; i<30; i++) {
        printf("errno=%d : %s\n", i, strerror(i));
    }

    return 0;
}

strerrorの実行結果

サンプルコードでは、0〜29までのエラー番号について表示するようになっています。

$ gcc strerror.c -o strerror
$ ./strerror 
errno=0 : Success
errno=1 : Operation not permitted
errno=2 : No such file or directory
errno=3 : No such process
errno=4 : Interrupted system call
errno=5 : Input/output error
errno=6 : No such device or address
errno=7 : Argument list too long
errno=8 : Exec format error
errno=9 : Bad file descriptor
errno=10 : No child processes
errno=11 : Resource temporarily unavailable
errno=12 : Cannot allocate memory
errno=13 : Permission denied
errno=14 : Bad address
errno=15 : Block device required
errno=16 : Device or resource busy
errno=17 : File exists
errno=18 : Invalid cross-device link
errno=19 : No such device
errno=20 : Not a directory
errno=21 : Is a directory
errno=22 : Invalid argument
errno=23 : Too many open files in system
errno=24 : Too many open files
errno=25 : Inappropriate ioctl for device
errno=26 : Text file busy
errno=27 : File too large
errno=28 : No space left on device
errno=29 : Illegal seek

以上、strerrorのCサンプルコードでした。

c-btm.html is not found or not readable.

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS