From Bugzilla Helper: User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 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. Code snippet: m_fd = open(filename.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); if (m_fd == -1) return -1; do { char arr[2000]; error = read(m_fd, arr, 4); } while (error == EINTR); Version-Release number of selected component (if applicable): kernel-2.6.9-22.0.1.EL How reproducible: Always 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" Actual Results: Got 0. Expected Results: Got 4. Additional info:
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.