OSDN Git Service

c80e924af1b1188d20121f1c17473d0f11f9be75
[linuxjm/LDP_man-pages.git] / release / man3 / strerror.3
1 .\" Copyright (C) 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\" and Copyright (C) 2005, Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" References consulted:
27 .\"     Linux libc source code
28 .\"     Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
29 .\"     386BSD man pages
30 .\" Modified Sat Jul 24 18:05:30 1993 by Rik Faith <faith@cs.unc.edu>
31 .\" Modified Fri Feb 16 14:25:17 1996 by Andries Brouwer <aeb@cwi.nl>
32 .\" Modified Sun Jul 21 20:55:44 1996 by Andries Brouwer <aeb@cwi.nl>
33 .\" Modified Mon Oct 15 21:16:25 2001 by John Levon <moz@compsoc.man.ac.uk>
34 .\" Modified Tue Oct 16 00:04:43 2001 by Andries Brouwer <aeb@cwi.nl>
35 .\" Modified Fri Jun 20 03:04:30 2003 by Andries Brouwer <aeb@cwi.nl>
36 .\" 2005-12-13, mtk, Substantial rewrite of strerror_r() description
37 .\"         Addition of extra material on portability and standards.
38 .\"
39 .\"*******************************************************************
40 .\"
41 .\" This file was generated with po4a. Translate the source file.
42 .\"
43 .\"*******************************************************************
44 .TH STRERROR 3 2013\-06\-21 "" "Linux Programmer's Manual"
45 .SH 名前
46 strerror, strerror_r \- エラー番号を説明する文字列を返す。
47 .SH 書式
48 .nf
49 \fB#include <string.h>\fP
50 .sp
51 \fBchar *strerror(int \fP\fIerrnum\fP\fB);\fP
52 .sp
53 \fBint strerror_r(int \fP\fIerrnum\fP\fB, char *\fP\fIbuf\fP\fB, size_t \fP\fIbuflen\fP\fB);\fP
54             /* XSI\-compliant */
55 .sp
56 \fBchar *strerror_r(int \fP\fIerrnum\fP\fB, char *\fP\fIbuf\fP\fB, size_t \fP\fIbuflen\fP\fB);\fP
57             /* GNU\-specific */
58 .fi
59 .sp
60 .in -4n
61 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
62 .in
63 .sp
64 次の場合には XSI 準拠のバージョンの \fBstrerror_r\fP()  が提供される:
65 .br
66 (_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600) && !\ _GNU_SOURCE
67 .br
68 それ以外の場合、GNU バージョンが提供される。
69 .SH 説明
70 \fBstrerror\fP() 関数は、引き数 \fIerrnum\fP で渡されたエラーコードについての
71 説明が入った文字列へのポインタを返す。 可能であるならば、適切な言語を選
72 択するために、 現在のロケールの \fBLC_MESSAGES\fP を使う。(例えば、
73 \fIerrnum\fP が \fBEINVAL\fP の場合、説明として"Invalid argument" が返され
74 る。) この文字列は、アプリケーションで変更してはならないが、 これ以降に
75 行われる \fBstrerror\fP() の呼び出しで 変更されても構わない。この文字列を
76 変更するライブラリ関数はない (\fBperror\fP(3) も含まれる)。
77
78 \fBstrerror_r\fP() 関数は \fBstrerror\fP() と似ているが、スレッドセーフである。
79 この関数には二種類のバージョンが存在し、 POSIX.1\-2001 で規定された XSI
80 準拠のバージョン (glibc 2.3.4 以降で利用可能だが、glibc 2.13 までは
81 POSIX 準拠ではない) と、 GNU 仕様のバージョン (glibc 2.0 以降で利用可能)
82 である。 「書式」の節に記載された機能検査マクロの場合には、 XSI 準拠の
83 バージョンが提供される。それ以外の場合には GNU 仕様のバージョンが提供さ
84 れる。機能検査マクロが一つも明示的に定義されない場合、 (glibc 2.4 以降
85 では) デフォルトで \fB_POSIX_SOURCE\fP は値 200112l で定義され、その結果
86 XSI 準拠のバージョンの \fBstrerror_r\fP() がデフォルトで提供される。
87
88 移植性が必要なアプリケーションでは、 XSI 準拠の \fBstrerror_r\fP()  を使う方がよい。 この関数は、ユーザーから提供される長さ
89 \fIbuflen\fP のバッファ \fIbuf\fP にエラー文字列を返す。
90
91 GNU 仕様の \fBstrerror_r\fP() は、 エラーメッセージを格納した文字列へのポインタを返す。 返り値は、 この関数が \fIbuf\fP
92 に格納した文字列へのポインタか、 何らかの (不変な) 静的な文字列へのポインタ、 のいずれかとなる (後者の場合は \fIbuf\fP は使用されない)。
93 \fIbuf\fP に文字列が格納される場合は、 最大で \fIbuflen\fP バイトが格納される (\fIbuflen\fP
94 が小さ過ぎたときには文字列は切り詰められ、 \fIerrnum\fP は不定である)。 文字列には必ず終端ヌル文字 (\(aq\e0\(aq) が含まれる。
95 .SH 返り値
96 \fBstrerror\fP()  と \fBstrerror_r\fP()  はエラー内容を説明する 文字列を返す。エラー番号が未知の場合は "Unknown
97 error nnn" という メッセージを返す。
98
99 POSIX.1\-2001 と POSIX.1\-2008 では、 \fBstrerror\fP() が成功した場合は
100 \fIerrno\fP を変更せずに元のままにしなければならないとされている。関数のど
101 の返り値もエラーを示すために予約されていないので、エラーをチェックした
102 いアプリケーションは呼び出しを行う前に \fIerrno\fP を 0 に初期化し、呼び出
103 しの後で \fIerrno\fP をチェックすべき点に注意すること。
104
105 XSI 準拠の \fBstrerror_r\fP() 関数は成功すると 0 を返す。エラーの場合には、
106 (glibc 2.13 以降では) (正の) エラー番号が返され、(バージョン 2.13 より前
107 の glibc では) \-1 が返され、 \fIerrno\fP にエラーを示す値がセットされる。
108 .SH エラー
109 .TP 
110 \fBEINVAL\fP
111 \fIerrnum\fP の値が有効なエラー番号ではない。
112 .TP 
113 \fBERANGE\fP
114 エラーコードを説明する文字列のために、充分な領域が確保できなかった。
115 .SH 属性
116 .SS "マルチスレッディング (pthreads(7) 参照)"
117 \fBstrerror\fP() 関数はスレッドセーフではない。
118 .LP
119 \fBstrerror_r\fP() 関数はスレッドセーフである。
120 .SH 準拠
121 \fBstrerror\fP()  は POSIX.1\-2001, C89, C99 で規定されている。 \fBstrerror_r\fP()  は
122 POSIX.1\-2001 で規定されている。
123
124 GNU 仕様の \fBstrerror_r\fP()  関数は非標準の拡張である。
125
126 .\" e.g., Solaris 8, HP-UX 11
127 .\" e.g., FreeBSD 5.4, Tru64 5.1B
128 POSIX.1\-2001 は、 \fBstrerror\fP() がエラーに遭遇した場合に \fIerrno\fP をセッ
129 トすることを認めているが、エラー発生時に関数の結果として どんな値を返す
130 べきかを規定してない。 あるシステムでは、 エラー番号が未知の場合、
131 \fBstrerror\fP() は NULL を返す。 他のシステムでは、 エラー番号が未知の場
132 合、 \fBstrerror\fP() は "Error nnn occurred" といった文字列を返し、
133 \fIerrno\fP に \fBEINVAL\fP をセットする。 C99 と POSIX.1\-2008 では、返り値が
134 NULL 以外になることが求められている。
135 .SH 関連項目
136 \fBerr\fP(3), \fBerrno\fP(3), \fBerror\fP(3), \fBperror\fP(3), \fBstrsignal\fP(3)
137 .SH この文書について
138 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
139 である。プロジェクトの説明とバグ報告に関する情報は
140 http://www.kernel.org/doc/man\-pages/ に書かれている。