|
|||||||
|
|
GETCWDSection: Linux Programmer's Manual (3)Updated: 21 July 1993 Index Return to Main Contents ̾Á°getcwd, get_current_dir_name, getwd - ¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê̾¤Î¼èÆÀ½ñ¼°#include <unistd.h> char *getcwd(char *buf, size_t size); char *get_current_dir_name(void); char *getwd(char *buf); ÀâÌÀgetcwd() ´Ø¿ô¤Ï¥«¥ì¥ó¥È¥ï¡¼¥¥ó¥°¥Ç¥£¥ì¥¯¥È¥ê¤ÎÀäÂХѥ¹Ì¾(absolute pathname)¤ò buf ¤Ç¼¨¤µ¤ì¤¿ size ŤÎÇÛÎó¤Ë¥³¥Ô¡¼¤¹¤ë¡£¥«¥ì¥ó¥ÈÀäÂХѥ¹Ì¾(current absolute path name)¤¬ size ¤è¤ê¤âŤ¤¾ì¹ç¤Ï¡¢ÊÖ¤êÃͤȤ·¤Æ NULL ¤¬ÊÖ¤ê errno ¤Ë ERANGE ¤¬¥»¥Ã¥È¤µ¤ì¤ë¡£ ¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¤Ï¤³¤Î¥¨¥é¡¼¤ò¥Á¥§¥Ã¥¯¤·¡¢ ɬÍפ˱þ¤¸¤Æ¤è¤êŤ¤¥Ð¥Ã¥Õ¥¡¤òÍѰդ¹¤Ù¤¤Ç¤¢¤ë¡£
buf ¤¬ NULL ¤Î¾ì¹ç¡¢ getcwd() ¤Îưºî¤Ï̤ÄêµÁ¤Ç¤¢¤ë¡£ POSIX.1 ɸ½à¤Î³ÈÄ¥¤È¤·¤Æ¡¢ Linux (libc4, libc5, glibc)¤Ç¤Ï¸Æ¤Ó¤À¤·»þ¤Ë buf ¤Ë NULL ¤òÍ¿¤¨¤ë¤³¤È¤Ç getcwd() ¤¬É¬ÍפʥХåե¡¤ò malloc() ÍѤ¤¤ÆÆ°Åª¤Ë³ÍÆÀ¤¹¤ë¤è¤¦¤Ç¤¤ë¡£ ¤³¤Î¾ì¹ç¡¢ size ¤¬ 0 ¤Î¾ì¹ç¤ò½ü¤¥Ð¥Ã¥Õ¥¡¤ÎŤµ¤Ï size ¤È¤Ê¤ë¡£ size ¤¬ 0 ¤Î¾ì¹ç¤Ë¤ÏɬÍפÊÂ礤µ¤¬³ÎÊݤµ¤ì¤ë¡£ ¤³¤ÎÊýË¡¤Ç³ÍÆÀ¤·¤¿¥Ð¥Ã¥Õ¥¡¤Ï free() ¤Ç²òÊü¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¢¤ë(¤·¡¢¤½¤¦¤¹¤ë¤Î¤¬¸ÌÀ¤À)¡£ _GNU_SOURCE ¤¬ define ¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢ get_current_dir_name ¤¬¥×¥í¥È¥¿¥¤¥×Àë¸À¤µ¤ì¤ë¡£¤³¤Î´Ø¿ô¤Ï¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê̾ ¤ò¼ý¤á¤ë¤Î¤Ë½½Ê¬¤ÊÂ礤µ¤ÎÇÛÎó¤ò malloc(3) ¤Ç³ÍÆÀ¤¹¤ë¡£´Ä¶ÊÑ¿ô PWD ¤¬ÀßÄꤵ¤ì¤Æ¤ª¤ê¤½¤ÎÃͤ¬Àµ¤·¤±¤ì¤Ð¡¢¤½¤ÎÃͤ¬ÊÖ¤µ¤ì¤ë¡£ _BSD_SOURCE ¤Þ¤¿¤Ï _XOPEN_SOURCE_EXTENDED ¤¬define¤µ¤ì¤Æ¤¤¤ì¤Ð getwd ¤¬¥×¥í¥È¥¿¥¤¥×Àë¸À¤µ¤ì¤ë¡£ ¤³¤Î´Ø¿ô¤Ï malloc(3) ¤Ë¤è¤ë¥á¥â¥ê³ÍÆÀ¤ò°ìÀڹԤʤï¤Ê¤¤¡£ buf °ú¿ô¤Ï¾¯¤Ê¤¯¤È¤â PATH_MAX ¥Ð¥¤¥È¤ÎŤµ¤ò»ý¤ÄÇÛÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ëɬÍפ¬¤¢¤ë¡£ getwd ¤Ï¼ÂºÝ¤Î¥Ñ¥¹Ì¾¤ÎÀèÆ¬ PATH_MAX ¥Ð¥¤¥È¤òÊÖ¤¹¡£ ÊÖ¤êÃÍ¥¨¥é¡¼(Î㤨¤Ð¥«¥ì¥ó¥È¥Ç¥£¥ì¥¯¥È¥ê¤¬ÆÉ¹þ²Äǽ¤Ç¤Ê¤¤)¤¬È¯À¸¤¹¤ë¤È NULL ¤òÊÖ¤·¡¢ errno ¤¬¥¨¥é¡¼¤Ë½¾¤Ã¤Æ¥»¥Ã¥È¤µ¤ì¤ë¡£ À®¸ù¤¹¤ì¤Ð buf ¤òÊÖ¤¹¡£ ¥¨¥é¡¼¤Î¾ì¹ç¤Ï buf ¤¬»Ø¤¹ÇÛÎó¤ÎÆâÍÆ¤Ï̤ÄêµÁ¤Ç¤¢¤ë¡£½àµòPOSIX.1´ØÏ¢¹àÌÜchdir(2), free(3), malloc(3)
Index | ||||||
|
|
|
Home :: Copyright :: Privacy :: Credits :: Get a free Linuxinfor Email Account Document on this page is part of "Linuxinfor Man Pages in HTML Format: man3". See Index Page for more info about Authorship and Copyright. 1999-2008 Linuxinfor.com. No rights reserved. |