read() vs pread()

发布时间 2023-07-31 14:01:16作者: 球球小世界

read()

  • ssize_t read(int fd, void buf[.count], size_t count);
  • read from a file descriptor: attempts to read up to count bytes from file descriptor fd into the buffer starting at buf. On files that support seeking, the read operation commences at the file offset and the file offset is incremented by the number of bytes read. If the file offset is at or past the end of file, no bytes are read, and read() returns zero 
  • standard C library (libc, -lc)
  • #include <unistd.h>

pread()

  • ssize_t pread(int fd, void buf[.count], size_t count, off_t offset);
  • read from or write to a file descriptor at a given offset