OSDN Git Service

(split) LDP: draft snapshots from latest ja.po(s).
[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 .\" All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. All advertising materials mentioning features or use of this software
14 .\"    must display the following acknowledgement:
15 .\"     This product includes software developed by the University of
16 .\"     California, Berkeley and its contributors.
17 .\" 4. Neither the name of the University nor the names of its contributors
18 .\"    may be used to endorse or promote products derived from this software
19 .\"    without specific prior written permission.
20 .\"
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" SUCH DAMAGE.
32 .\"
33 .\"     @(#)readlink.2  6.8 (Berkeley) 3/10/91
34 .\"
35 .\" Modified Sat Jul 24 00:10:21 1993 by Rik Faith (faith@cs.unc.edu)
36 .\" Modified Tue Jul  9 23:55:17 1996 by aeb
37 .\" Modified Fri Jan 24 00:26:00 1997 by aeb
38 .\" 2011-09-20, Guillem Jover <guillem@hadrons.org>:
39 .\"     Added text on dynamically allocating buffer + example program
40 .\"
41 .\"*******************************************************************
42 .\"
43 .\" This file was generated with po4a. Translate the source file.
44 .\"
45 .\"*******************************************************************
46 .TH READLINK 2 2011\-09\-20 Linux "Linux Programmer's Manual"
47 .SH 名前
48 readlink \- シンボリックリンクの値を読む
49 .SH 書式
50 \fB#include <unistd.h>\fP
51 .sp
52 \fBssize_t readlink(const char *\fP\fIpath\fP\fB, char *\fP\fIbuf\fP\fB, size_t
53 \fP\fIbufsiz\fP\fB);\fP
54 .sp
55 .in -4n
56 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
57 .in
58 .sp
59 .ad l
60 \fBreadlink\fP():
61 .RS 4
62 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED || _POSIX_C_SOURCE\ >=\ 200112L
63 .RE
64 .ad b
65 .SH 説明
66 \fBreadlink\fP()  は \fIpath\fP で与えられたシンボリックリンクの内容を \fIbuf\fP バッファーへ格納する、 \fIbuf\fP のサイズは
67 \fIbufsiz\fP である。 \fBreadlink\fP()  は NULL バイトを \fIbuf\fP に追加しない。
68 その内容全てを格納するのにバッファーが小さ過ぎる場合は、 (\fIbufsiz\fP バイトの長さに) 内容を切り詰める。
69 .SH 返り値
70 成功すると、 \fBreadlink\fP()  は \fIbuf\fP に格納されたバイト数を返す。 エラーの場合、\-1 を返し、 \fIerrno\fP
71 にエラーを示す値を設定する。
72 .SH エラー
73 .TP 
74 \fBEACCES\fP
75 パスのディレクトリ部分に検索許可が与えられていない (\fBpath_resolution\fP(7)  も参照すること)。
76 .TP 
77 \fBEFAULT\fP
78 \fIbuf\fP がプロセスに割り当てられたアドレス空間の外を指している。
79 .TP 
80 \fBEINVAL\fP
81 .\" At the glibc level, bufsiz is unsigned, so this error can only occur
82 .\" if bufsiz==0.  However, the in the kernel syscall, bufsiz is signed,
83 .\" and this error can also occur if bufsiz < 0.
84 .\" See: http://thread.gmane.org/gmane.linux.man/380
85 .\" Subject: [patch 0/3] [RFC] kernel/glibc mismatch of "readlink" syscall?
86 \fIbufsiz\fP が正でない。
87 .TP 
88 \fBEINVAL\fP
89 指定したファイルがシンボリックリンクでない。
90 .TP 
91 \fBEIO\fP
92 ファイルシステムの読み込み中に I/O エラーが起こった。
93 .TP 
94 \fBELOOP\fP
95 パス名にシンボリックリンクが多すぎる。
96 .TP 
97 \fBENAMETOOLONG\fP
98 パス名かパス名の一部分が長過ぎる。
99 .TP 
100 \fBENOENT\fP
101 その名前のファイルが存在しない。
102 .TP 
103 \fBENOMEM\fP
104 十分なカーネルメモリーがない。
105 .TP 
106 \fBENOTDIR\fP
107 パスのディレクトリ部分がディレクトリでない。
108 .SH 準拠
109 4.4BSD (\fBreadlink\fP()  は 4.2BSD で初めて登場した), POSIX.1\-2001.
110 .SH 注意
111 バージョン 2.4 以前の glibc (バージョン 2.4 を含む) では、 \fBreadlink\fP()  の返り値の型は \fIint\fP
112 で宣言されていた。現在では、返り値の型は \fIssize_t\fP である (返り値 \fIssize_t\fP は POSIX.1\-2001 で (新たに)
113 必須となった)。
114
115 静的な大きさのバッファを使うと、シンボリックリンクの内容を
116 格納するのに十分な領域がない場合がある。
117 バッファに必要なサイズは、そのシンボリックリンクに対して \fBlstat\fP(2)
118 の呼び出しで返される \fIstat.st_size\fP の値から取得できる。
119 ただし、 \fBreadlink\fP() が書き込んだバイト数をチェックして、
120 シンボリックリンクのサイズが \fBlstat\fP(2) と \fBreadlink\fP() の呼び出し
121 の間で増えていないことを確認すべきである。
122 \fBreadlink\fP() 用のバッファを動的に割り当てる方法でも、
123 バッファサイズとして \fIPATH_MAX\fP を使用する場合に共通する移植性の
124 問題を解決することができる。なぜなら、POSIX では、
125 システムがそのような上限値を定義していない場合には、
126 \fIPATH_MAX\fP が定義されることが保証されていないからである。
127 .SH 例
128 以下のプログラムは、 \fBreadlink\fP() が必要とするバッファを、
129 \fBlstat\fP() が提供する情報に基づいて動的に割り当てる。
130 また、両方の呼び出し間で競合条件がないことを保証している。
131 .nf
132
133 #include <sys/types.h>
134 #include <sys/stat.h>
135 #include <stdio.h>
136 #include <stdlib.h>
137 #include <unistd.h>
138
139 int
140 main(int argc, char *argv[])
141 {
142     struct stat sb;
143     char *linkname;
144     ssize_t r;
145
146     if (argc != 2) {
147         fprintf(stderr, "Usage: %s <pathname>\en", argv[0]);
148         exit(EXIT_FAILURE);
149     }
150
151     if (lstat(argv[1], &sb) == \-1) {
152         perror("lstat");
153         exit(EXIT_FAILURE);
154     }
155
156     linkname = malloc(sb.st_size + 1);
157     if (linkname == NULL) {
158         fprintf(stderr, "insufficient memory\en");
159         exit(EXIT_FAILURE);
160     }
161
162     r = readlink(argv[1], linkname, sb.st_size + 1);
163
164     if (r < 0) {
165         perror("lstat");
166         exit(EXIT_FAILURE);
167     }
168
169     if (r > sb.st_size) {
170         fprintf(stderr, "symlink increased in size "
171                         "between lstat() and readlink()\en");
172         exit(EXIT_FAILURE);
173     }
174
175     linkname[sb.st_size] = \(aq\e0\(aq;
176
177     printf("\(aq%s\(aq points to \(aq%s\(aq\en", argv[1], linkname);
178
179     exit(EXIT_SUCCESS);
180 }
181 .fi
182 .SH 関連項目
183 \fBreadlink\fP(1), \fBlstat\fP(2), \fBreadlinkat\fP(2), \fBstat\fP(2), \fBsymlink\fP(2),
184 \fBpath_resolution\fP(7), \fBsymlink\fP(7)
185 .SH この文書について
186 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.41 の一部
187 である。プロジェクトの説明とバグ報告に関する情報は
188 http://www.kernel.org/doc/man\-pages/ に書かれている。