If you use fseek
to go past the end of a file and then append data after the EOF, would the data in between the EOF and what you wrote be undefined?
For example in the code below, would there be 10 bytes of undefined data in the written file because of randomLengthPastEOF
?
unsigned char *someText= "ExampleText";
int length = 11;
int randomLengthPastEOF = 10;
FILE *output = fopen("/Example/FilePath", "wb");
fseek(input, randomLengthPastEOF ,SEEK_END);
fwrite(someText, 1, length, output);
I can't find a reference any where to what might happen so I assume it is undefined.
POSIX defines data in between to be zero bytes: http://www.unix.com/man-page/POSIX/3posix/fseek/
The fseek() function shall allow the file-position indicator to be set beyond the end of existing data in the file. If data is later written at this point, subsequent reads of data in the gap shall return bytes with the value 0 until data is actually written into the gap.