The following program:
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main(int argc, char **argv) {
int fd;
char c;
if ((fd = open("/dev/zero", 0)) < 0) {
err(1, NULL);
}
printf("F_GETFL before: %i\n", fcntl(fd, F_GETFL));
if ((fcntl(fd,F_SETFL, O_NONBLOCK)) == -1) {
printf("F_GETFL after: %i\n", fcntl(fd, F_GETFL));
err(1, NULL);
}
if ((read(fd, &c, 1)) < 0) {
err(1, NULL);
}
return c;
}
has the following output:
F_GETFL before: 0
F_GETFL after: 4
test_zero_nonblock: Operation not supported by device
I think this may be a bug. I'm guessing either:
1) fcntl(fd,F_SETFL, O_NONBLOCK) shouldn't fail, because
open("/dev/zero", O_NONBLOCK) doesn't fail; or
2) fcntl should not modify the flags for the file descriptor if it does
fail.
or both.
After more testing, it appears any fcntl/F_SETFL call on /dev/zero
fails, even if you are setting the flags to the same value.
One of ruby's specs fails due to this issue.
Thanks,
Jeremy