.\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk) .\" and Copyright (C) 2005, Michael Kerrisk .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sat Jul 24 18:05:30 1993 by Rik Faith .\" Modified Fri Feb 16 14:25:17 1996 by Andries Brouwer .\" Modified Sun Jul 21 20:55:44 1996 by Andries Brouwer .\" Modified Mon Oct 15 21:16:25 2001 by John Levon .\" Modified Tue Oct 16 00:04:43 2001 by Andries Brouwer .\" Modified Fri Jun 20 03:04:30 2003 by Andries Brouwer .\" 2005-12-13, mtk, Substantial rewrite of strerror_r() description .\" Addition of extra material on portability and standards. .\" .\" Japanese Version Copyright (c) 1997 YOSHINO Takashi .\" all rights reserved. .\" Translated 1997-01-20, YOSHINO Takashi .\" Updated & Modified 2001-11-03, Yuichi SATO .\" Updated 2005-12-26, Akihiro MOTOKI .\" Updated 2007-09-06, Akihiro MOTOKI , LDP v2.64 .\" .\"WORD GNU-specific GNU 仕様の .\"WORD XSI-compliant XSI 準拠の .\" .TH STRERROR 3 2009-03-30 "" "Linux Programmer's Manual" .SH 名前 strerror, strerror_r \- エラー番号を説明する文字列を返す。 .SH 書式 .nf .B #include .sp .BI "char *strerror(int " errnum ); .sp .BI "char *strerror_r(int " errnum ", char *" buf ", size_t " buflen ); .fi .sp .in -4n glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp 次の場合には XSI 準拠のバージョンの .BR strerror_r () が提供される: .br (_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600) && !\ _GNU_SOURCE .fi .SH 説明 .BR strerror () 関数は、引き数 \fIerrnum\fP で渡されたエラーコードについての 説明が入った文字列へのポインタを返す。 可能であるならば、適切な言語を選択するために、 現在のロケールの .B LC_MESSAGES を使う。 この文字列は、アプリケーションで変更してはならないが、 その後に起こる .BR perror (3) や .BR strerror () の呼び出しで 変更されても構わない。 この文字列を変更するライブラリ関数はない。 .BR strerror_r () 関数は .BR strerror () と似ているが、 スレッドセーフである。 この関数には二種類のバージョンが存在し、 POSIX.1-2001 で規定された XSI 準拠のバージョン (glibc 2.3.4 以降で利用可能) と、 GNU 仕様のバージョン (glibc 2.0 以降で利用可能) である。 「書式」の節に記載された機能検査マクロの場合には、 XSI 準拠のバージョンが提供される。 それ以外の場合には GNU 仕様のバージョンが提供される。 機能検査マクロが一つも明示的に定義されない場合、 (glibc 2.4 以降では) デフォルトで .B _POSIX_SOURCE は値 200112l で定義され、その結果 XSI 準拠のバージョンの .BR strerror_r () がデフォルトで提供される。 移植性が必要なアプリケーションでは、 XSI 準拠の .BR strerror_r () を使う方がよい。 この関数は、ユーザーから提供される長さ .I buflen のバッファ .I buf にエラー文字列を返す。 GNU 仕様の .BR strerror_r () は、エラーメッセージを格納した文字列へのポインタを返す。 返り値は、この関数が .I buf に格納した文字列へのポインタか、 何らかの (不変な) 静的な文字列へのポインタ、のいずれかとなる (後者の場合は .I buf は使用されない)。 .I buf に文字列が格納される場合は、 最大で .I buflen バイトが格納され .RI ( buflen が小さ過ぎたときには文字列は切り詰められる)、 文字列には必ず終端ヌル文字が含まれる。 .SH 返り値 .BR strerror () と .BR strerror_r () はエラー内容を説明する 文字列を返す。エラー番号が未知の場合は "Unknown error nnn" という メッセージを返す。 XSI 準拠の .BR strerror_r () 関数は成功すると 0 を返す。 エラーの場合には、 \-1 を返し、 .I errno にエラー内容を示す値をセットする。 .SH エラー .TP .B EINVAL .I errnum の値が有効なエラー番号ではない。 .TP .B ERANGE エラーコードを説明する文字列のために、充分な領域が確保できなかった。 .SH 準拠 .BR strerror () は POSIX.1-2001, C89, C99 で規定されている。 .BR strerror_r () は POSIX.1-2001 で規定されている。 GNU 仕様の .BR strerror_r () 関数は非標準の拡張である。 POSIX.1-2001 は、 .BR strerror () がエラーに遭遇した場合に .I errno をセットすることを認めているが、エラー発生時に関数の結果として どんな値を返すべきかを規定してない。 あるシステムでは、 .\" 例えば Solaris 8, HP-UX 11 エラー番号が未知の場合、 .BR strerror () は NULL を返す。 他のシステムでは、 .\" 例えば FreeBSD 5.4, Tru64 5.1B エラー番号が未知の場合、 .BR strerror () は "Error nnn occurred" といった文字列を返し、 .I errno に .B EINVAL をセットする。 .SH 関連項目 .BR err (3), .BR errno (3), .BR error (3), .BR perror (3), .BR strsignal (3)