What calls best emulate pread/pwrite in MSVC 10?
A:
At the C runtime library level, look at fread, fwrite and fseek.
At the Win32 API level, have a look at ReadFile, WriteFile, and SetFilePointer. MSDN has extensive coverage of file I/O API's.
Note that both ReadFile and WriteFile take an OVERLAPPED struct argument, which lets you specify a file offset. The offset is respected for all files that support byte offsets, even when opened for synchronous (i.e. non 'overlapped') I/O.
Depending on the problem you are trying to solve, file mapping may be a better design choice.
Oren Trutner
2010-10-04 05:27:22
With the exception of file mapping, these calls are not atomic with respect to file position. I think file mapping is a little far afield, but it's a consideration.
Matt Joiner
2010-10-04 13:05:51
ReadFile/WriteFile take an OVERLAPPED argument, which lets you specify the file offset you're interested in. Don't let the OVERLAPPED type name mislead you -- the offset is respected even for files opened for synchronous I/O.
Oren Trutner
2010-10-04 18:32:13