Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fread错误使用 #53

Open
DongwenHuang opened this issue Sep 1, 2015 · 1 comment
Open

fread错误使用 #53

DongwenHuang opened this issue Sep 1, 2015 · 1 comment

Comments

@DongwenHuang
Copy link

int ret = fread(data, size, 1, file_);
if (size == 0 || ret == 0) return false;
if (ret == -1) {}

上面是你的filesystem.cc的代码,这段代码有错误,fread不会返回-1,当返回0的时候应该用feof,ferror来检测是什么原因导致返回的数目比1少,发生错误到关闭

引用下面这段话:
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.
@liyichao
Copy link
Contributor

liyichao commented Dec 5, 2016

Thanks, can you create a pull request ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants