.\" Copyright (c) 1994 Michael Haardt (michael@moria.de), 1994-06-04 .\" Copyright (c) 1995 Michael Haardt .\" (michael@cantor.informatik.rwth-aachen.de), 1995-03-16 .\" Copyright (c) 1996 Andries Brouwer (aeb@cwi.nl), 1996-01-13 .\" .\" %%%LICENSE_START(GPLv2+_DOC_FULL) .\" This is free documentation; you can redistribute it and/or .\" modify it under the terms of the GNU General Public License as .\" published by the Free Software Foundation; either version 2 of .\" the License, or (at your option) any later version. .\" .\" The GNU General Public License's references to "object code" .\" and "executables" are to be interpreted as the output of any .\" document formatting or typesetting system, including .\" intermediate and printed output. .\" .\" This manual is distributed in the hope that it will be useful, .\" but WITHOUT ANY WARRANTY; without even the implied warranty of .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the .\" GNU General Public License for more details. .\" .\" You should have received a copy of the GNU General Public .\" License along with this manual; if not, see .\" . .\" %%%LICENSE_END .\" .\" 1996-01-13 aeb: merged in some text contributed by Melvin Smith .\" (msmith@falcon.mercer.peachnet.edu) and various other changes. .\" Modified 1996-05-16 by Martin Schulze (joey@infodrom.north.de) .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1998 TACHIBANA Akira .\" all rights reserved. .\" Translated 1998-05-28, TACHIBANA Akira .\" Updated 2001-12-21, Kentaro Shirakata .\" Updated 2005-03-15, Akihiro MOTOKI .\" Updated 2012-04-30, Akihiro MOTOKI .\" .TH PERROR 3 2014\-05\-28 "" "Linux Programmer's Manual" .SH 名前 perror \- システムエラーメッセージを出力する .SH 書式 \fB#include \fP .sp \fBvoid perror(const char *\fP\fIs\fP\fB);\fP .sp \fB#include \fP .sp \fBconst char * const \fP\fIsys_errlist\fP\fB[];\fP .br \fBint \fP\fIsys_nerr\fP\fB;\fP .br \fBint \fP\fIerrno\fP\fB; /* 実際にこのように宣言されているわけではない。 errno(3) 参照 */\fP .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp \fIsys_errlist\fP, \fIsys_nerr\fP: _BSD_SOURCE .SH 説明 関数 \fBperror\fP() は、システムコールやライブラリ関数の呼び出しにおいて、最後に発生した エラーに関する説明メッセージを生成し、標準エラー出力に出力する。 (\fIs\fP が NULL でなく、 \fI*s\fP がヌルバイト (\(aq\e0\(aq) でない場合には) 引き数の文字列 \fIs\fP がまず出力され、続いてコロン、空白が出力され、 それからメッセージと改行が出力される。 このメッセージを最大限活用するためには、引き数文字列にエラーが発生した 関数名を入れておくとよい。 エラー番号は外部変数 \fIerrno\fP から取得される。 \fIerrno\fP はエラーが発生した時に設定され、 成功した呼び出しではクリアされない。 大域変数のエラーリスト \fIsys_errlist\fP[] は \fIerrno\fP を添字とする配列で、この 配列から改行無しのエラーメッセージが取得される。 テーブルでの最大のメッセージ 番号は \fIsys_nerr\fP \-1 となる。 このテーブルを直接参照する際には注意すること。 なぜなら、新しいエラー番号が \fIsys_errlist\fP[] に追加済とは限らないからである。 現在では、\fIsys_errlist\fP[] の使用は非推奨となっている。 システムコールが失敗した場合、通常、返り値として \-1 が返り、 \fIerrno\fP にエラーを識別する値が設定される (設定されるエラー番号は \fI\fP に記載されている)。 多くのライブラリ関数も同様の動作となる。 関数 \fBperror\fP() は、このエラーコードの可読なメッセージへの変換を行う。 \fIerrno\fP は、ライブラリ呼び出しが成功した後には未定義であることに注意が必要である: その呼び出し自身は成功したとしても、内部で呼び出した他のライブラリ関数が 失敗して、その結果をこの変数に設定することがあるからだ。 よって、失敗した呼び出しの直後に \fBperror\fP() を呼ばない場合には \fIerrno\fP の値を 保存しておかなければならない。 .SH 準拠 関数 \fBperror\fP() と外部変数 \fIerrno\fP (\fBerrno\fP(3) 参照) は C89, 4.3BSD, POSIX.1\-2001 に準拠している。 外部変数 \fIsys_nerr\fP と \fIsys_errlist\fP は BSD に準拠している。 .SH 注意 .\" and only when _BSD_SOURCE is defined. .\" When .\" .B _GNU_SOURCE .\" is defined, the symbols .\" .I _sys_nerr .\" and .\" .I _sys_errlist .\" are provided. 外部変数 \fIsys_nerr\fP と \fIsys_errlist\fP は glibc で定義されているが、 \fI\fP に含まれている。 .SH 関連項目 \fBerr\fP(3), \fBerrno\fP(3), \fBerror\fP(3), \fBstrerror\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。