minix/lib/libc/posix/pread.c
Ben Gras 7c4cd0e6b0 - new pread(), fnmatch() calls
- split sprintf() and snprintf() to solve a linking problem when
   compiling an application
2010-02-25 17:08:08 +00:00

27 lines
414 B
C

#include <lib.h>
#include <unistd.h>
ssize_t pread(int fd, void *buffer, size_t nbytes, off_t where)
{
off_t here;
ssize_t r;
if((here = lseek(fd, 0, SEEK_CUR)) < 0)
return -1;
if(lseek(fd, where, SEEK_SET) < 0)
return -1;
if((r=read(fd, buffer, nbytes)) < 0) {
int e = errno;
lseek(fd, here, SEEK_SET);
errno = e;
return -1;
}
if(lseek(fd, here, SEEK_SET) < 0)
return -1;
return r;
}