OSDN Git Service

(split) LDP v3.30, v3.31 の定型的な変更内容を反映。
[linuxjm/LDP_man-pages.git] / release / 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 .SH Ì¾Á°
32 basename, dirname \- ¥Ñ¥¹Ì¾¤ò²òÀϤ·¤Æ³ÆÉôʬ¤ò¼è¤ê½Ð¤¹
33 .SH ½ñ¼°
34 .nf
35 .B #include <libgen.h>
36 .sp
37 .BI "char *dirname(char *" path );
38
39 .BI "char *basename(char *" path );
40 .fi
41 .SH ÀâÌÀ
42 ·Ù¹ð:
43 .BR basename ()
44 ¤Ë¤Ï°Û¤Ê¤ë¥Ð¡¼¥¸¥ç¥ó¤¬ 2¤Ä¸ºß¤¹¤ë¡£²¼µ­¤Î¡ÖÃí°Õ¡×¤ÎÀá¤ò»²¾È¤Î¤³¤È¡£
45 .LP
46 .BR dirname ()
47 ¤È
48 .BR basename ()
49 ¤Ï¡¢NULL ¤Ç½ªÃ¼¤µ¤ì¤¿¥Ñ¥¹Ì¾¤Îʸ»úÎó¤ò¡¢
50 ¥Ç¥£¥ì¥¯¥È¥êÉôʬ¡¦¥Õ¥¡¥¤¥ë̾Éôʬ¤Ëʬ³ä¤¹¤ë¡£
51 Ä̾ï¤Ï¡¢
52 .BR dirname ()
53 ¤ÏºÇ¸å¤Î \(aq/\(aq ¤Þ¤Ç¤ÎÉôʬ (ºÇ¸å¤Î \(aq/\(aq ¤Ï´Þ¤Þ¤Ê¤¤) ¤òÊÖ¤·¡¢
54 .BR basename ()
55 ¤ÏºÇ¸å¤Î \(aq/\(aq °Ê¹ß¤ÎÉôʬ¤òÊÖ¤¹¡£
56 ʸ»úÎó¤ÎËöÈø¤Ë¤Ä¤¤¤¿ \(aq/\(aq Ê¸»ú¤Ï¡¢¥Ñ¥¹Ì¾¤Î°ìÉô¤È¤Ï¤ß¤Ê¤µ¤ì¤Ê¤¤¡£
57 .PP
58 .I path
59 ¤Ë '/' Ê¸»ú¤¬¤Ê¤¤¾ì¹ç¤Ï¡¢
60 .BR dirname ()
61 ¤Ïʸ»úÎó "." ¤òÊÖ¤·¡¢
62 .BR basename ()
63 ¤Ï
64 .I path
65 ¤ÈƱ¤¸ÆâÍƤòÊÖ¤¹¡£
66 .I path
67 ¤¬Ê¸»úÎó "/" ¤ËÅù¤·¤¤¾ì¹ç¤Ï¡¢
68 .BR dirname ()
69 ¤â
70 .BR basename ()
71 ¤âʸ»úÎó "/" ¤òÊÖ¤¹¡£
72 .I path
73 ¤¬ NULL ¥Ý¥¤¥ó¥¿¤À¤Ã¤¿¤ê¡¢¶õ¤Îʸ»úÎó¤ò»Ø¤·¤Æ¤¤¤¿¾ì¹ç¤Ï¡¢
74 .BR dirname ()
75 ¤â
76 .BR basename ()
77 ¤âʸ»úÎó "." ¤òÊÖ¤¹¡£
78 .PP
79 .BR dirname ()
80 ¤ÎÊÖ¤·¤¿Ê¸»úÎó¡¢ "/"¡¢
81 .BR basename ()
82 ¤ÎÊÖ¤·¤¿Ê¸»úÎó¡¢
83 ¤ò½ç¤Ë·ë¹ç¤¹¤ë¤È¡¢´°Á´¤Ê¥Ñ¥¹Ì¾¤¬ÆÀ¤é¤ì¤ë¡£
84 .PP
85 .BR dirname ()
86 ¤È
87 .BR basename ()
88 ¤Ï¡¢¤¤¤º¤ì¤â
89 .I path
90 ¤ÎÆâÍƤòÊѹ¹¤¹¤ë¤³¤È¤¬¤¢¤ë¡£
91 ¤·¤¿¤¬¤Ã¤Æ¡¢¤³¤ì¤é¤Î´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë¤Ï
92 ¥³¥Ô¡¼¤òÅϤ¹¤Î¤¬Ë¾¤Þ¤·¤¤¡£
93 .PP
94 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢ÀÅŪ¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¤³¤È¤¬¤¢¤ê¡¢
95 ¤³¤ì¤é¤ÎÎΰè¤Ï¸å¤Î´Ø¿ô¸Æ¤Ó½Ð¤·¤Ç¾å½ñ¤­¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
96 ¤Þ¤¿¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï
97 .I path
98 ¤Î°ìÉôʬ¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¤³¤È¤â¤¢¤ë¡£¤½¤Î¤¿¤á¡¢
99 .I path
100 ¤Ç»²¾È¤µ¤ì¤ëʸ»úÎó¤Ï¡¢´Ø¿ô¤¬ÊÖ¤¹¥Ý¥¤¥ó¥¿¤¬ÉÔÍפˤʤë¤Þ¤Ç¤Ï
101 Êѹ¹¤·¤¿¤ê free ¤·¤¿¤ê¤¹¤Ù¤­¤Ç¤Ï¤Ê¤¤¡£
102 .PP
103 °Ê²¼¤Î°ìÏ¢¤ÎÎã (SUSv2 ¤«¤é°úÍÑ) ¤Ï¡¢
104 ¤¤¤í¤¤¤í¤Ê path ¤ËÂФ·¤Æ
105 .BR dirname ()
106 ¤È
107 .BR basename ()
108 ¤¬ÊÖ¤¹Ê¸»úÎó¤òɽ¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
109 .sp
110 .nf
111 .B "path         dirname    basename"
112 "/usr/lib"    "/usr"    "lib"
113 "/usr/"       "/"       "usr"
114 "usr"         "."       "usr"
115 "/"           "/"       "/"
116 "."           "."       "."
117 ".."          "."       ".."
118 .fi
119 .SH ÊÖ¤êÃÍ
120 .BR dirname ()
121 ¤È
122 .BR basename ()
123 ¤Ï¡¢¤¤¤º¤ì¤â NULL ¤Ç½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
124 (¤³¤ì¤é¤Î¥Ý¥¤¥ó¥¿¤ò
125 .BR free (3)
126 ¤ËÅϤµ¤Ê¤¤¤³¤È¡£)
127 .SH ½àµò
128 POSIX.1-2001.
129 .SH Ãí°Õ
130 .BR basename ()
131 ¤Ë¤Ï 2¼ïÎà¤Î°Û¤Ê¤ë¥Ð¡¼¥¸¥ç¥ó¤¬¤¢¤ë¡£
132 °ì¤Ä¤Ï¤¹¤Ç¤ËÀâÌÀ¤·¤¿ POSIX ¥Ð¡¼¥¸¥ç¥ó¤Ç¤¢¤ê¡¢
133 ¤â¤¦°ì¤Ä¤Ï GNU ¥Ð¡¼¥¸¥ç¥ó¤Ç¤¢¤ë¡£
134 GNU ¥Ð¡¼¥¸¥ç¥ó¤ò»ÈÍѤ¹¤ë¤Ë¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ë¡£
135 .br
136 .nf
137
138 .BR "    #define _GNU_SOURCE" "         /* feature_test_macros(7) »²¾È */"
139 .br
140 .B "    #include <string.h>"
141
142 .fi
143 GNU ¥Ð¡¼¥¸¥ç¥ó¤Ï°ú¤­¿ô¤òÊѹ¹¤¹¤ë¤³¤È¤Ï¤Ê¤¯¡¢
144 .I path
145 ¤ÎËöÈø¤¬ '/'¤Î¾ì¹ç¤Ï¶õ¤Îʸ»úÎó¤òÊÖ¤¹¡£
146 ÆäË
147 .I path
148 ¤¬ "/" ¤Î¾ì¹ç¤â¶õʸ»úÎó¤òÊÖ¤¹¡£
149 .BR dirname ()
150 ¤Ë¤Ï GNU ¥Ð¡¼¥¸¥ç¥ó¤Ï¤Ê¤¤¡£
151 .LP
152 glibc ¤Ç¤Ï¡¢
153 .I <libgen.h>
154 ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤È POSIX ¥Ð¡¼¥¸¥ç¥ó¤Î
155 .BR basename ()
156 ¤¬»ÈÍѤµ¤ì¡¢¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï GNU ¥Ð¡¼¥¸¥ç¥ó¤È¤Ê¤ë¡£
157 .SH ¥Ð¥°
158 glibc ¤Î POSIX ¥Ð¡¼¥¸¥ç¥ó¤Î¼ÂÁõ¤Ç¤Ï¡¢°ú¤­¿ô¤ÎÆâÍƤ¬Êѹ¹¤µ¤ì¡¢
159 °ú¤­¿ô¤Ë ("/usr/" ¤Ê¤É¤Î) Äê¿ôʸ»úÎó¤ò»ØÄꤵ¤ì¤ë¤È
160 ¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¥Õ¥©¡¼¥ë¥È¤òµ¯¤³¤¹¡£
161 ¥Ð¡¼¥¸¥ç¥ó 2.2.1 °ÊÁ°¤Î glibc ¤Ç¤Ï¡¢ glibc ¤Î
162 .BR dirname ()
163 ¤ÏËöÈø¤¬ \(aq/\(aq Ê¸»ú¤Ë¤Ê¤Ã¤Æ¤¤¤ë¥Ñ¥¹Ì¾¤òÀµ¤·¤¯°·¤¨¤º¡¢
164 °ú¤­¿ô¤¬ NULL ¤À¤È¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¥Õ¥©¡¼¥ë¥È¤òµ¯¤³¤·¤¿¡£
165 .SH Îã
166 .in +4n
167 .nf
168 char *dirc, *basec, *bname, *dname;
169 char *path = "/etc/passwd";
170
171 dirc = strdup(path);
172 basec = strdup(path);
173 dname = dirname(dirc);
174 bname = basename(basec);
175 printf("dirname=%s, basename=%s\\n", dname, bname);
176 .fi
177 .in
178 .SH ´ØÏ¢¹àÌÜ
179 .BR basename (1),
180 .BR dirname (1)