I\'m trying to read binary data in a C program with read() but EOF test doesn\'t work. Instead it keeps running forever reading the last bit of the file.
#in
You must check for errors. On some (common) errors you want to call read again!
If read() returns -1 you have to check errno
for the error code. If errno equals either EAGAIN
or EINTR
, you want to restart the read()
call, without using its (incomplete) returned values. (On other errors, you maybe want to exit the program with the appropriate error message (from strerror))
Example: a wrapper called xread() from git's source code