terminating a file
Does anyone know what function call I need to make to end a file early? For example, if I have a file that is 10 bytes long, and I'm at byte 7, is there a way to end the file now and let the last 3 bytes be ignored?
any help would be greatly appriciated |
Well, ASCII 26 is CTRL-Z aka EOF, but I'm not sure if that would work in this situation.
Personally, I'd read the file into mem, close it, truncate data in mem, then open file for write (thereby clobbering old data) and write data. |
I agree with the "chrism01" that the normal and very typical way to do that is to read the 7 bytes in a buffer and copy to a new file and delete this one.
|
truncate(2) truncates a file on disc;
ftruncate(2) truncates a file opened for writing. |
thanks for all of the replys. The reason i didn't want to read the data into memory is that file (in this application) would be way to large. I still could have acheved the same effect with a buffer, but i was wondering if there was a wheel already invented. Therefore, I'm going to go with addy86's solution with truncate and ftruncate. Those are actually really useful functions. I'm suprised i'd never heard of them.
Thanks for the help... |
All times are GMT -5. The time now is 08:02 AM. |