zbigh
zbigh

Reputation: 467

How to get a pointer to the beginning of a file in C++

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?

Upvotes: 1

Views: 813

Answers (2)

Will
Will

Reputation: 75673

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

Upvotes: 4

Anteru
Anteru

Reputation: 19434

You can just mmap() the complete file, and then pass this pointer to write. You'll have to open it using the open(), not fopen() though.

Upvotes: 4

Related Questions