Reputation: 59
...
rewind(ftmpname);
if (stat(tmpname, &st_file)==-1)
longjmp(Berror, (ETMPSTAT) );
tmpsize = st_file.st_size;
i = 0;
while (i<tmpsize)
{
n = fread(buf, 1, (READ_CONST), ftmpname );
write_byte(farch, buf, n);
i+=n;
}
...
fread
always returns 0. I don't know what's wrong. I do a rewind before, and it didn't help. Sorry for my English.
Upvotes: 0
Views: 1787
Reputation:
If you don't know what is wrong, you have to check for errors. Here is what a manual page says:
RETURN VALUE
fread() and fwrite() return the number of items successfully read or written (i.e., not the number of characters). If an error occurs, or the end-of-file is reached, the return value is a short item count (or zero).
fread() does not distinguish between end-of-file and error, and callers must use feof(3) and ferror(3) to determine which occurred.
So why don't you use those functions which tell you exactly what is wrong?
Upvotes: 2