Function pread for windows

The pread function is used to read N bytes from a stream/file from a given offset point. It is natively present on linux/unix but not on windows. However its easy to implement it on windows using the lseek and read functions. Here is an example

#include <io.h>
#include <stdio.h>

int pread(unsigned int fd, char *buf, size_t count, int offset)
{
	if (_lseek(fd, offset, SEEK_SET) != offset) {
		return -1;
	}
	return read(fd, buf, count);
}

Resources

http://man7.org/linux/man-pages/man2/pread64.2.html
http://man.he.net/?topic=pread§ion=all







Last Updated On : 13th February 2012

Subscribe to get updates delivered to your inbox

Leave a comment