OSDN Git Service

Update drafts based on the previous PO changes
[linuxjm/LDP_man-pages.git] / draft / man2 / readlink.2
1 .\" Copyright (c) 1983, 1991 The Regents of the University of California.
2 .\" And Copyright (C) 2011 Guillem Jover <guillem@hadrons.org>
3 .\" And Copyright (C) 2006, 2014 Michael Kerrisk
4 .\" All rights reserved.
5 .\"
6 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\" %%%LICENSE_END
35 .\"
36 .\"     @(#)readlink.2  6.8 (Berkeley) 3/10/91
37 .\"
38 .\" Modified Sat Jul 24 00:10:21 1993 by Rik Faith (faith@cs.unc.edu)
39 .\" Modified Tue Jul  9 23:55:17 1996 by aeb
40 .\" Modified Fri Jan 24 00:26:00 1997 by aeb
41 .\" 2011-09-20, Guillem Jover <guillem@hadrons.org>:
42 .\"     Added text on dynamically allocating buffer + example program
43 .\"
44 .\"*******************************************************************
45 .\"
46 .\" This file was generated with po4a. Translate the source file.
47 .\"
48 .\"*******************************************************************
49 .\"
50 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
51 .\"         all rights reserved.
52 .\" Translated 1997-12-12, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
53 .\" Updated 2005-02-10, Yuichi SATO <ysato444@yahoo.co.jp>
54 .\" Updated 2006-07-19, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v2.36
55 .\" Updated 2008-08-06, Akihiro MOTOKI, LDP v3.05
56 .\" Updated 2012-05-08, Akihiro MOTOKI <amotoki@gmail.com>
57 .\"
58 .TH READLINK 2 2014\-10\-15 Linux "Linux Programmer's Manual"
59 .SH 名前
60 readlink, readlinkat \- シンボリックリンクの値を読む
61 .SH 書式
62 .nf
63 \fB#include <unistd.h>\fP
64 .sp
65 \fBssize_t readlink(const char *\fP\fIpathname\fP\fB, char *\fP\fIbuf\fP\fB, size_t \fP\fIbufsiz\fP\fB);\fP
66 .sp
67 \fB#include <fcntl.h>           \fP/* AT_* 定数の定義 */
68 \fB#include <unistd.h>\fP
69 .sp
70 \fBssize_t readlinkat(int \fP\fIdirfd\fP\fB, const char *\fP\fIpathname\fP\fB,\fP
71 \fB                   char *\fP\fIbuf\fP\fB, size_t \fP\fIbufsiz\fP\fB);\fP
72 .sp
73 .fi
74 .in -4n
75 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
76 .in
77 .sp
78 .ad l
79 \fBreadlink\fP():
80 .RS 4
81 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED || _POSIX_C_SOURCE\ >=\ 200112L
82 .RE
83 .sp
84 \fBreadlinkat\fP():
85 .PD 0
86 .ad l
87 .RS 4
88 .TP  4
89 glibc 2.10 以降:
90 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
91 .TP 
92 glibc 2.10 より前:
93 _ATFILE_SOURCE
94 .RE
95 .ad b
96 .PD
97 .SH 説明
98 \fBreadlink\fP()  は \fIpathname\fP で与えられたシンボリックリンクの内容を \fIbuf\fP バッファーへ格納する、 \fIbuf\fP
99 のサイズは \fIbufsiz\fP である。 \fBreadlink\fP()  はヌルバイトを \fIbuf\fP に追加しない。
100 その内容全てを格納するのにバッファーが小さ過ぎる場合は、 (\fIbufsiz\fP バイトの長さに) 内容を切り詰める。
101 .SS readlinkat()
102 \fBreadlinkat\fP() システムコールは \fBreadlink\fP() と全く同様に動作するが、以下で説明する点が異なる。
103
104 \fIpathname\fP で指定されたパス名が相対パスの場合、このパス名はファイルディスクリプター \fIdirfd\fP
105 が参照するディレクトリに対する相対パスと解釈される (\fBreadlink\fP()
106 に相対パス名を渡した場合のように、呼び出したプロセスのカレントワーキングディレクトリに対する相対パスではない)。
107
108 \fIpathname\fP で指定されたパス名が相対パスで、 \fIdirfd\fP が特別な値 \fBAT_FDCWD\fP の場合、 (\fBreadlink\fP()
109 と同様に) \fIpathname\fP は呼び出したプロセスのカレントワーキングディレクトリに対する相対パスと解釈される。
110
111 \fIpathname\fP で指定されたパス名が絶対パスの場合、 \fIdirfd\fP は無視される。
112
113 .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
114 Since Linux 2.6.39, \fIpathname\fP can be an empty string, in which case the
115 call operates on the symbolic link referred to by \fIdirfd\fP (which should
116 have have been obtained using \fBopen\fP(2)  with the \fBO_PATH\fP and
117 \fBO_NOFOLLOW\fP flags).
118 .PP
119 \fBreadlinkat\fP() の必要性についての説明については \fBopenat\fP(2) を参照。
120 .SH 返り値
121 成功すると、これらのシステムコールは \fIbuf\fP に格納されたバイト数を返す。 エラーの場合、\-1 を返し、 \fIerrno\fP
122 にエラーを示す値を設定する。
123 .SH エラー
124 .TP 
125 \fBEACCES\fP
126 パスのディレクトリ部分に検索許可が与えられていない (\fBpath_resolution\fP(7)  も参照すること)。
127 .TP 
128 \fBEFAULT\fP
129 \fIbuf\fP がプロセスに割り当てられたアドレス空間の外を指している。
130 .TP 
131 \fBEINVAL\fP
132 .\" At the glibc level, bufsiz is unsigned, so this error can only occur
133 .\" if bufsiz==0.  However, the in the kernel syscall, bufsiz is signed,
134 .\" and this error can also occur if bufsiz < 0.
135 .\" See: http://thread.gmane.org/gmane.linux.man/380
136 .\" Subject: [patch 0/3] [RFC] kernel/glibc mismatch of "readlink" syscall?
137 \fIbufsiz\fP が正でない。
138 .TP 
139 \fBEINVAL\fP
140 指定したファイルがシンボリックリンクでない。
141 .TP 
142 \fBEIO\fP
143 ファイルシステムの読み込み中に I/O エラーが起こった。
144 .TP 
145 \fBELOOP\fP
146 パス名にシンボリックリンクが多すぎる。
147 .TP 
148 \fBENAMETOOLONG\fP
149 パス名かパス名の一部分が長過ぎる。
150 .TP 
151 \fBENOENT\fP
152 その名前のファイルが存在しない。
153 .TP 
154 \fBENOMEM\fP
155 十分なカーネルメモリーがない。
156 .TP 
157 \fBENOTDIR\fP
158 パスのディレクトリ部分がディレクトリでない。
159 .PP
160 \fBreadlinkat\fP() では以下のエラーも発生する。
161 .TP 
162 \fBEBADF\fP
163 \fIdirfd\fP が有効なファイルディスクリプタではない。
164 .TP 
165 \fBENOTDIR\fP
166 \fIpathname\fP が相対パスで、 \fIdirfd\fP がディレクトリ以外のファイルを参照しているファイルディスクリプタである。
167 .SH バージョン
168 \fBreadlinkat\fP()  はカーネル 2.6.16 で Linux に追加された。 ライブラリによるサポートはバージョン 2.4 で glibc
169 に追加された。
170 .SH 準拠
171 4.4BSD (\fBreadlink\fP()  は 4.2BSD で初めて登場した), POSIX.1\-2001, POSIX.1\-2008.
172
173 \fBreadlinkat\fP(): POSIX.1\-2008.
174 .SH 注意
175 バージョン 2.4 以前の glibc (バージョン 2.4 を含む) では、 \fBreadlink\fP()  の返り値の型は \fIint\fP
176 で宣言されていた。現在では、返り値の型は \fIssize_t\fP である (返り値 \fIssize_t\fP は POSIX.1\-2001 で (新たに)
177 必須となった)。
178
179 静的な大きさのバッファを使うと、 シンボリックリンクの内容を格納するのに十分な領域がない場合がある。 バッファに必要なサイズは、
180 そのシンボリックリンクに対して \fBlstat\fP(2) の呼び出しで返される \fIstat.st_size\fP の値から取得できる。 ただし、
181 \fBreadlink\fP() や \fBreadlinkat\fP() が書き込んだバイト数をチェックして、
182 シンボリックリンクのサイズが二つの呼び出しの間で増えていないことを確認すべきである。 \fBreadlink\fP() や \fBreadlinkat\fP()
183 用のバッファを動的に割り当てる方法でも、 バッファサイズとして \fIPATH_MAX\fP を使用する場合に共通する移植性の問題を解決することができる。
184 なぜなら、POSIX では、 システムがそのような上限値を定義していない場合には、 \fIPATH_MAX\fP
185 が定義されることが保証されていないからである。
186 .SS "glibc での注意"
187 On older kernels where \fBreadlinkat\fP()  is unavailable, the glibc wrapper
188 function falls back to the use of \fBreadlink\fP().  When \fIpathname\fP is a
189 relative pathname, glibc constructs a pathname based on the symbolic link in
190 \fI/proc/self/fd\fP that corresponds to the \fIdirfd\fP argument.
191 .SH 例
192 以下のプログラムは、 \fBreadlink\fP() が必要とするバッファを、
193 \fBlstat\fP() が提供する情報に基づいて動的に割り当てる。
194 また、両方の呼び出し間で競合条件がないことを保証している。
195 .nf
196
197 #include <sys/types.h>
198 #include <sys/stat.h>
199 #include <stdio.h>
200 #include <stdlib.h>
201 #include <unistd.h>
202
203 int
204 main(int argc, char *argv[])
205 {
206     struct stat sb;
207     char *linkname;
208     ssize_t r;
209
210     if (argc != 2) {
211         fprintf(stderr, "Usage: %s <pathname>\en", argv[0]);
212         exit(EXIT_FAILURE);
213     }
214
215     if (lstat(argv[1], &sb) == \-1) {
216         perror("lstat");
217         exit(EXIT_FAILURE);
218     }
219
220     linkname = malloc(sb.st_size + 1);
221     if (linkname == NULL) {
222         fprintf(stderr, "insufficient memory\en");
223         exit(EXIT_FAILURE);
224     }
225
226     r = readlink(argv[1], linkname, sb.st_size + 1);
227
228     if (r == \-1) {
229         perror("readlink");
230         exit(EXIT_FAILURE);
231     }
232
233     if (r > sb.st_size) {
234         fprintf(stderr, "symlink increased in size "
235                         "between lstat() and readlink()\en");
236         exit(EXIT_FAILURE);
237     }
238
239     linkname[r] = \(aq\e0\(aq;
240
241     printf("\(aq%s\(aq points to \(aq%s\(aq\en", argv[1], linkname);
242
243     free(linkname);
244
245     exit(EXIT_SUCCESS);
246 }
247 .fi
248 .SH 関連項目
249 \fBreadlink\fP(1), \fBlstat\fP(2), \fBstat\fP(2), \fBsymlink\fP(2), \fBrealpath\fP(3),
250 \fBpath_resolution\fP(7), \fBsymlink\fP(7)
251 .SH この文書について
252 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.76 の一部
253 である。プロジェクトの説明とバグ報告に関する情報は
254 http://www.kernel.org/doc/man\-pages/ に書かれている。