pread

å称
     read, readv, pread — å¥åãèªã¿åã

ã©ã¤ãã©ãª
     Standard C Library (libc, -lc)

æ¸å¼
     <sys/types.h> <sys/uio.h> <unistd.h> ssize_t read(int d, void *buf,
     size_t nbytes) ssize_t readv(int d, const struct iovec *iov, int iovcnt)
     ssize_t pread(int d, void *buf, size_t nbytes, off_t offset)

解説
     read() ã·ã¹ãã ã³ã¼ã«ã¯ãè¨è¿°å d ã§åç§ããããªãã¸ã§ã¯ããã buf ãæããããã¡ã¸
     nbytes ã®ãã¼ã¿ãèªã¿åããã¨ãã¾ãã readv()
     ã·ã¹ãã ã³ã¼ã«ã¯åæ§ã®å¦çãå®è¡ãã¾ãããéå iov : iov[0], iov[1], ...,
     iov[iovcnt-1] ã®ã¡ã³ãã§æå®ããã iovcnt åã®ãããã¡ã«å¥åãã¼ã¿ãåæ£ããã¾ãã pread()
     ã·ã¹ãã ã³ã¼ã«ã¯åæ§ã®æ©è½ãå®è¡ãã¾ããã ãã¡ã¤ã«åã®æå®ã®ä½ç½®ããèªã¿åã£ãå¾ã
     ãã¡ã¤ã«ãã¤ã³ã¿ãå¤æ´ãã¾ããã

     readv() ã«å¯¾ãã iovec æ§é ä½ã¯æ¬¡ã®ããã«å®ç¾©ããã¾ã:

           struct iovec {
                   void   *iov_base;  /* ãã¼ã¹ã¢ãã¬ã¹ */
                   size_t iov_len;    /* é·ã */
           };

     iovec ã®åã¨ã³ããªã¯ããã¼ã¿ãéç½®ããã¹ãã¡ã¢ãªé åã®ãã¼ã¹ã¢ãã¬ã¹ã¨
     é·ããæå®ãã¦ãã¾ãã readv()
     ã·ã¹ãã ã³ã¼ã«ã¯ã次ã®ã¨ã³ããªã«é²ãåã«å¿ãé åãå®å¨ã«æºããã¾ãã

     ã·ã¼ã¯å¯è½ãªãªãã¸ã§ã¯ãä¸ã§ã¯ read() 㯠d
     ã«çµã³ä»ãããããã¤ã³ã¿ãæå®ããä½ç½®ããéå§ãã¾ã (lseek(2) ãåç§)ã read()
     ããã®æ»ãæã«ããã¤ã³ã¿ã¯å®éã«èªã¿åããããã¤ãæ°ã ãå¢å ããããã¾ãã

     ã·ã¼ã¯ã§ããªããªãã¸ã§ã¯ãã¯å¿ãç¾å¨ã®ä½ç½®ããèªã¿åããã¾ãã
     ãã®ãããªãªãã¸ã§ã¯ãã«çµã³ä»ãããããã¤ã³ã¿ã®å¤ã¯æªå®ç¾©ã§ãã

     å¦çãæåããã¨ã read(), readv() ããã³ pread() ã¯ãå®éã«èª‐
     ã¿åãããããã¡åã«éç½®ããããã¤ãæ°ãè¿ãã¾ãã è¨è¿°åãé常ãã¡ã¤ã«ãåç§ãã¦ããã
     ãã¡ã¤ã«ã®çµç«¯ã¾ã§ã«ååãªéã®ãã¤ããããã°ã ã·ã¹ãã ã¯è¦æ±ããããã¤ãæ°ãèª‐
     ã¿åããã¨ãä¿è¨¼ãã¾ããã ä»ã®ã±ã¼ã¹ã§ã¯ããã§ã¯ããã¾ããã

æ»ãå¤
     æ£å¸¸ã«å®äºããã¨ãå®éã«èªã¿åããããã¤ãæ°ãè¿ããã¾ãã ãã¡ã¤ã«çµäº (EOF) ãèª‐
     ã¿åããã㨠0 ãè¿ããã¾ãã ããã§ãªãå ´å㯠-1 ãè¿ãããã¨ã©ã¼ã示ãããã«ã°ãã¼ãã«å¤æ°
     errno ãè¨å®ããã¾ãã

ã¨ã©ã¼
     read(), readv() ããã³ pread() ã·ã¹ãã ã³ã¼ã«ã¯æ¬¡ã®å ´åãé¤ãã¦æ‐
     £å¸¸ã«å®äºãã¾ã:

     [EBADF]            d å¼æ°ã¯èªåãç¨ã«ãªã¼ãã³ãããæå¹ãªãã¡ã¤ã«ã¾ãã¯
                        ã½ã±ããã®è¨è¿°åã§ã¯ããã¾ããã

     [EFAULT]           buf å¼æ°ã¯ããã‐
                        ã»ã¹ã«å²ãå½ã¦ãããã¢ãã¬ã¹ç©ºéã®ç¯å²å¤ãæãã¦ãã¾ãã

     [EIO]              ãã¡ã¤ã«ã·ã¹ãã ããèªã¿åã£ã¦ããéã«å¥åºåã¨ã©ã¼ãçºçãã¾ããã

     [EINTR]            ãã¼ã¿ãå°çããåã«ãã·ã°ãã«ã®ééã«ããä½éããã¤ã¹ããã®èªåãã
                        å²ãè¾¼ã¾ãã¾ããã

     [EINVAL]           d ã«çµã³ä»ãããããã¤ã³ã¿ãè² ã§ããã

     [EAGAIN]           ãã¡ã¤ã«ã¯éããããã³ã°å¥åºåã¨ãã¼ã¯ããã¦ããã èª‐
                        åãã®æºåãã§ãããã¼ã¿ãããã¾ããã

     [EISDIR]           ãã¡ã¤ã«è¨è¿°åãããã£ã¬ã¯ããªä¸ã§ã®æ®éã®èª‐
                        ã¿è¾¼ã¿æä½ã許å¯ãã¦ããªã ãã¡ã¤ã«ã·ã¹ãã  (ä¾ãã° NFS)
                        ã«å±ãã¦ãããã£ã¬ã¯ããªã« é¢é£ä»ãããã¦ãã¾ãã

     [EOPNOTSUPP]       ãã¡ã¤ã«è¨è¿°åããæ®éã®èª‐
                        ã¿è¾¼ã¿æä½ã許å¯ãã¦ããªããã¡ã¤ã«ã·ã¹ãã ããã³
                        ãã¡ã¤ã«ã¿ã¤ãã«é¢é£ä»ãããã¦ãã¾ãã

     [EOVERFLOW]        ãã¡ã¤ã«è¨è¿°åãæ®éã®ãã¡ã¤ã«ã«é¢é£ä»ãããã¦ãã¦ã nbytes ã 0
                        ããã大ããã offset ããã¡ã¤ã«ã®æ«å°¾ã®åã«ãããã㤠offset
                        ããã®ãã¡ã¤ã«ã·ã¹ãã ã«åã¾ããªãã»ããã®æ大å¤ä»¥ä¸ã§ãã

     ããã«ã readv() ã¯æ¬¡ã®ã¨ã©ã¼ã®ãã¡ã® 1 ã¤ãè¿ããã¨ãããã¾ã:

     [EINVAL]           iovcnt å¼æ°ã 0 以ä¸ã§ããããã¾ã㯠IOV_MAX
                        ãã大ãããªã£ã¦ãã¾ãã

     [EINVAL]           iov éåã®ä¸ã® iov_len å¤ã® 1 ã¤ãè² ã§ããã

     [EINVAL]           iov éåã®ä¸ã® iov_len å¤ã®åè¨ã 32 ãããæ´æ°ããªã¼ããã‐
                        ã¼ãã¾ããã

     [EFAULT]           iov ã®ä¸é¨ãããã‐
                        ã»ã¹ã«å²ãå½ã¦ãããã¢ãã¬ã¹ç©ºéã®ç¯å²å¤ãæãã¦ãã¾ãã

     pread() ã·ã¹ãã ã³ã¼ã«ã¯æ¬¡ã®ã¨ã©ã¼ãè¿ããã¨ãããã¾ã:

     [EINVAL]           offset ã®å¤ãè² ã§ãã

     [ESPIPE]           ãã¡ã¤ã«è¨è¿°åããã¤ããã½ã±ãããã¾ã㯠FIFO
                        ã«çµã³ä»ãããã¦ãã¾ãã

é¢é£é ç®
     dup(2), fcntl(2), getdirentries(2), open(2), pipe(2), select(2),
     socket(2), socketpair(2), fread(3), readdir(3)

è¦æ ¼
     read() ã·ã¹ãã ã³ã¼ã«ã¯ ISO/IEC 9945-1:1990 (“POSIX.1”) ã«é©åãã¦ãã¾ãã
     readv() ã·ã¹ãã ã³ã¼ã«ã¨ pread() ã·ã¹ãã ã³ã¼ã«ã¯ X/Open Portability Guide
     Issue 4, Version 2 (“XPG4.2”) ã«é©åãã¦ãã¾ãã

æ´å²
     pread() é¢æ°ã¯ AT&T System V Release 4 UNIX ã§ç»å ´ãã¾ããã readv()
     ã·ã¹ãã ã³ã¼ã«ã¯ 4.2BSD ã§ç»å ´ãã¾ããã read() é¢æ°ã¯ Version 6 AT&T UNIX
     ã§ç»å ´ãã¾ããã