Currently, _file in /usr/include/stdio.h is declared as an
unsigned char, which limits the number of file descriptors
per process to 256 (2^8 = 256). ISV's such as Sybase need
to have that limit increased to 2048 for user connections
to their database server. Therefore, _file should be de-
clared as an unsigned long instead of an unsigned char.
The description field as copied from bug report 1212385 follows:
Although the limit for file descriptors is 1024, you cannot open more than 256 fd's
using stdio.h. _file is declared as an unsigned char in /usr/include/stdio.h which
restricts the access to file descriptors to 256.
Reproduce by compiling and running the following program:
#include <stdio.h>
main()
{
FILE *fd;
int i;
char buf[10];
printf("Could not open ");
for(i=3; i < 1024; i++)
{
sprintf(buf, "xx%d", i);
fd = fopen(buf, "w");
if (fd <= (FILE *)0)
{
printf("%d ",i);
}
}
printf("\\n");
}
1) Documentation bug: man page for fopen() needs to directly acknowledge its
limitation to file descriptors 0-255 or at least direct the user to the stdio
man page for information about limitations.
2) Code bug: fopen() provides no identification of error when it hits the
above limitation:
errono is set to 0 when fopen() fails.