How can I truncate a file with the given size and if the filesize is smaller then the given size how can I enlarge the existing file size with 0 padding.
Thanks for the help.
How can I truncate a file with the given size and if the filesize is smaller then the given size how can I enlarge the existing file size with 0 padding.
Thanks for the help.
To skrink use truncate()
or ftruncate()
, to enlarge use lseek()
/fseek()
followed by write()
/fwrite()
ing one byte.
This may help you with truncation:
And I do not think you can enlarge a file without some kind of padding (it depends on how you view "padding").
It has been solved in this How to truncate a file in C?
Basically, you can use these two functions:
#include <unistd.h>
int ftruncate(int fildes, off_t length);
int truncate(const char *path, off_t length);