errno、_doserrno、_sys_errlist、および _sys_nerrerrno, _doserrno, _sys_errlist, and _sys_nerr
プログラムの実行中に設定されるエラー コードと、エラー コードに相当する表示用の文字列を保持するグローバル マクロ。Global macros that hold error codes that are set during program execution, and string equivalents of the error codes for display.
構文Syntax
#define errno (*_errno())
#define _doserrno (*__doserrno())
#define _sys_errlist (__sys_errlist())
#define _sys_nerr (*__sys_nerr())
解説Remarks
errno
と _doserrno
は両方とも、プログラムの起動中にランタイムによって 0 に設定されます。Both errno
and _doserrno
are set to 0 by the runtime during program startup. システム レベルの呼び出しでエラーが発生すると、errno
が設定されます。errno
is set on an error in a system-level call. errno
には最後の呼び出しで設定された値が保持されるため、この値は、その後の呼び出しによって変更される可能性があります。Because errno
holds the value for the last call that set it, this value may be changed by succeeding calls. エラーの発生時に errno
を設定するランタイム ライブラリの呼び出しでは、正常に完了しても、errno
はクリアされません。Run-time library calls that set errno
on an error do not clear errno
on success. errno
は、これを設定する呼び出しの直前に _set_errno(0)
を呼び出して必ずクリアし、呼び出しの直後に確認します。Always clear errno
by calling _set_errno(0)
immediately before a call that may set it, and check it immediately after the call.
エラーの発生時、errno
は、必ずしもシステム呼び出しで返されるエラー コードと同じ値に設定されるとは限りません。On an error, errno
is not necessarily set to the same value as the error code returned by a system call. I/O 操作では、_doserrno
に errno
コードと同等のオペレーティング システムのエラー コードが格納されます。For I/O operations, _doserrno
stores the operating-system error-code equivalents of errno
codes. I/O 以外の操作については、ほとんどの場合、_doserrno
の値は設定されません。For most non-I/O operations, the value of _doserrno
is not set.
各 errno
値は、_sys_errlist
のエラー メッセージに関連付けられており、これは perror 関数のいずれかを使用して出力するか、strerror または strerror_s 関数のいずれかを使用して文字列に格納できます。Each errno
value is associated with an error message in _sys_errlist
that can be printed by using one of the perror functions, or stored in a string by using one of the strerror or strerror_s functions. perror
および strerror
関数は、_sys_errlist
配列と _sys_nerr
(_sys_errlist
の要素の数) を使用して、エラー情報を処理します。The perror
and strerror
functions use the _sys_errlist
array and _sys_nerr
—the number of elements in _sys_errlist
—to process error information. _sys_errlist
および _sys_nerr
への直接アクセスは、コードのセキュリティ上の理由から非推奨とされます。Direct access to _sys_errlist
and _sys_nerr
is deprecated for code-security reasons. 次に示すように、グローバル マクロではなく、より安全かつ機能的なバージョンを使用することをお勧めします。We recommend that you use the more secure, functional versions instead of the global macros, as shown here:
グローバル マクロGlobal Macro | 機能的に同等なバージョンFunctional Equivalents |
---|---|
_doserrno |
_get_doserrno、_set_doserrno_get_doserrno, _set_doserrno |
errno |
_get_errno、_set_errno_get_errno, _set_errno |
_sys_errlist , _sys_nerr _sys_errlist , _sys_nerr |
strerror_s、_strerror_s、_wcserror_s、 _ _wcserror_sstrerror_s, _strerror_s, _wcserror_s, __wcserror_s |
ライブラリの数値演算ルーチンでは、_matherr を呼び出して errno
を設定します。Library math routines set errno
by calling _matherr. 別の方法で数値演算エラーを処理するには、_matherr
リファレンスの説明に従って独自のルーチンを記述し、_matherr
という名前を付けます。To handle math errors differently, write your own routine according to the _matherr
reference description and name it _matherr
.
次の表のすべての errno
値は、の定義済み定数で、 <errno.h> UNIX と互換性があります。All errno
values in the following table are predefined constants in <errno.h>, and are UNIX-compatible. ERANGE
、EILSEQ
、および EDOM
のみが、ISO C99 標準で指定されます。Only ERANGE
, EILSEQ
, and EDOM
are specified in the ISO C99 standard.
定数Constant | システム エラー メッセージSystem error message | 値Value |
---|---|---|
EPERM |
操作は許可されていませんOperation not permitted | 11 |
ENOENT |
を開けませんでした 原因: ファイルまたはディレクトリが存在しませんNo such file or directory | 22 |
ESRCH |
該当するプロセスがありませんNo such process | 33 |
EINTR |
関数に割り込みがありましたInterrupted function | 44 |
EIO |
I/O エラーですI/O error | 55 |
ENXIO |
このようなデバイスまたはアドレスはありませんNo such device or address | 66 |
E2BIG |
引数が長すぎますArgument list too long | 77 |
ENOEXEC |
実行形式エラーですExec format error | 88 |
EBADF |
ファイル番号が正しくありませんBad file number | 99 |
ECHILD |
子プロセスが存在しませんNo spawned processes | 1010 |
EAGAIN |
これ以上プロセスを生成できないか、メモリが不足しているか、最大の入れ子レベルに達しましたNo more processes or not enough memory or maximum nesting level reached | 1111 |
ENOMEM |
メモリが不足していますNot enough memory | 1212 |
EACCES |
アクセス許可は拒否されましたPermission denied | 1313 |
EFAULT |
アドレスが正しくありませんBad address | 1414 |
EBUSY |
デバイスまたはリソースがビジー状態ですDevice or resource busy | 1616 |
EEXIST |
ファイルが存在するかFile exists | 1717 |
EXDEV |
クロス デバイス リンクがありますCross-device link | 1818 |
ENODEV |
該当するデバイスがありませんNo such device | 1919 |
ENOTDIR |
ディレクトリではありませんNot a directory | 2020 |
EISDIR |
ディレクトリですIs a directory | 2121 |
EINVAL |
引数が無効ですInvalid argument | 2222 |
ENFILE |
システムで開いているファイルが多すぎますToo many files open in system | 2323 |
EMFILE |
開いているファイルが多すぎますToo many open files | 2424 |
ENOTTY |
不適切な I/O 制御操作ですInappropriate I/O control operation | 2525 |
EFBIG |
ファイルが大きすぎますFile too large | 2727 |
ENOSPC |
デバイスに空き領域がありませんNo space left on device | 2828 |
ESPIPE |
シークが無効ですInvalid seek | 2929 |
EROFS |
読み取り専用ファイル システムが使用されていますRead-only file system | 3030 |
EMLINK |
リンクが多すぎますToo many links | 3131 |
EPIPE |
パイプが破壊されていますBroken pipe | 3232 |
EDOM |
算術演算引数が使用されましたMath argument | 3333 |
ERANGE |
結果が大きすぎますResult too large | 3434 |
EDEADLK |
リソース デッドロックが発生しますResource deadlock would occur | 3636 |
EDEADLOCK |
古いバージョンの Microsoft C との互換性のために EDEADLK と同じですSame as EDEADLK for compatibility with older Microsoft C versions | 3636 |
ENAMETOOLONG |
ファイル名が長すぎますFilename too long | 3838 |
ENOLCK |
ロックがありませんNo locks available | 3939 |
ENOSYS |
関数はサポートされていませんFunction not supported | 4040 |
ENOTEMPTY |
ディレクトリが空ではありませんDirectory not empty | 4141 |
EILSEQ |
無効なバイト シーケンスですIllegal byte sequence | 4242 |
STRUNCATE |
残りの文字列は切り詰められましたString was truncated | 8080 |
要件Requirements
グローバル マクロGlobal macro | 必須ヘッダーRequired header | オプション ヘッダーOptional header |
---|---|---|
errno |
<errno.h> または <stdlib.h> 、 <cerrno> または <cstdlib> (C++)<errno.h> or <stdlib.h>, <cerrno> or <cstdlib> (C++) | |
_doserrno , _sys_errlist , _sys_nerr _doserrno , _sys_errlist , _sys_nerr |
<stdlib.h>、 <cstdlib> (C++)<stdlib.h>, <cstdlib> (C++) | <errno.h>、 <cerrno> (C++)<errno.h>, <cerrno> (C++) |
_doserrno
、_sys_errlist
、および _sys_nerr
マクロは Microsoft 拡張機能です。The _doserrno
, _sys_errlist
, and _sys_nerr
macros are Microsoft extensions. 互換性について詳しくは、「 Compatibility」をご覧ください。For more compatibility information, see Compatibility.
関連項目See also
グローバル変数Global Variables
errno 定数errno Constants
perror、_wperrorperror, _wperror
strerror、_strerror、_wcserror、 _ _wcserrorstrerror, _strerror, _wcserror, __wcserror
strerror_s、_strerror_s、_wcserror_s、 _ _wcserror_sstrerror_s, _strerror_s, _wcserror_s, __wcserror_s
_get_doserrno_get_doserrno
_set_doserrno_set_doserrno
_get_errno_get_errno
_set_errno_set_errno