Insert EOF marker into file

Z

zambak

Hi

I have decompression function which opens compressed input file,
grabs the header containing the original file size and the date compressed
and
starts decompressing data into output file....
Because of the padding, decompessed file may be larger than original by up
to 7 bytes....


What I want to do is to insert EOF at the position == original file size
into output file...
So after processing I want to do

// set the position in output file to original file size
fseek(out_file, orig_size, SEEK_SET);
// write EOF in that position
// ???????????????????????????????? fwrite maybe???
// close output file
fclose(out_file);


Question is how do I "inject" EOF at the position i want....What is the code
for it???

Thanks
zambak
 
G

glen herrmannsfeldt

zambak said:
Hi

I have decompression function which opens compressed input file,
grabs the header containing the original file size and the date compressed
and
starts decompressing data into output file....
Because of the padding, decompessed file may be larger than original by up
to 7 bytes....


What I want to do is to insert EOF at the position == original file size
into output file...
So after processing I want to do

Some systems may have ftruncate(), but it is not standard C.

Best bet is to not write more than the length of file that you want.

-- glen
 
D

Derk Gwen

# Question is how do I "inject" EOF at the position i want....What is the code
# for it???

There is no C standard for reducing the size of an existing file. If you
create a new file, the operating system of any quality will not allocate
much more space than the highest offset you write.

Why are you decompressing into a file? You're going to destroy whatever
is in the file from where you start writing. You can accomplish the same
in standard C by openning what was the output as input, open a new output file,
copy the initial portion. (If the decompression write starts at the beginning,
you actually don't even have an initial portion to copy.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top