1 .\" Copyright (c) 2000 by Michael Kerrisk (mtk.manpages@gmail.com)
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.
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.
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
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" Created, 14 Dec 2000 by Michael Kerrisk
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
30 .TH BASENAME 3 2009-03-30 "GNU" "Linux Programmer's Manual"
32 basename, dirname \- ¥Ñ¥¹Ì¾¤ò²òÀϤ·¤Æ³ÆÉôʬ¤ò¼è¤ê½Ð¤¹
35 .B #include <libgen.h>
37 .BI "char *dirname(char *" path );
39 .BI "char *basename(char *" path );
44 ¤Ë¤Ï°Û¤Ê¤ë¥Ð¡¼¥¸¥ç¥ó¤¬ 2¤Ä¸ºß¤¹¤ë¡£²¼µ¤Î¡ÖÃí°Õ¡×¤ÎÀá¤ò»²¾È¤Î¤³¤È¡£
49 ¤Ï¡¢NULL ¤Ç½ªÃ¼¤µ¤ì¤¿¥Ñ¥¹Ì¾¤Îʸ»úÎó¤ò¡¢
50 ¥Ç¥£¥ì¥¯¥È¥êÉôʬ¡¦¥Õ¥¡¥¤¥ë̾Éôʬ¤Ëʬ³ä¤¹¤ë¡£
53 ¤ÏºÇ¸å¤Î \(aq/\(aq ¤Þ¤Ç¤ÎÉôʬ (ºÇ¸å¤Î \(aq/\(aq ¤Ï´Þ¤Þ¤Ê¤¤) ¤òÊÖ¤·¡¢
55 ¤ÏºÇ¸å¤Î \(aq/\(aq °Ê¹ß¤ÎÉôʬ¤òÊÖ¤¹¡£
56 ʸ»úÎó¤ÎËöÈø¤Ë¤Ä¤¤¤¿ \(aq/\(aq ʸ»ú¤Ï¡¢¥Ñ¥¹Ì¾¤Î°ìÉô¤È¤Ï¤ß¤Ê¤µ¤ì¤Ê¤¤¡£
59 ¤Ë '/' ʸ»ú¤¬¤Ê¤¤¾ì¹ç¤Ï¡¢
67 ¤¬Ê¸»úÎó "/" ¤ËÅù¤·¤¤¾ì¹ç¤Ï¡¢
73 ¤¬ NULL ¥Ý¥¤¥ó¥¿¤À¤Ã¤¿¤ê¡¢¶õ¤Îʸ»úÎó¤ò»Ø¤·¤Æ¤¤¤¿¾ì¹ç¤Ï¡¢
80 ¤ÎÊÖ¤·¤¿Ê¸»úÎó¡¢ "/"¡¢
83 ¤ò½ç¤Ë·ë¹ç¤¹¤ë¤È¡¢´°Á´¤Ê¥Ñ¥¹Ì¾¤¬ÆÀ¤é¤ì¤ë¡£
90 ¤ÎÆâÍƤòÊѹ¹¤¹¤ë¤³¤È¤¬¤¢¤ë¡£
91 ¤·¤¿¤¬¤Ã¤Æ¡¢¤³¤ì¤é¤Î´Ø¿ô¤ò¸Æ¤Ó½Ð¤¹ºÝ¤Ë¤Ï
92 ¥³¥Ô¡¼¤òÅϤ¹¤Î¤¬Ë¾¤Þ¤·¤¤¡£
94 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢ÀÅŪ¤Ë³ä¤êÅö¤Æ¤é¤ì¤¿¥á¥â¥ê¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¤³¤È¤¬¤¢¤ê¡¢
95 ¤³¤ì¤é¤ÎÎΰè¤Ï¸å¤Î´Ø¿ô¸Æ¤Ó½Ð¤·¤Ç¾å½ñ¤¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
98 ¤Î°ìÉôʬ¤ò»Ø¤¹¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¤³¤È¤â¤¢¤ë¡£¤½¤Î¤¿¤á¡¢
100 ¤Ç»²¾È¤µ¤ì¤ëʸ»úÎó¤Ï¡¢´Ø¿ô¤¬ÊÖ¤¹¥Ý¥¤¥ó¥¿¤¬ÉÔÍפˤʤë¤Þ¤Ç¤Ï
101 Êѹ¹¤·¤¿¤ê free ¤·¤¿¤ê¤¹¤Ù¤¤Ç¤Ï¤Ê¤¤¡£
103 °Ê²¼¤Î°ìÏ¢¤ÎÎã (SUSv2 ¤«¤é°úÍÑ) ¤Ï¡¢
104 ¤¤¤í¤¤¤í¤Ê path ¤ËÂФ·¤Æ
108 ¤¬ÊÖ¤¹Ê¸»úÎó¤òɽ¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
111 .B "path dirname basename"
112 "/usr/lib" "/usr" "lib"
123 ¤Ï¡¢¤¤¤º¤ì¤â NULL ¤Ç½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
131 ¤Ë¤Ï 2¼ïÎà¤Î°Û¤Ê¤ë¥Ð¡¼¥¸¥ç¥ó¤¬¤¢¤ë¡£
132 °ì¤Ä¤Ï¤¹¤Ç¤ËÀâÌÀ¤·¤¿ POSIX ¥Ð¡¼¥¸¥ç¥ó¤Ç¤¢¤ê¡¢
133 ¤â¤¦°ì¤Ä¤Ï GNU ¥Ð¡¼¥¸¥ç¥ó¤Ç¤¢¤ë¡£
134 GNU ¥Ð¡¼¥¸¥ç¥ó¤ò»ÈÍѤ¹¤ë¤Ë¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤¹¤ë¡£
138 .BR " #define _GNU_SOURCE" " /* feature_test_macros(7) »²¾È */"
140 .B " #include <string.h>"
143 GNU ¥Ð¡¼¥¸¥ç¥ó¤Ï°ú¤¿ô¤òÊѹ¹¤¹¤ë¤³¤È¤Ï¤Ê¤¯¡¢
145 ¤ÎËöÈø¤¬ '/'¤Î¾ì¹ç¤Ï¶õ¤Îʸ»úÎó¤òÊÖ¤¹¡£
148 ¤¬ "/" ¤Î¾ì¹ç¤â¶õʸ»úÎó¤òÊÖ¤¹¡£
150 ¤Ë¤Ï GNU ¥Ð¡¼¥¸¥ç¥ó¤Ï¤Ê¤¤¡£
154 ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤È POSIX ¥Ð¡¼¥¸¥ç¥ó¤Î
156 ¤¬»ÈÍѤµ¤ì¡¢¤½¤ì°Ê³°¤Î¾ì¹ç¤Ï GNU ¥Ð¡¼¥¸¥ç¥ó¤È¤Ê¤ë¡£
158 glibc ¤Î POSIX ¥Ð¡¼¥¸¥ç¥ó¤Î¼ÂÁõ¤Ç¤Ï¡¢°ú¤¿ô¤ÎÆâÍƤ¬Êѹ¹¤µ¤ì¡¢
159 °ú¤¿ô¤Ë ("/usr/" ¤Ê¤É¤Î) Äê¿ôʸ»úÎó¤ò»ØÄꤵ¤ì¤ë¤È
160 ¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¥Õ¥©¡¼¥ë¥È¤òµ¯¤³¤¹¡£
161 ¥Ð¡¼¥¸¥ç¥ó 2.2.1 °ÊÁ°¤Î glibc ¤Ç¤Ï¡¢ glibc ¤Î
163 ¤ÏËöÈø¤¬ \(aq/\(aq ʸ»ú¤Ë¤Ê¤Ã¤Æ¤¤¤ë¥Ñ¥¹Ì¾¤òÀµ¤·¤¯°·¤¨¤º¡¢
164 °ú¤¿ô¤¬ NULL ¤À¤È¥»¥°¥á¥ó¥Æ¡¼¥·¥ç¥ó¥Õ¥©¡¼¥ë¥È¤òµ¯¤³¤·¤¿¡£
168 char *dirc, *basec, *bname, *dname;
169 char *path = "/etc/passwd";
172 basec = strdup(path);
173 dname = dirname(dirc);
174 bname = basename(basec);
175 printf("dirname=%s, basename=%s\\n", dname, bname);