error when using fseek() function

The errors EBADF & ESPIPE occur at this fseek call. Does anybody know how to solve this problem? Thanks in advance.

toFileStream=fdopen(localFileDes,"ra+");

if(fseek(toFileStream, 0, SEEK_END)!=0){
if(errno==EBADF)
printf("errno==EBADF\n");
if(errno==EINVAL)
printf("errno==EINVAL\n");
if(errno=ESPIPE)
printf("errno==ESPIPE\n");
}

Please do not post questions in multiple forums - I deleted your other post. See the rules

Driver,

For your reference, my coe should be like this and "file1.txt" is a regular file. Can you please help me to see why error occurs in this code? thanks again.

 
localFileDes=open("file1.txt", O_RDWR|O_CREAT|O_EXCL|O_APPEND);

toFileStream=fdopen(localFileDes,"ra+");

if(fseek(toFileStream, 0, SEEK_END)!=0){
if(errno==EBADF)
printf("errno==EBADF\n");
if(errno==EINVAL)
printf("errno==EINVAL\n");
if(errno=ESPIPE)
printf("errno==ESPIPE\n");
}
 

Driver,

Thanks very much. With your help, I have solved the problem.

Ivan