read

Autres langues

Langue: ja

Version: 1997-07-12 (openSuse - 09/10/07)

Section: 2 (Appels système)

̾Á°

read - ¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤«¤éÆɤ߹þ¤à

½ñ¼°


#include <unistd.h>



ssize_t read(int fd, void *buf, size_t count);

ÀâÌÀ

read() ¤Ï¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼ (file descriptor) fd ¤«¤éºÇÂç count ¥Ð¥¤¥È¤ò buf ¤Ç»Ï¤Þ¤ë¥Ð¥Ã¥Õ¥¡¡¼¤ØÆɤ߹þ¤â¤¦¤È¤¹¤ë¡£

count ¤¬ 0 ¤Ê¤é¤Ð¡¢ read() ¤Ï 0 ¤òÊÖ¤·¡¢Â¾¤Ë²¿¤âµ¯¤­¤Ê¤¤¡£ count ¤¬ SSIZE_MAX ¤è¤êÂ礭¤±¤ì¤Ð¡¢·ë²Ì¤ÏÆÃÄê¤Ç¤­¤Ê¤¤¡£

ÊÖ¤êÃÍ

À®¸ù¤·¤¿¾ì¹ç¡¢Æɤ߹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤¹ (0 ¤Ï¥Õ¥¡¥¤¥ë¤Î½ª¤ê¤ò°ÕÌ£¤¹¤ë)¡£ ¥Õ¥¡¥¤¥ë°ÌÃ֤Ϥ³¤Î¿ô¤À¤±¿Ê¤á¤é¤ì¤ë¡£ ¤³¤Î¿ô¤¬Í׵ᤷ¤¿¿ô¤è¤ê¾®¤µ¤«¤Ã¤¿¤È¤·¤Æ¤â¥¨¥é¡¼¤Ç¤Ï¤Ê¤¤; Î㤨¤Ðº£¤¹¤°¤Ë¤Ï¼ÂºÝ¤Ë¤½¤ì¤À¤±¤Î¿ô¤·¤«¤Ê¤¤¾ì¹ç (¥Õ¥¡¥¤¥ë¤ÎºÇ¸å¤Ë¶á¤¤¤Î¤«¤â ¤·¤ì¤Ê¤¤¤·¡¢¥Ñ¥¤¥× (pipe) ¤äüËö (terminal) ¤«¤éÆɤ߹þ¤ó¤Ç¤¤¤ë¤«¤â¤·¤ì¤Ê¤¤) ¤ä read() ¤¬¥·¥°¥Ê¥ë (signal) ¤Ë¤è¤Ã¤Æ³ä¤ê¹þ¤Þ¤ì¤¿¾ì¹ç¤Ë¤³¤ì¤Ïµ¯¤³¤ê¤¨¤ë¡£ ¥¨¥é¡¼¤Î¾ì¹ç¤Ï¡¢-1 ¤¬ÊÖ¤µ¤ì¡¢ errno ¤¬Å¬ÀÚ¤ËÀßÄꤵ¤ì¤ë¡£¤³¤Î¾ì¹ç¤Ï¥Õ¥¡¥¤¥ë°ÌÃÖ¤¬Êѹ¹¤µ¤ì¤ë¤«¤É¤¦¤«¤Ï ÉÔÄê¤Ç¤¢¤ë¡£

¥¨¥é¡¼

EAGAIN
O_NONBLOCK ¤ò»ÈÍѤ·¤ÆÈóÄä»ß (Non-blocking) I/O ¤¬ÁªÂò¤µ¤ì¤Æ¤ª¤ê¡¢ ¤¹¤°¤Ë¥Ç¡¼¥¿¤¬Æɤ߹þ¤ß²Äǽ¤Ç¤Ê¤«¤Ã¤¿¡£
EBADF
fd ¤¬Í­¸ú¤Ê¥Õ¥¡¥¤¥ë¡¦¥Ç¥£¥¹¥¯¥ê¥×¥¿¡¼¤Ç¤Ê¤¤¤«¡¢Æɤ߹þ¤ß¤Î¤¿¤á¤Ë ¥ª¡¼¥×¥ó (open) ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
EFAULT
buf ¤¬¥¢¥¯¥»¥¹²Äǽ¤Ê¥¢¥É¥ì¥¹¶õ´Ö¤Î³°¤Ë¤¢¤ë¡£
EINTR
²¿¤Î¥Ç¡¼¥¿¤âÆɤ߹þ¤Þ¤Ê¤¤¤¦¤Á¤Ë¥·¥°¥Ê¥ë¤Ë³ä¤ê¹þ¤Þ¤ì¤¿¡£
EINVAL
fd ¤ÏÆɤ߹þ¤ß¤ËŬ¤·¤Æ¤¤¤Ê¤¤¥ª¥Ö¥¸¥§¥¯¥È¤ò»²¾È¤·¤Æ¤¤¤ë¡£ ¤â¤·¤¯¤Ï¡¢¥Õ¥¡¥¤¥ë¤¬ O_DIRECT ¥Õ¥é¥°¤ò»ØÄꤷ¤Æ¥ª¡¼¥×¥ó¤µ¤ì¤Æ¤¤¤ë¤¬¡¢ buf ¤Ë»ØÄꤵ¤ì¤¿¥¢¥É¥ì¥¹¡¢ count ¤Ë»ØÄꤵ¤ì¤¿ÃÍ¡¢ ¸½ºß¤Î¥Õ¥¡¥¤¥ë¥ª¥Õ¥»¥Ã¥È¤Î¤¤¤º¤ì¤«¤Î ¥¢¥é¥¤¥ó¥á¥ó¥È¤¬ÉÔŬÀڤǤ¢¤ë¡£
EIO
I/O ¥¨¥é¡¼¡£¤³¤ì¤ÏÎ㤨¤Ð¥×¥í¥»¥¹¤¬¥Ð¥Ã¥¯¥°¥é¥ó¥É¡¦¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×¤Ç¡¢ ¤½¤ì¤òÀ©¸æ¤·¤Æ¤¤¤ë tty ¤«¤éÆɤ߹þ¤â¤¦¤È¤·¡¢SIGTTIN ¤¬Ìµ»ë (ignore) ¤Þ¤¿¤Ï ¶Ø»ß (blocking) ¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¤ä¡¢¤½¤Î¥×¥í¥»¥¹¡¦¥°¥ë¡¼¥×¤¬¸ÉΩ (orphan) ¤·¤Æ ¤¤¤ë¾ì¹ç¤Ëµ¯¤³¤ë¡£¤Þ¤¿¥Ç¥£¥¹¥¯¤ä¥Æ¡¼¥×¤òÆɤó¤Ç¤¤¤ë»þ¤ËÄã¥ì¥Ù¥ë I/O ¥¨¥é¡¼ ¤¬È¯À¸¤·¤¿¾ì¹ç¤Ë¤âµ¯¤³¤ë¡£
EISDIR
fd ¤¬¥Ç¥£¥ì¥¯¥È¥ê¤ò»²¾È¤·¤Æ¤¤¤ë¡£

fd ¤¬Àܳ¤·¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Ë¤è¤Ã¤Æ¤Ï¾¤Î¥¨¥é¡¼¤âµ¯¤³¤ê¤¨¤ë¡£ POSIX ¤Ç¤Ï¡¢ ¤¤¤¯¤é¤«¤Î¥Ç¡¼¥¿¤òÆɤó¤À¸å¤Ë³ä¤ê¹þ¤ß¤¬µ¯¤³¤Ã¤¿¾ì¹ç¡¢ read() ¤Ï (errno ¤Ë EINTR ¤òÀßÄꤷ¤Æ) -1 ¤òÊÖ¤·¤Æ¤â¤è¤¤¤·¡¢ ´û¤ËÆɤ߹þ¤ó¤À¥Ð¥¤¥È¿ô¤òÊÖ¤·¤Æ¤â¤è¤¤¡£

½àµò

SVr4, 4.3BSD, POSIX.1-2001.

Ãí°Õ

NFS ¤Ë¤ª¤¤¤Æ¡£¾¯Î̤Υǡ¼¥¿¤òÆɤ߹þ¤à¾ì¹ç¡¢ºÇ½é¤Î»þ¤Î¤ß¤Ë¥¿¥¤¥à¡¦ ¥¹¥¿¥ó¥×¤¬¹¹¿·¤µ¤ì¡¢Â³¤¯¥³¡¼¥ë¤Ç¤Ï¹¹¿·¤µ¤ì¤Ê¤¤¤À¤í¤¦¡£ ¤³¤ì¤Ï¥¯¥é¥¤¥¢¥ó¥È¦¤Ç°À­¤Î¥­¥ã¥Ã¥·¥ó¥°¤ò¹Ô¤Ê¤¦¤¿¤á¤Ç¤¢¤ë¡£ ¤Ê¤¼¤Ê¤é¤Ð¡¢¤â¤·Á´¤Æ¤Î NFS ¥¯¥é¥¤¥¢¥ó¥È¤¬ st_atime (ºÇ½ª¥Õ¥¡¥¤¥ë¥¢¥¯¥»¥¹»þ¹ï) ¤Î¹¹¿·¤ò¥µ¡¼¥Ð¡¼¤ËÁ÷¤é¤º¡¢¥¯¥é¥¤¥¢¥ó¥È¦¤Ç¥­¥ã¥Ã¥·¥å¤òÆɤळ¤È¤ËËþ­¤·¤Æ ¤¤¤ì¤Ð¡¢¥µ¡¼¥Ð¡¼Â¦¤Ç¤Î read ¤ÏȯÀ¸¤·¤Ê¤¤¤Î¤Ç st_atime ¤Î¹¹¿·¤Ï¹Ô¤Ê¤ï¤ì¤«¤é¤À¡£ UNIX ¤ÎÊý¼°¤Ç¤Ï¡¢¥¯¥é¥¤¥¢¥ó¥È¦¤Î°À­¤Î¥­¥ã¥Ã¥·¥ó¥°¤ò̵¸ú¤Ë¤¹¤ë¤³¤È¤Ç¡¢ ¤³¤ì¤òÆÀ¤ë¤³¤È¤¬¤Ç¤­¤ë¡£¤·¤«¤·¤Û¤È¤ó¤É¤Î¾õ¶·¤Ç¤Ï¤³¤ì¤Ï³¤¯¥µ¡¼¥Ð¡¼¤Î Éé²Ù¤òÁý²Ã¤µ¤»¡¢¥Ñ¥Õ¥©¡¼¥Þ¥ó¥¹¤ÎÄã²¼¤ò¤â¤¿¤é¤¹¡£

¿¤¯¤Î¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤ä¥Ç¥£¥¹¥¯¤Ï O_NONBLOCK ¤Î¼ÂÁõ¤Ï¤·¤Ê¤¯¤Æ¤âºÑ¤à¤¯¤é¤¤¤Ë½½Ê¬¤Ë¹â®¤Ç¤¢¤ë¤È¹Í¤¨¤é¤ì¤Æ¤¤¤ë¡£ ¤½¤ì¤Ç¤½¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë¤ä¥Ç¥£¥¹¥¯¤Ë¤Ï O_NONBLOCK ¤Ï ÍøÍѤǤ­¤Ê¤¤¤«¤â¤·¤ì¤Ê¤¤¡£

´ØÏ¢¹àÌÜ

close(2), fcntl(2), ioctl(2), lseek(2), open(2), pread(2), readdir(2), readlink(2), readv(2), select(2), write(2), fread(3)