tags:

views:

49

answers:

2

For instance if I called WriteFile to the end of a file, and later I wanted to delete the written bytes, how could I do this? Do I have to read the file's contents into a buffer, re-create the file, and write the desired bytes, or is there an easier way?

+3  A: 

Seek to the file position you want to truncate from (if you're not already there), then call the aptly-named SetEndOfFile() function.

Frédéric Hamidi
A: 

On Posix complient systems (Unix, Linux and others (Windows 7 has the Posix layer again))

int truncate(const char *path, off_t length); 
int ftruncate(int fildes, off_t length);

http://www.opengroup.org/onlinepubs/009695399/functions/truncate.html

http://www.opengroup.org/onlinepubs/009695399/functions/ftruncate.html

tristopia