I have the following code:
int main(int argc,char *argv[]){
FILE *fp;
if(argc != 2){
perror("Please specify a file");
return 1;
}
if((fp=fopen(argv[1], "rb")) == 0){
perror("File not found!");
return 2;
}
int a = fseek(fp, 1000, SEEK_CUR);
if(a<0){
printf("fail\n");
}
fclose(fp);
return 0;
}
When I call this with an empty binary file, no error occurs, eve though I would expect fseek() to return with -1. Does anyone know why is this not happening?
From the documentation of fseek
POSIX allows seeking beyond the existing end of file. If an output is performed after this seek, any read from the gap will return zero bytes. Where supported by the filesystem, this creates a sparse file.