.\" 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 .\" .\" 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, write to the Free .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, .\" USA. .\" .\" 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) .\" .\" 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 .\" .TH PERROR 3 2007-07-26 "" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O perror \- print a system error message perror \- システムエラーメッセージを出力する .\"O .SH SYNOPSIS .SH 書式 .B #include .sp .BI "void perror(const char *" s ); .sp .B #include .sp .BI "const char *" sys_errlist []; .br .BI "int " sys_nerr ; .br .BI "int " errno ; .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .IR sys_errlist , .IR sys_nerr : _BSD_SOURCE .\"O .SH DESCRIPTION .SH 説明 .\"O The routine .\"O .BR perror () .\"O produces a message on the standard error output, describing the last .\"O error encountered during a call to a system or library function. 関数 .BR perror () は、システムコールやライブラリ関数の呼び出しにおいて、最後に発生した エラーに関する説明メッセージを生成し、標準エラー出力に出力する。 .\"O First (if .\"O .I s .\"O is not NULL and .\"O .I *s .\"O is not a null byte (\(aq\\0\(aq)) the argument string .\"O .I s .\"O is printed, followed by a colon and a blank. .\"O Then the message and a new-line. .RI ( s が NULL でなく、 .I *s が NULL バイト (\(aq\\0\(aq) でない場合には) 引き数の文字列 .I s がまず出力され、続いてコロン、空白が出力され、 それからメッセージと改行が出力される。 .\"O To be of most use, the argument string should include the name .\"O of the function that incurred the error. .\"O The error number is taken from .\"O the external variable .\"O .IR errno , .\"O which is set when errors occur but not .\"O cleared when successful calls are made. このメッセージを最大限活用するためには、引き数文字列にエラーが発生した 関数名を入れておくとよい。 エラー番号は外部変数 .I errno から取得される。 .I errno はエラーが発生した時に設定され、 成功した呼び出しではクリアされない。 .\"O The global error list .\"O .IR sys_errlist "[]" .\"O indexed by .\"O .I errno .\"O can be used to obtain the error message without the newline. .\"O The largest message number provided in the table is .\"O .IR sys_nerr " \-1." .\"O Be careful when directly accessing this list because new error values .\"O may not have been added to .\"O .IR sys_errlist "[]." 大域変数のエラーリスト .IR sys_errlist "[]" は .I errno を添字とする配列で、この配列から改行無しのエラーメッセージが取得される。 テーブルでの最大のメッセージ番号は .IR sys_nerr " \-1" となる。 このテーブルを直接参照する際には注意すること。なぜなら、新しいエラー番号が .IR sys_errlist "[]" に追加済とは限らないからである。 .\"O When a system call fails, it usually returns \-1 and sets the .\"O variable .\"O .I errno .\"O to a value describing what went wrong. .\"O (These values can be found in .\"O .IR .) .\"O Many library functions do likewise. システムコールが失敗した場合、通常、返り値として \-1 が返り、 .I errno にエラーを識別する値が設定される (設定されるエラー番号は .I に記載されている)。 多くのライブラリ関数も同様の動作となる。 .\"O The function .\"O .BR perror () .\"O serves to translate this error code into human-readable form. .\"O Note that .\"O .I errno .\"O is undefined after a successful library call: .\"O this call may well change this variable, even though it succeeds, .\"O for example because it internally used some other library function that failed. 関数 .BR perror () は、このエラーコードの可読なメッセージへの変換を行う。 .I errno は、ライブラリ呼び出しが成功した後には未定義であることに注意が必要である: その呼び出し自身は成功したとしても、内部で呼び出した他のライブラリ関数が 失敗して、その結果をこの変数に設定することがあるからだ。 .\"O Thus, if a failing call is not immediately followed by a call to .\"O .BR perror (), .\"O the value of .\"O .I errno .\"O should be saved. よって、失敗した呼び出しの直後に .BR perror () を呼ばない場合には .I errno の値を 保存しておかなければならない。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O The function .\"O .BR perror () .\"O and the external .\"O .I errno .\"O (see .\"O .BR errno (3)) .\"O conform to C89, C99, 4.3BSD, POSIX.1-2001. .\"O The externals .\"O .I sys_nerr .\"O and .\"O .I sys_errlist .\"O conform to BSD. 関数 .BR perror () と外部変数 .I errno .RB ( errno (3) 参照) は C89, 4.3BSD, POSIX.1-2001 に準拠している。 外部変数 .I sys_nerr と .I sys_errlist は BSD に準拠している。 .\"O .SH NOTES .SH 注意 .\"O The externals .\"O .I sys_nerr .\"O and .\"O .I sys_errlist .\"O are defined by glibc, but in .\"O .IR . 外部変数 .I sys_nerr と .I sys_errlist は glibc で定義されているが、 .I に含まれている。 .\"O .\" and only when _BSD_SOURCE is defined. .\"O .\" When .\"O .\" .B _GNU_SOURCE .\"O .\" is defined, the symbols .\"O .\" .I _sys_nerr .\"O .\" and .\"O .\" .I _sys_errlist .\"O .\" are provided. .\" .B _BSD_SOURCE .\" が定義された場合にのみ、これらの変数は定義される。 .\" .B _GNU_SOURCE .\" が定義された場合は、 .\" .I _sys_nerr .\" と .\" .I _sys_errlist .\" というシンボルが提供される。 .\"O .SH "SEE ALSO" .SH 関連項目 .BR err (3), .BR errno (3), .BR error (3), .BR strerror (3)