Rechercher une page de manuel
fopen
Langue: ja
Version: 2006-05-04 (openSuse - 09/10/07)
Section: 3 (Bibliothèques de fonctions)
̾Á°
fopen, fdopen, freopen - ¥¹¥È¥ê¡¼¥à¤ò³«¤¯´Ø¿ô½ñ¼°
#include <stdio.h>FILE *fopen(const char *path, const char *mode);
FILE *fdopen(int fildes, const char *mode);
FILE *freopen(const char *path, const char *mode, FILE *stream);
ÀâÌÀ
fopen() ´Ø¿ô¤Ï¡¢ path ¤Ç»ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥Õ¥¡¥¤¥ë¤ò³«¤¡¢¥¹¥È¥ê¡¼¥à¤È·ë¤Ó¤Ä¤±¤ë¡£°ú¿ô mode ¤Ï¡¢°Ê²¼¤Ë³¤¯Ê¸»ú¤Î¤Ò¤È¤Ä¤«¤é»Ï¤Þ¤ëʸ»úÎó¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ë (ÄɲäÎʸ»ú¤¬¤³¤Îʸ»ú¤Î¸å¤Ë³¤¯¤³¤È¤â¤¢¤ë):
- r
- ¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤òÆɤ߽Ф¹¤¿¤á¤Ë³«¤¯¡£ ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
- r+
- Æɤ߽Ф·¤ª¤è¤Ó½ñ¤¹þ¤ß¤¹¤ë¤¿¤á¤Ë³«¤¯¡£ ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
- w
- ¥Õ¥¡¥¤¥ë¤ò½ñ¤¹þ¤ß¤Î¤¿¤á¤Ë³«¤¯¡£ ¥Õ¥¡¥¤¥ë¤¬´û¤Ë¸ºß¤¹¤ë¾ì¹ç¤Ë¤ÏŤµ¥¼¥í¤ËÀÚ¤êµÍ¤á¤ë¡£ ¥Õ¥¡¥¤¥ë¤¬¤Ê¤«¤Ã¤¿¾ì¹ç¤Ë¤Ï¿·¤¿¤ËºîÀ®¤¹¤ë¡£ ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
- w+
- Æɤ߽Ф·¤ª¤è¤Ó½ñ¤¹þ¤ß¤Î¤¿¤á¤Ë³«¤¯¡£ ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¿·¤¿¤ËºîÀ®¤¹¤ë¡£ ¸ºß¤·¤Æ¤¤¤ë¾ì¹ç¤Ë¤ÏŤµ¥¼¥í¤ËÀÚ¤êµÍ¤á¤é¤ì¤ë¡£ ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
- a
- Äɲà (¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Ë½ñ¤¹þ¤à) ¤Î¤¿¤á¤Ë³«¤¯¡£ ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¿·¤¿¤ËºîÀ®¤¹¤ë¡£ ¥¹¥È¥ê¡¼¥à¤Ï¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Ë°ÌÃÖ¤µ¤ì¤ë¡£
- a+
- Æɤ߽Ф·¤ª¤è¤ÓÄɲà (¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Ë½ñ¤¹þ¤à) ¤Î¤¿¤á¤Ë³«¤¯¡£ ¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤·¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¿·¤¿¤ËºîÀ®¤¹¤ë¡£ Æɤ߽Ф·¤Î½é´ü¥Õ¥¡¥¤¥ë°ÌÃ֤ϥե¡¥¤¥ë¤ÎÀèƬ¤Ç¤¢¤ë¤¬¡¢ ½ñ¤¹þ¤ß¤Ï¾ï¤Ë¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤ËÄɲ䵤ì¤ë¡£
mode ʸ»úÎó¤Ë¤Ïʸ»ú ``b'' ¤òÄɲûØÄꤹ¤ë¤³¤È¤¬¤Ç¤¡¢ mode ʸ»úÎó¤ÎºÇ¸å¤Îʸ»ú¤È¤·¤Æ»ØÄꤹ¤ë¡£ ¾åµ¤Î¤¦¤Á 2 ʸ»ú¤Î¥â¡¼¥É¤Î¾ì¹ç¤Ë¤Ï 2 ¤Ä¤Îʸ»ú¤Î´Ö¤Ë»ØÄꤹ¤ë¤³¤È¤â¤Ç¤¤ë¡£ ¤³¤ì¤Ï C89 ¤È¤Î¸ß´¹À¤Î¤¿¤á¤À¤±¤ËÍÑ°Õ¤µ¤ì¤¿ ¤â¤Î¤Ç¤¢¤ê¡¢´Ø¿ô¤Î¼Â¹Ô¤ËÂФ·¤Æ¤Ï¤¤¤«¤Ê¤ë±Æ¶Á¤â»ý¤¿¤Ê¤¤¡£ ¤¹¤Ê¤ï¤Á¡¢Linux ¤ò´Þ¤àÁ´¤Æ¤Î POSIX ½àµò¥·¥¹¥Æ¥à¤Ç¤Ï¡¢ ¤³¤Î ``b'' ¤Ï̵»ë¤µ¤ì¤ë¡£ (¤½¤Î¾¤Î¥·¥¹¥Æ¥à¤Ç¤Ï¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤È¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤òÊÌ¡¹¤Ë°·¤¦¤â¤Î¤â¤¢¤ë¤Î¤Ç¡¢ ¤â¤·¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤ÎÆþ½ÐÎϤò¹Ô¤¤¡¢ ¤½¤Î¥×¥í¥°¥é¥à¤¬Èó UNIX ´Ä¶¤Ø°Ü¿¢¤µ¤ì¤ë¤Èͽ¬¤¹¤ë¤Ê¤é¡¢ ``b''¤òÉÕ¤±¤Æ¤ª¤¯¤Î¤ÏÎɤ¤¹Í¤¨¤Ç¤¢¤ë)
¤¹¤Ù¤Æ¤ÎÀ¸À®¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ï¡¢ S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH (0666) ¤Î¥â¡¼¥É¤ò ¤½¤Î¥×¥í¥»¥¹¤Î umask Ãͤˤè¤Ã¤Æ½¤Àµ¤·¤¿¥â¡¼¥É¤ò»ý¤Ä (umask(2) ¤ò¸«¤è)¡£
Æɤ߽Ф·/½ñ¤¹þ¤ß¥¹¥È¥ê¡¼¥à¤ËÂФ·¤Æ¤ÏǤ°Õ¤Î½ç½ø¤ÇÆɤ߽ñ¤¤ò¹Ô¤¦¤³¤È¤¬¤Ç¤¤ë¡£ ¤¿¤À¤· ANSI C ¤Ç¤Ï¡¢ (ÆþÎÏÁàºî¤¬¥Õ¥¡¥¤¥ë¤ÎËöÈø¤ËÅþ㤷¤¿¾ì¹ç¤ò½ü¤¤¤Æ) ½ÐÎϤÈÆþÎϤδ֤ˤϥե¡¥¤¥ë¤Î°ÌÃÖ·è¤á´Ø¿ô¤ò ¶´¤Þ¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¤³¤È¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤³¤È¤ËÃí°Õ¤µ¤ì¤¿¤¤ (¤³¤Î¾ò·ï¤òËþ¤·¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢Æɤ߹þ¤ßÁàºî¤Ï¡¢ ºÇ¸å¤Ë½ñ¤¹þ¤Þ¤ì¤¿¤â¤Î¤Ç¤Ê¤¯¡¢°ÊÁ°¤Ë½ñ¤¹þ¤Þ¤ì¤¿ ÃͤòÊÖ¤¹¤³¤È¤òµö¤µ¤ì¤Æ¤¤¤ë)¡£ ¤·¤¿¤¬¤Ã¤Æ¡¢¤³¤Î¤è¤¦¤Ê¥¹¥È¥ê¡¼¥à¤Ç¤ÎÆɤ߽ñ¤Áàºî¤Î´Ö¤Ë¤Ï fseek(3) ¤Þ¤¿¤Ï fgetpos(3) Áàºî¤ò¶´¤ó¤Ç¤ª¤¯¤ÈÎɤ¤¤À¤í¤¦ (Linux ¤Ç¤ÏËÜÅö¤ËɬÍפȤʤ뤳¤È¤â¤È¤¤É¤¤¢¤ë)¡£ ¤³¤ÎÁàºî¤Ï¸«¤«¤±¾å²¿¤â¤·¤Ê¤¤Áàºî (no-op) ¤Ç¤âÎɤ¤ (Î㤨¤Ð fseek(..., 0L, SEEK_CUR) ¤ò ¤½¤ÎÉû¼¡Åª¸ú²Ì¤Ç¤¢¤ëƱ´ü¤Î¤¿¤á¤À¤±¤Ë¸Æ¤Ù¤ÐÎɤ¤)¡£
¥Õ¥¡¥¤¥ë¤òÄɲå⡼¥É (mode ¤ÎºÇ½é¤Îʸ»ú¤òa¤Ë¤¹¤ë) ¤Ç³«¤¯¤È¡¢ ¤³¤Î¥¹¥È¥ê¡¼¥à¤ËÂФ¹¤ë½ñ¤¹þ¤ßÁàºî¤Ï (Àè¤Ë
- fseek(stream,0,SEEK_END);
fdopen() ´Ø¿ô¤Ï¡¢´û¸¤Î¥Õ¥¡¥¤¥ëµ½Ò»Ò fildes ¤Ë¥¹¥È¥ê¡¼¥à¤ò·ë¤Ó¤Ä¤±¤ë¡£ ¥¹¥È¥ê¡¼¥à¤Î mode ("r", "r+", "w", "w+", "a", "a+" ¤Î¤¤¤º¤ì¤«) ¤Ï ¥Õ¥¡¥¤¥ëµ½Ò»Ò¤Î¥â¡¼¥É¤È¸ß´¹¤Î¤â¤Î¤Ç¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£ ¿·¤·¤¤¥¹¥È¥ê¡¼¥à¤Î¥Õ¥¡¥¤¥ë°ÌÃֻؼ¨»Ò¤Ï fildes ¤Ë°¤·¤Æ¤¤¤ëÃͤËÀßÄꤵ¤ì¤ë¡£ error ¤È end-of-file ¤Î³Æ»Ø¼¨»Ò¤Ï¥¯¥ê¥¢¤µ¤ì¤ë¡£ "w" ¤ª¤è¤Ó "w+" ¥â¡¼¥É¤Ç¤Î¥Õ¥¡¥¤¥ë¤ÎÀÚ¤êµÍ¤á¤Ï¹Ô¤ï¤ì¤Ê¤¤¡£ ¥Õ¥¡¥¤¥ëµ½Ò»Ò¤ÎÊ£À½¤Ï¹Ô¤Ê¤ï¤ì¤Ê¤¤¡£ fdopen() ¤ÇºîÀ®¤µ¤ì¤¿¥¹¥È¥ê¡¼¥à¤¬ÊĤ¸¤é¤ì¤¿¤È¤¤Ë¥Õ¥¡¥¤¥ëµ½Ò»Ò¤â ÊĤ¸¤é¤ì¤ë¡£ ¶¦Í¥á¥â¥ê¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Ø fdopen() ¤ò¹Ô¤Ã¤¿¤È¤¤Î·ë²Ì¤ÏÄêµÁ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
freopen() ´Ø¿ô¤Ï path ¤Ç̾Á°¤¬»ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤ò³«¤¡¢ stream ¤Ç»ØÄꤵ¤ì¤¿¥¹¥È¥ê¡¼¥à¤Ë¡¢¤½¤Î¥Õ¥¡¥¤¥ë¤ò·ë¤Ó¤Ä¤±¤ë¡£ ¤â¤È¤Î¥¹¥È¥ê¡¼¥à¤Ï (¤â¤·Â¸ºß¤¹¤ë¾ì¹ç¤Ë¤Ï) ÊĤ¸¤é¤ì¤ë¡£ mode °ú¿ô¤Ï fopen() ´Ø¿ô¤ÈƱ¤¸·Á¤Ç»È¤ï¤ì¤ë¡£ freopen() ´Ø¿ô¤Î¼ç¤ÊÍÑÅӤϡ¢É¸½à¥Æ¥¥¹¥È¥¹¥È¥ê¡¼¥à (stderr¡¢stdin¡¢stdout) ¤ÈÂбþÉÕ¤±¤é¤ì¤Æ¤¤¤ë¥Õ¥¡¥¤¥ë¤òÊѹ¹¤¹¤ë¤³¤È¤Ç¤¢¤ë¡£
ÊÖ¤êÃÍ
fopen(), fdopen(), freopen() ¤ÏÀ®¸ù¤¹¤ë¤È FILE ·¿¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£ ¼ºÇÔ¤¹¤ë¤È NULL ¤¬ÊÖ¤µ¤ì¡¢Âç°èÊÑ¿ô errno ¤¬¥¨¥é¡¼¤ò¼¨¤¹Ãͤ˥»¥Ã¥È¤µ¤ì¤ë¡£¥¨¥é¡¼
- EINVAL
- fopen(), fdopen(), freopen() ¤ÇÍ¿¤¨¤é¤ì¤¿ mode ¤¬ÉÔŬÀڤǤ¢¤ë¡£
fopen(), fdopen(), freopen() ´Ø¿ô¤Ï malloc(3) ¥ë¡¼¥Á¥ó¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Ç¤â¼ºÇÔ¤¹¤ë¤³¤È¤¬¤¢¤ê¡¢ ¤½¤Î»þ¤ÏÂбþ¤¹¤ëÃÍ¤Ë errno ¤ò¥»¥Ã¥È¤¹¤ë¡£
fopen() ´Ø¿ô¤Ï open(2) ¥ë¡¼¥Á¥ó¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Ç¤â¼ºÇÔ¤¹¤ë¤³¤È¤¬¤¢¤ê¡¢ ¤½¤Î»þ¤ÏÂбþ¤¹¤ëÃÍ¤Ë errno ¤ò¥»¥Ã¥È¤¹¤ë¡£
fdopen() ´Ø¿ô¤Ï fcntl(2) ¥ë¡¼¥Á¥ó¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Ç¤â¼ºÇÔ¤¹¤ë¤³¤È¤¬¤¢¤ê¡¢ ¤½¤Î»þ¤ÏÂбþ¤¹¤ëÃÍ¤Ë errno ¤ò¥»¥Ã¥È¤¹¤ë¡£
freopen() ´Ø¿ô¤Ï open(2), fclose(3), fflush(3) ³Æ¥ë¡¼¥Á¥ó¤Çµ¬Äꤵ¤ì¤Æ¤¤¤ë¥¨¥é¡¼¤Ç¤â¼ºÇÔ¤¹¤ë¤³¤È¤¬¤¢¤ê¡¢ ¤½¤Î»þ¤ÏÂбþ¤¹¤ëÃÍ¤Ë errno ¤ò¥»¥Ã¥È¤¹¤ë¡£
½àµò
fopen() ´Ø¿ô¤È freopen() ´Ø¿ô¤Ï C89¤Ë½àµò¤·¤Æ¤¤¤ë¡£ fdopen() ´Ø¿ô¤Ï POSIX.1-1990 ¤Ë½àµò¤·¤Æ¤¤¤ë¡£Ãí°Õ
glibc ¤Ç¤ÎÃí°Õ
GNU C ¥é¥¤¥Ö¥é¥ê¤Ç¤Ï¡¢ mode ¤Ë»ØÄê¤Ç¤¤ëʸ»úÎó¤È¤·¤Æ¡¢°Ê²¼¤Î³ÈÄ¥¤¬¹Ô¤ï¤ì¤Æ¤¤¤ë:- c (glibc 2.3.3 °Ê¹ß)
- open Áàºî¡¢¤½¤ì¤Ë³¤¯ read/write Áàºî¤Î¡¢ ¥¹¥ì¥Ã¥É¤Î¥¥ã¥ó¥»¥ì¡¼¥·¥ç¥ó¥Ý¥¤¥ó¥È (cancellation points) ¤òºîÀ®¤·¤Ê¤¤¡£
- m (glibc 2.3 °Ê¹ß)
- I/O ¥·¥¹¥Æ¥à¥³¡¼¥ë (read(2), write(2)) ¤Ç¤Ï¤Ê¤¯¡¢ mmap(2) ¤ò»È¤Ã¤Æ¥Õ¥¡¥¤¥ë¤Ë¥¢¥¯¥»¥¹¤·¤è¤¦¤È¤¹¤ë¡£ mmap(2) ¤ò»È¤ª¤¦¤È¤¹¤ë¤Î¤Ï¡¢Æɤ߽Ф·ÍѤ˥ª¡¼¥×¥ó¤¹¤ë¥Õ¥¡¥¤¥ë¤Ë¤Ä¤¤¤Æ¤À¤±¤Ç¤¢¤ë¡£
- x
- ¥Õ¥¡¥¤¥ë¤òÇÓ¾Ū¤Ë¥ª¡¼¥×¥ó¤¹¤ë (open(2) ¤Î O_EXCL ¥Õ¥é¥°¤ÈƱÍÍ)¡£ ¥Õ¥¡¥¤¥ë¤¬¤¹¤Ç¤Ë¸ºß¤¹¤ë¾ì¹ç¡¢ fopen() ¤Ï¼ºÇÔ¤·¡¢ errno ¤Ë EEXIST ¤¬¥»¥Ã¥È¤µ¤ì¤ë¡£ ¤³¤Î¥Õ¥é¥°¤Ï fdopen() ¤Ç¤Ï̵»ë¤µ¤ì¤ë¡£
´ØÏ¢¹àÌÜ
open(2), fclose(3), fileno(3)Contenus ©2006-2024 Benjamin Poulain
Design ©2006-2024 Maxime Vantorre