1

Is it possible in C++ to somehow get a pointer to the beginning of an opened file so that it ( the pointer ) can be passed to the unix write function together with the size of the file?

Just to be clear: I want to pass the whole file to a write-like function - how do I do this?

4

2 回答 2

4

你可以只mmap()写完整的文件,然后把这个指针传给write。您必须使用open(), 来打开它,但不是fopen()

于 2009-08-27T06:45:54.640 回答
4

sendfile() is specifically for this purpose on POSIX platforms when sending over the network, and the kernel handles the intricacies of doing it.

于 2009-08-27T06:58:36.300 回答