diff --git a/src/io.c b/src/io.c index d22fca8..6b3f58a 100644 --- a/src/io.c +++ b/src/io.c @@ -10,19 +10,15 @@ struct pang_io { }; ssize_t pang_write(struct pang_io *io, off_t offset, const void *buf, size_t count) { - if (-1 == lseek(io->fd, offset, SEEK_SET)) - return -1; - return write(io->fd, buf, count); + return pwrite(io->fd, buf, count, offset); } ssize_t pang_read(struct pang_io *io, off_t offset, void *buf, size_t count) { - if (-1 == lseek(io->fd, offset, SEEK_SET)) - return -1; - return read(io->fd, buf, count); + return pread(io->fd, buf, count, offset); } struct pang_io *pang_open(const char *pathname) { - int fd = open(pathname, O_RDWR | O_TRUNC | O_CREAT, 0777); + int fd = open(pathname, O_RDWR | O_CREAT, 0777); if (-1 == fd) return NULL; struct pang_io *io = malloc(sizeof(struct pang_io));