OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man3 / basename.3
1 .\" Copyright (c) 2000 by Michael Kerrisk (mtk.manpages@gmail.com)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\" License.
23 .\" Created, 14 Dec 2000 by Michael Kerrisk
24 .\"
25 .\" Japanese Version Copyright (c) 2001 NAKANO Takeo all rights reserved.
26 .\" Translated 2001-03-31, NAKANO Takeo <nakano@apm.seikei.ac.jp>
27 .\" Updated 2005-02-26, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
28 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
29 .\"
30 .TH BASENAME 3  2009-03-30 "GNU" "Linux Programmer's Manual"
31 .\"O .SH NAME
32 .\"O basename, dirname \- parse pathname components
33 .SH Ì¾Á°
34 basename, dirname \- ¥Ñ¥¹Ì¾¤ò²òÀϤ·¤Æ³ÆÉôʬ¤ò¼è¤ê½Ð¤¹
35 .\"O .SH SYNOPSIS
36 .SH ½ñ¼°
37 .nf
38 .B #include <libgen.h>
39 .sp
40 .BI "char *dirname(char *" path );
41
42 .BI "char *basename(char *" path );
43 .fi
44 .\"O .SH DESCRIPTION
45 .SH ÀâÌÀ
46 .\"O Warning: there are two different functions
47 .\"O .BR basename ()
48 .\"O - see below.
49 ·Ù¹ð:
50 .BR basename ()
51 ¤Ë¤Ï°Û¤Ê¤ë¥Ð¡¼¥¸¥ç¥ó¤¬ 2¤Ä¸ºß¤¹¤ë¡£²¼µ­¤Î¡ÖÃí°Õ¡×¤ÎÀá¤ò»²¾È¤Î¤³¤È¡£
52 .LP
53 .\"O The functions
54 .\"O .BR dirname ()
55 .\"O and
56 .\"O .BR basename ()
57 .\"O break a null-terminated pathname string into directory
58 .\"O and filename components.
59 .\"O In the usual case,
60 .\"O .BR dirname ()
61 .\"O returns the string up to, but not including, the final \(aq/\(aq, and
62 .\"O .BR basename ()
63 .\"O returns the component following the final \(aq/\(aq.
64 .\"O Trailing \(aq/\(aq characters are not counted as part of the pathname.
65 .BR dirname ()
66 ¤È
67 .BR basename ()
68 ¤Ï¡¢NULL ¤Ç½ªÃ¼¤µ¤ì¤¿¥Ñ¥¹Ì¾¤Îʸ»úÎó¤ò¡¢
69 ¥Ç¥£¥ì¥¯¥È¥êÉôʬ¡¦¥Õ¥¡¥¤¥ë̾Éôʬ¤Ëʬ³ä¤¹¤ë¡£
70 Ä̾ï¤Ï¡¢
71 .BR dirname ()
72 ¤ÏºÇ¸å¤Î \(aq/\(aq ¤Þ¤Ç¤ÎÉôʬ (ºÇ¸å¤Î \(aq/\(aq ¤Ï´Þ¤Þ¤Ê¤¤) ¤òÊÖ¤·¡¢
73 .BR basename ()
74 ¤ÏºÇ¸å¤Î \(aq/\(aq °Ê¹ß¤ÎÉôʬ¤òÊÖ¤¹¡£
75 ʸ»úÎó¤ÎËöÈø¤Ë¤Ä¤¤¤¿ \(aq/\(aq Ê¸»ú¤Ï¡¢¥Ñ¥¹Ì¾¤Î°ìÉô¤È¤Ï¤ß¤Ê¤µ¤ì¤Ê¤¤¡£
76 .PP
77 .\"O If
78 .\"O .I path
79 .\"O does not contain a slash,
80 .\"O .BR dirname ()
81 .\"O returns the string "." while
82 .\"O .BR basename ()
83 .\"O returns a copy of
84 .\"O .IR path .
85 .\"O If
86 .\"O .I path
87 .\"O is the string "/", then both
88 .\"O .BR dirname ()
89 .\"O and
90 .\"O .BR basename ()
91 .\"O return the string "/".
92 .\"O If
93 .\"O .I path
94 .\"O is a NULL pointer or points to an empty string, then both
95 .\"O .BR dirname ()
96 .\"O and
97 .\"O .BR basename ()
98 .\"O return the string ".".
99 .I path
100 ¤Ë '/' Ê¸»ú¤¬¤Ê¤¤¾ì¹ç¤Ï¡¢
101 .BR dirname ()
102 ¤Ïʸ»úÎó "." ¤òÊÖ¤·¡¢
103 .BR basename ()
104 ¤Ï
105 .I path
106 ¤ÈƱ¤¸ÆâÍƤòÊÖ¤¹¡£
107 .I path
108 ¤¬Ê¸»úÎó "/" ¤ËÅù¤·¤¤¾ì¹ç¤Ï¡¢
109 .BR dirname ()
110 ¤â
111 .BR basename ()
112 ¤âʸ»úÎó "/" ¤òÊÖ¤¹¡£
113 .I path
114 ¤¬ NULL ¥Ý¥¤¥ó¥¿¤À¤Ã¤¿¤ê¡¢¶õ¤Îʸ»úÎó¤ò»Ø¤·¤Æ¤¤¤¿¾ì¹ç¤Ï¡¢
115 .BR dirname ()
116 ¤â
117 .BR basename ()
118 ¤âʸ»úÎó "." ¤òÊÖ¤¹¡£
119 .PP
120 .\"O Concatenating the string returned by
121 .\"O .BR dirname (),
122 .\"O a "/", and the string returned by
123 .\"O .BR basename ()
124 .\"O yields a complete pathname.
125 .BR dirname ()
126 ¤ÎÊÖ¤·¤¿Ê¸»úÎó¡¢ "/"¡¢
127 .BR basename ()
128 ¤ÎÊÖ¤·¤¿Ê¸»úÎó¡¢
129 ¤ò½ç¤Ë·ë¹ç¤¹¤ë¤È¡¢´°Á´¤Ê¥Ñ¥¹Ì¾¤¬ÆÀ¤é¤ì¤ë¡£
130 .PP
131 .\"O Both
132 .\"O .BR dirname ()
133 .\"O and
134 .\"O .BR basename ()
135 .\"O may modify the contents of
136 .\"O .IR path ,
137 .\"O so it may be desirable to pass a copy when calling one of
138 .\"O these functions.
139 .BR dirname ()
140 ¤È
141 .BR basename ()
142 ¤Ï¡¢¤¤¤º¤ì¤â
143 .I path
144 ¤ÎÆâÍƤòÊѹ¹¤¹¤ë¤³¤È¤¬¤¢¤ë¡£
145 ¤·¤¿¤¬¤Ã¤Æ¡¢¤³¤ì¤é¤Î´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë¤Ï
146 ¥³¥Ô¡¼¤òÅϤ¹¤Î¤¬Ë¾¤Þ¤·¤¤¡£
147 .PP
148 .\"O These functions may return pointers to statically allocated memory
149 .\"O which may be overwritten by subsequent calls.
150 .\"O Alternatively, they may return a pointer to some part of
151 .\"O .IR path ,
152 .\"O so that the string referred to by
153 .\"O .I path
154 .\"O should not be modified or freed until the pointer returned by
155 .\"O the function is no longer required.
156 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢ÀÅŪ¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¤³¤È¤¬¤¢¤ê¡¢
157 ¤³¤ì¤é¤ÎÎΰè¤Ï¸å¤Î´Ø¿ô¸Æ¤Ó½Ð¤·¤Ç¾å½ñ¤­¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
158 ¤Þ¤¿¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï
159 .I path
160 ¤Î°ìÉôʬ¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¤³¤È¤â¤¢¤ë¡£¤½¤Î¤¿¤á¡¢
161 .I path
162 ¤Ç»²¾È¤µ¤ì¤ëʸ»úÎó¤Ï¡¢´Ø¿ô¤¬ÊÖ¤¹¥Ý¥¤¥ó¥¿¤¬ÉÔÍפˤʤë¤Þ¤Ç¤Ï
163 Êѹ¹¤·¤¿¤ê free ¤·¤¿¤ê¤¹¤Ù¤­¤Ç¤Ï¤Ê¤¤¡£
164 .PP
165 .\"O The following list of examples (taken from SUSv2)
166 .\"O shows the strings returned by
167 .\"O .BR dirname ()
168 .\"O and
169 .\"O .BR basename ()
170 .\"O for different paths:
171 °Ê²¼¤Î°ìÏ¢¤ÎÎã (SUSv2 ¤«¤é°úÍÑ) ¤Ï¡¢
172 ¤¤¤í¤¤¤í¤Ê path ¤ËÂФ·¤Æ
173 .BR dirname ()
174 ¤È
175 .BR basename ()
176 ¤¬ÊÖ¤¹Ê¸»úÎó¤òɽ¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
177 .sp
178 .nf
179 .B "path         dirname    basename"
180 "/usr/lib"    "/usr"    "lib"
181 "/usr/"       "/"       "usr"
182 "usr"         "."       "usr"
183 "/"           "/"       "/"
184 "."           "."       "."
185 ".."          "."       ".."
186 .fi
187 .\"O .SH "RETURN VALUE"
188 .SH ÊÖ¤êÃÍ
189 .\"O Both
190 .\"O .BR dirname ()
191 .\"O and
192 .\"O .BR basename ()
193 .\"O return pointers to null-terminated strings.
194 .\"O (Do not pass these pointers to
195 .\"O .BR free (3).)
196 .BR dirname ()
197 ¤È
198 .BR basename ()
199 ¤Ï¡¢¤¤¤º¤ì¤â NULL ¤Ç½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
200 (¤³¤ì¤é¤Î¥Ý¥¤¥ó¥¿¤ò
201 .BR free (3)
202 ¤ËÅϤµ¤Ê¤¤¤³¤È¡£)
203 .\"O .SH "CONFORMING TO"
204 .SH ½àµò
205 POSIX.1-2001.
206 .\"O .SH NOTES
207 .SH Ãí°Õ
208 .\"O There are two different versions of
209 .\"O .BR basename ()
210 .\"O - the POSIX version described above, and the GNU version, which one gets
211 .\"O after
212 .BR basename ()
213 ¤Ë¤Ï 2¼ïÎà¤Î°Û¤Ê¤ë¥Ð¡¼¥¸¥ç¥ó¤¬¤¢¤ë¡£
214 °ì¤Ä¤Ï¤¹¤Ç¤ËÀâÌÀ¤·¤¿ POSIX ¥Ð¡¼¥¸¥ç¥ó¤Ç¤¢¤ê¡¢
215 ¤â¤¦°ì¤Ä¤Ï GNU ¥Ð¡¼¥¸¥ç¥ó¤Ç¤¢¤ë¡£
216 GNU ¥Ð¡¼¥¸¥ç¥ó¤ò»ÈÍѤ¹¤ë¤Ë¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ë¡£
217 .br
218 .nf
219
220 .B "    #define _GNU_SOURCE"
221 .br
222 .B "    #include <string.h>"
223
224 .fi
225 .\"O The GNU version never modifies its argument, and returns the
226 .\"O empty string when
227 .\"O .I path
228 .\"O has a trailing slash, and in particular also when it is "/".
229 .\"O There is no GNU version of
230 .\"O .BR dirname ().
231 GNU ¥Ð¡¼¥¸¥ç¥ó¤Ï°ú¤­¿ô¤òÊѹ¹¤¹¤ë¤³¤È¤Ï¤Ê¤¯¡¢
232 .I path
233 ¤ÎËöÈø¤¬ '/'¤Î¾ì¹ç¤Ï¶õ¤Îʸ»úÎó¤òÊÖ¤¹¡£
234 ÆäË
235 .I path
236 ¤¬ "/" ¤Î¾ì¹ç¤â¶õʸ»úÎó¤òÊÖ¤¹¡£
237 .BR dirname ()
238 ¤Ë¤Ï GNU ¥Ð¡¼¥¸¥ç¥ó¤Ï¤Ê¤¤¡£
239 .LP
240 .\"O With glibc, one gets the POSIX version of
241 .\"O .BR basename ()
242 .\"O when
243 .\"O .I <libgen.h>
244 .\"O is included, and the GNU version otherwise.
245 glibc ¤Ç¤Ï¡¢
246 .I <libgen.h>
247 ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤È POSIX ¥Ð¡¼¥¸¥ç¥ó¤Î
248 .BR basename ()
249 ¤¬»ÈÍѤµ¤ì¡¢¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï GNU ¥Ð¡¼¥¸¥ç¥ó¤È¤Ê¤ë¡£
250 .\"O .SH BUGS
251 .SH ¥Ð¥°
252 .\"O In the glibc implementation of the POSIX versions of these functions
253 .\"O they modify their argument, and segfault when called with a static string
254 .\"O like "/usr/".
255 glibc ¤Î POSIX ¥Ð¡¼¥¸¥ç¥ó¤Î¼ÂÁõ¤Ç¤Ï¡¢°ú¤­¿ô¤ÎÆâÍƤ¬Êѹ¹¤µ¤ì¡¢
256 °ú¤­¿ô¤Ë ("/usr/" ¤Ê¤É¤Î) Äê¿ôʸ»úÎó¤ò»ØÄꤵ¤ì¤ë¤È
257 ¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¥Õ¥©¡¼¥ë¥È¤òµ¯¤³¤¹¡£
258 .\"O Before glibc 2.2.1, the glibc version of
259 .\"O .BR dirname ()
260 .\"O did not correctly handle pathnames with trailing \(aq/\(aq characters,
261 .\"O and generated a segfault if given a NULL argument.
262 ¥Ð¡¼¥¸¥ç¥ó 2.2.1 °ÊÁ°¤Î glibc ¤Ç¤Ï¡¢ glibc ¤Î
263 .BR dirname ()
264 ¤ÏËöÈø¤¬ \(aq/\(aq Ê¸»ú¤Ë¤Ê¤Ã¤Æ¤¤¤ë¥Ñ¥¹Ì¾¤òÀµ¤·¤¯°·¤¨¤º¡¢
265 °ú¤­¿ô¤¬ NULL ¤À¤È¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¥Õ¥©¡¼¥ë¥È¤òµ¯¤³¤·¤¿¡£
266 .\"O .SH EXAMPLE
267 .SH Îã
268 .in +4n
269 .nf
270 char *dirc, *basec, *bname, *dname;
271 char *path = "/etc/passwd";
272
273 dirc = strdup(path);
274 basec = strdup(path);
275 dname = dirname(dirc);
276 bname = basename(basec);
277 printf("dirname=%s, basename=%s\\n", dname, bname);
278 .fi
279 .in
280 .\"O .SH "SEE ALSO"
281 .SH ´ØÏ¢¹àÌÜ
282 .BR basename (1),
283 .BR dirname (1),
284 .BR feature_test_macros (7)