Red Hat Bugzilla – Bug 213441
Reading 4 bytes from 4 byte file returns 0.
Last modified: 2007-11-30 17:07:27 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:22.214.171.124) Gecko/20060909 Firefox/126.96.36.199
Description of problem:
Reading 4 bytes from a file with length 4 should return 4. It returns 0. Tried this on NFS and local filesystem with the same results. Other size files work file (reading 3 bytes from a three byte file returns 3, reading 5 bytes from a 5 byte file returns 5, etc.). Very weird.
m_fd = open(filename.c_str(), O_CREAT | O_RDWR,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (m_fd == -1)
error = read(m_fd, arr, 4);
} while (error == EINTR);
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. Make a 4 byte file with vi or some other utility.
2. Use code similar to above.
3. Check value of "error"
That should say "Other size files work _fine_". Sorry for the typo.
The sample code above is busted. You will always go through 2 iterations of the
do..while loop when the input file is 4 bytes long (or almost always, barring no
other problems), because EINTR is defined as 4. As such, with a 4 byte input
file we wind up reading the first 4 bytes, looping back around because error ==
EINTR, then we read 0 bytes, since we're at the EOF.