1 .\" Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
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 .\" Modified Wed Jul 21 22:35:42 1993 by Rik Faith (faith@cs.unc.edu)
24 .\" Modified 18 Mar 1996 by Martin Schulze (joey@infodrom.north.de):
25 .\" Corrected description of getwd().
26 .\" Modified Sat Aug 21 12:32:12 MET 1999 by aeb - applied fix by aj
27 .\" Modified Mon Dec 11 13:32:51 MET 2000 by aeb
28 .\" Modified Thu Apr 22 03:49:15 CEST 2002 by Roger Luethi <rl@hellgate.ch>
30 .\" Japanese Version Copyright (c) 1997 IMAMURA Nobutaka
31 .\" all rights reserved.
32 .\" Translated Fri Feb 14 12:40:22 JST 1997
33 .\" by IMAMURA Nobutaka <imamura@spp.hpc.fujitsu.co.jp>
34 .\" Modified Thu Dec 8 05:08:44 JST 1999
35 .\" by Kentaro Shirakata <argrath@yo.rim.or.jp>
36 .\" Modified Sun Mar 12 21:08:44 JST 2000
37 .\" by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
38 .\" Updated 2001-01-29 by Kentaro Shirakata <argrath@ub32.org>
39 .\" Updated 2002-03-23 by Kentaro Shirakata <argrath@ub32.org>
40 .\" Updated 2002-10-17 by Kentaro Shirakata <argrath@ub32.org>
41 .\" Updated 2007-01-01 by Kentaro Shirakata <argrath@ub32.org>
42 .\" Updated 2008-08-21, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.07
44 .\" WORD: current working directory ¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê
45 .\" WORD: LEGACY ¡Ö²áµî¤Î̾»Ä(LEGACY)¡×
47 .TH GETCWD 3 2010-09-20 "GNU" "Linux Programmer's Manual"
50 .\"O getcwd, getwd, get_current_dir_name \- Get current working directory
51 getcwd, getwd, get_current_dir_name \- ¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê̾¤Î¼èÆÀ
55 .B #include <unistd.h>
57 .BI "char *getcwd(char *" buf ", size_t " size );
59 .BI "char *getwd(char *" buf );
61 .B "char *get_current_dir_name(void);"
65 .\"O Feature Test Macro Requirements for glibc (see
66 .\"O .BR feature_test_macros (7)):
67 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
68 .RB ( feature_test_macros (7)
72 .BR get_current_dir_name ():
82 .\"O Since glibc 2.10:
86 (_XOPEN_SOURCE\ >=\ 500 ||
87 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
88 !(_POSIX_C_SOURCE\ >=\ 200809L || _XOPEN_SOURCE\ >=\ 700)
91 .\"O Before glibc 2.10:
93 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
94 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
100 .\"O These functions return a null-terminated string containing an
101 .\"O absolute pathname that is the current working directory of
102 .\"O the calling process.
103 .\"O The pathname is returned as the function result and via the argument
106 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¡¢¸Æ¤Ó½Ð¤·¤¿¥×¥í¥»¥¹¤Î¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤Î
107 ÀäÂХѥ¹Ì¾ (absolute pathname) ¤¬Æþ¤Ã¤¿Ê¸»úÎó¤òÊÖ¤¹¡£
108 ÊÖ¤µ¤ì¤ëʸ»úÎó¤Ï NULL ¤Ç½ªÃ¼¤µ¤ì¤ë¡£
109 ¥Ñ¥¹Ì¾¤Ï´Ø¿ô¤Î·ë²Ì¤È¤·¤ÆÊÖ¤µ¤ì¡¢°ú¿ô
117 .\"O function copies an absolute pathname of the current working directory
118 .\"O to the array pointed to by
120 .\"O which is of length
123 ´Ø¿ô¤Ï¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤ÎÀäÂХѥ¹Ì¾¤ò
127 ŤÎÇÛÎó¤Ë¥³¥Ô¡¼¤¹¤ë¡£
129 .\"O If the length of the absolute pathname of the current working directory,
130 .\"O including the terminating null byte, exceeds
132 .\"O bytes, NULL is returned, and
136 .\"O an application should check for this error, and allocate a larger
137 .\"O buffer if necessary.
138 ½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤â´Þ¤á¤¿¡¢¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤Î
141 ¥Ð¥¤¥È¤òĶ¤¨¤Æ¤¤¤ë¾ì¹ç¤Ï¡¢ÊÖ¤êÃͤȤ·¤Æ NULL ¤¬ÊÖ¤ê
146 ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¤³¤Î¥¨¥é¡¼¤ò¥Á¥§¥Ã¥¯¤·¡¢
147 ɬÍפ˱þ¤¸¤Æ¤è¤êŤ¤¥Ð¥Ã¥Õ¥¡¤òÍÑ°Õ¤¹¤Ù¤¤Ç¤¢¤ë¡£
149 .\"O As an extension to the POSIX.1-2001 standard, Linux (libc4, libc5, glibc)
151 .\"O allocates the buffer dynamically using
156 .\"O In this case, the allocated buffer has the length
162 .\"O is allocated as big as necessary.
163 .\"O The caller should
165 .\"O the returned buffer.
166 POSIX.1-2001 ɸ½à¤Î³ÈÄ¥¤È¤·¤Æ¡¢
167 Linux (libc4, libc5, glibc) ¤Ç¤Ï
173 ¤òÍѤ¤¤ÆưŪ¤Ë³ä¤êÅö¤Æ¤ë¡£
176 ¤¬ 0 ¤Î¾ì¹ç¤ò½ü¤¡¢¥Ð¥Ã¥Õ¥¡¤ÎŤµ¤Ï
180 ¤¬ 0 ¤Î¾ì¹ç¤Ë¤ÏɬÍפÊÂ礤µ¤¬³ÎÊݤµ¤ì¤ë¡£
181 ¸Æ¤Ó½Ð¤·Â¦¤Ç¡¢ÊÖ¤µ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤ò
185 .\"O .BR get_current_dir_name ()
188 .\"O an array big enough to hold the absolute pathname of
189 .\"O the current working directory.
190 .\"O If the environment
193 .\"O is set, and its value is correct, then that value will be returned.
194 .BR get_current_dir_name ()
195 ¤Ï¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤ÎÀäÂХѥ¹Ì¾¤ò¼ý¤á¤ë¤Î¤Ë
200 ¤¬ÀßÄꤵ¤ì¤Æ¤ª¤ê¤½¤ÎÃͤ¬Àµ¤·¤±¤ì¤Ð¡¢¤½¤ÎÃͤ¬ÊÖ¤µ¤ì¤ë¡£
201 .\"O The caller should
203 .\"O the returned buffer.
204 ¸Æ¤Ó½Ð¤·Â¦¤Ç¡¢ÊÖ¤µ¤ì¤¿¥Ð¥Ã¥Õ¥¡¤ò
214 .\"O argument should be a pointer to an array at least
217 .\"O If the length of the absolute pathname of the current working directory,
218 .\"O including the terminating null byte, exceeds
220 .\"O bytes, NULL is returned, and
223 .\"O .BR ENAMETOOLONG .
227 ¤Ë¤è¤ë¥á¥â¥ê³ÍÆÀ¤ò°ìÀڹԤʤï¤Ê¤¤¡£
231 ¥Ð¥¤¥È¤ÎŤµ¤ò»ý¤ÄÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ëɬÍפ¬¤¢¤ë¡£
232 ½ªÃ¼¤Î NULL ¥Ð¥¤¥È¤â´Þ¤á¤¿¡¢¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤Î
235 ¥Ð¥¤¥È¤òĶ¤¨¤Æ¤¤¤ë¾ì¹ç¡¢
241 .\"O (Note that on some systems,
243 .\"O may not be a compile-time constant;
244 .\"O furthermore, its value may depend on the file system, see
245 .\"O .BR pathconf (3).)
246 .\"O For portability and security reasons, use of
249 (¥·¥¹¥Æ¥à¤Ë¤è¤Ã¤Æ¤Ï¡¢
251 ¤Ïɬ¤º¤·¤â¥³¥ó¥Ñ¥¤¥ë»þ¤Ë·è¤Þ¤ëÄê¿ô¤Ç¤Ï¤Ê¤¤ÅÀ¤ËÃí°Õ¤¹¤ë¤³¤È¡£
252 ¤Þ¤¿¡¢¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤Ë°Í¸¤¹¤ë¾ì¹ç¤â¤¢¤ë¡£
255 °Ü¿¢À¤È¥»¥¥å¥ê¥Æ¥£¾å¤ÎÍýͳ¤«¤é¡¢
257 ¤ÎÍøÍѤϿ侩¤µ¤ì¤Ê¤¤¡£
258 .\"O .SH "RETURN VALUE"
260 .\"O On success, these functions return a pointer to a string containing
261 .\"O the pathname of the current working directory.
266 .\"O this is the same value as
268 À®¸ù¤¹¤ë¤È¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤ÎÀäÂХѥ¹Ì¾
269 ¤¬Æþ¤Ã¤¿Ê¸»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
277 .\"O On failure, these functions return NULL, and
279 .\"O is set to indicate the error.
280 .\"O The contents of the array pointed to by
282 .\"O are undefined on error.
283 ¼ºÇÔ¤·¤¿¾ì¹ç¡¢¤³¤ì¤é¤Î´Ø¿ô¤Ï NULL ¤òÊÖ¤·¡¢
285 ¤Ë¥¨¥é¡¼¤ò¼¨¤¹ÃͤòÀßÄꤹ¤ë¡£
287 ¤¬»Ø¤¹ÇÛÎó¤ÎÆâÍƤÏ̤ÄêµÁ¤Ç¤¢¤ë¡£
292 .\"O Permission to read or search a component of the filename was denied.
293 ¥Õ¥¡¥¤¥ë̾¤Î¹½À®Í×ÁǤËÂФ¹¤ëÆɤ߹þ¤ß¤¢¤ë¤¤¤Ï¸¡º÷¤Î¸¢¸Â¤¬¤Ê¤¤¡£
297 .\"O points to a bad address.
299 ¤¬ÉÔÀµ¤Ê¥¢¥É¥ì¥¹¤ò»Ø¤·¤Æ¤¤¤ë¡£
304 .\"O argument is zero and
306 .\"O is not a null pointer.
310 °ú¿ô¤¬ NULL ¥Ý¥¤¥ó¥¿¤Ç¤Ê¤¤¡£
322 .\"O The size of the null-terminated absolute pathname string exceeds
326 ÀäÂХѥ¹Ì¾¤¬Æþ¤Ã¤¿ NULL ½ªÃ¼¤µ¤ì¤¿Ê¸»úÎó¤ÎŤµ¤¬
331 .\"O The current working directory has been unlinked.
332 ¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤¬ºï½ü¤µ¤ì¤Æ¤¤¤ë¡£
337 .\"O argument is less than the length of the absolute pathname of the
338 .\"O working directory, including the terminating null byte.
339 .\"O You need to allocate a bigger array and try again.
341 °ú¿ô¤ÎÃͤ¬¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤ÎÀäÂХѥ¹Ì¾¤ÎŤµ¤è¤ê¾®¤µ¤¤¡£
342 Ťµ¤Ë¤Ïʸ»úÎó¤Î½ªÃ¼¥Ð¥¤¥È¤â´Þ¤Þ¤ì¤ë¡£
343 ¤è¤êÂ礤¤ÇÛÎó¤ò³ÎÊݤ·¤Æ¤â¤¦°ìÅټ¹Ԥ¹¤ëɬÍפ¬¤¢¤ë¡£
344 .\"O .SH "CONFORMING TO"
347 .\"O conforms to POSIX.1-2001.
349 ¤Ï POSIX.1-2001 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£
350 .\"O Note however that POSIX.1-2001 leaves the behavior of
359 ¤ÎÆ°ºî¤òµ¬Äꤷ¤Ê¤¤¤Þ¤Þ¤È¤·¤Æ¤¤¤ë¡£
362 .\"O is present in POSIX.1-2001, but marked LEGACY.
364 ¤Ï POSIX.1-2001 ¤Ë¸ºß¤·¤Æ¤¤¤ë¤¬¡¢¡Ö²áµî¤Î̾»Ä(LEGACY)¡×¤È¤µ¤ì¤Æ¤¤¤ë¡£
365 .\"O POSIX.1-2008 removes the specification of
371 .\"O does not define any errors for
375 ¤Î»ÅÍͤ¬ºï½ü¤µ¤ì¤Æ¤¤¤ë¡£
381 ¤Ë´Ø¤¹¤ë¥¨¥é¡¼¤òÄêµÁ¤·¤Æ¤¤¤Ê¤¤¡£
383 .\"O .BR get_current_dir_name ()
384 .\"O is a GNU extension.
385 .BR get_current_dir_name ()
389 .\"O Under Linux, the function
391 .\"O is a system call (since 2.1.92).
392 Linux ¤Ç¤Ï (2.1.92 °Ê¹ß)¡¢
394 ¤Ï¥·¥¹¥Æ¥à¥³¡¼¥ë¤Ç¤¢¤ë¡£
395 .\"O On older systems it would query
396 .\"O .IR /proc/self/cwd .
400 .\"O If both system call and proc file system are missing, a
401 .\"O generic implementation is called.
402 .\"O Only in that case can
403 .\"O these calls fail under Linux with
405 ¥·¥¹¥Æ¥à¥³¡¼¥ë¤â proc ¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤â¤Ê¤¤¾ì¹ç¡¢
406 °ìÈÌŪ¤Ê¼ÂÁõ¤¬¸Æ¤Ó½Ð¤µ¤ì¤ë¡£
407 ¤³¤Î¾ì¹ç¤Ë¤ª¤¤¤Æ¤Î¤ß¡¢(Linux ¤Ç¤Ï) ¤³¤Î´Ø¿ô¤Ï
409 ¤Ç¼ºÇÔ¤¹¤ë²ÄǽÀ¤¬¤¢¤ë¡£
411 .\"O These functions are often used to save the location of the current working
412 .\"O directory for the purpose of returning to it later.
413 .\"O Opening the current
414 .\"O directory (".") and calling
416 .\"O to return is usually a faster and more reliable alternative when sufficiently
417 .\"O many file descriptors are available, especially on platforms other than Linux.
418 ¤³¤ì¤é¤Î´Ø¿ô¤Ï¤·¤Ð¤·¤Ð¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤Î°ÌÃÖ¤òÊݸ¤·¡¢
419 ¸å¤ÇÌá¤Ã¤Æ¤¯¤ë¤¿¤á¤ËÍøÍѤµ¤ì¤ë¡£
420 ̤»ÈÍѤΥե¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤¬½½Ê¬¤¢¤ë¾ì¹ç¤Ï¡¢
421 ¸½ºß¤Î¥Ç¥£¥ì¥¯¥È¥ê (".") ¤ò³«¤¤¤Æ
423 ¤ò¸Æ¤Ó½Ð¤¹¤Û¤¦¤¬ÉáÄ̤Ϲ⮤ǿ®ÍêÀ¤¬¤¢¤ë¡£
424 ÆÃ¤Ë Linux °Ê³°¤Î¥×¥é¥Ã¥È¥Õ¥©¡¼¥à¤Î¾ì¹ç¤Ï¤½¤¦¤Ç¤¢¤ë¡£