"Fossies" - the Fresh Open Source Software Archive

Member "file-5.35/src/pread.c" (15 Sep 2014, 424 Bytes) of package /linux/misc/file-5.35.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "pread.c" see the Fossies "Dox" file reference documentation.

    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 
    8 ssize_t
    9 pread(int fd, void *buf, size_t len, off_t off) {
   10     off_t old;
   11     ssize_t rv;
   12 
   13     if ((old = lseek(fd, off, SEEK_SET)) == -1)
   14         return -1;
   15 
   16     if ((rv = read(fd, buf, len)) == -1)
   17         return -1;
   18 
   19     if (lseek(fd, old, SEEK_SET) == -1)
   20         return -1;
   21 
   22     return rv;
   23 }