pread.c 424 B

1234567891011121314151617181920212223
  1. #include "file.h"
  2. #ifndef lint
  3. FILE_RCSID("@(#)$File: pread.c,v 1.3 2014/09/15 19:11:25 christos Exp $")
  4. #endif /* lint */
  5. #include <fcntl.h>
  6. #include <unistd.h>
  7. ssize_t
  8. pread(int fd, void *buf, size_t len, off_t off) {
  9. off_t old;
  10. ssize_t rv;
  11. if ((old = lseek(fd, off, SEEK_SET)) == -1)
  12. return -1;
  13. if ((rv = read(fd, buf, len)) == -1)
  14. return -1;
  15. if (lseek(fd, old, SEEK_SET) == -1)
  16. return -1;
  17. return rv;
  18. }