I am interested in knowing the valid values ββthat I can expect for a file descriptor.
Please let me clarify a bit. I know that, for example, when I use #include <unistd.h> on my Linux system, then opening the file for reading is called:
int fileDescriptor; fileDescriptor = open("/some/filename",O_RDONLY);
an error may occur and as a result I get -1.
Accidentally (- 1) the negative must have some special meaning. Is all the other values ββvalid file descriptors? i.e. negative like -2 and -1023?
Assuming int is 4 bytes ( sizeof(int)==4 ), then <
(-1) = 10000000 0000000 00000000 00000001
will be the only detectable invalid file descriptor? Others would like to:
(0) = 00000000 0000000 00000000 00000000(-2) = 10000000 0000000 00000000 00000010(2) = 00000000 0000000 00000000 00000010
to be okay? Since a file descriptor can store 4 bytes, I could have a maximum (2 ^ (8 * 4) -1) of valid file descriptors, and therefore this would be the maximum number of files that I can open, right?
Repeat again:
What should I expect a (valid) file descriptor?
any value but -1?
c linux validation file-descriptor
humanityANDpeace
source share