mirror of
https://git.planet-casio.com/Lephenixnoir/gint.git
synced 2025-04-16 16:06:53 +02:00
24 lines
455 B
C
24 lines
455 B
C
#include <unistd.h>
|
|
#include <gint/fs.h>
|
|
#include <errno.h>
|
|
|
|
ssize_t pread(int fd, void *buf, size_t size, off_t offset)
|
|
{
|
|
off_t current = lseek(fd, 0, SEEK_CUR);
|
|
if(current == (off_t)-1)
|
|
return (ssize_t)-1;
|
|
|
|
ssize_t rc = -1;
|
|
|
|
if(lseek(fd, offset, SEEK_SET) == (off_t)-1)
|
|
goto end;
|
|
|
|
rc = read(fd, buf, size);
|
|
if(rc < 0)
|
|
goto end;
|
|
|
|
end:
|
|
/* At the end, always try to restore the current position */
|
|
lseek(fd, current, SEEK_SET);
|
|
return rc;
|
|
}
|