fopen bug in Interactive ix/386 ?
News Admin
news at edvcom.UUCP
Thu May 4 00:21:06 AEST 1989
The following pice of code hangs because it tries to fopen() more than
_NFILE files. Insteed of returning a NULL pointer after the 18th call
it returns a 'valid' descriptor and chrashes.
We are using 1.0.6.
Any suggestions, maybe someone at ico.ISC.COM reading this group ?
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
int a = 1;
int print_iob()
{
int i, cnt, file;
for (i = 0; i < _NFILE; i++)
{
cnt = _iob[ i ]._cnt;
file = _iob[ i ]._file;
printf(" FD(%d) _cnt = %d _file = %d\n",i,cnt,file);
}
}
main(argc, argv)
int argc;
char *argv[];
{
int fod[ 200 ], i, num_opens;
FILE *fd[ 200 ];
char *msg;
if (argc == 2)
num_opens = atoi(argv[ 1 ]);
else
{
printf("Specify number of open()'s \n");
exit(-1);
}
for (i = 0; i < num_opens; i++)
{
fod[ i ] = open("/dev/null",O_WRONLY);
printf("errno=%d,variable=%d,FOD(%d)=%d\n",
errno,a,i,fod[ i ]);
}
for (i = 0; i < 30; i++)
{
printf("fopen (%d): ",i);
fflush(stdout);
if (fd[ i ] = fopen("/dev/null","w"))
{
printf("errno=%d,variable=%d,FD(%d)=%d\n",
errno,a,i,fileno(fd[ i ]));
print_iob();
}
else
{
printf("fopen(%d) delivered NULL...\n",i);
break;
}
}
getchar();
exit(0);
} /* end main() */
+-----------------------------------------------------------------------------+
| G}nther Moschen | UUCP : ...!uunet!mcvax!unido!edvcom!gm |
| EDV-COMPAS Gmbh | FAX : +49 8331 84024 |
| 8940 Memmingen W-Germany | PHONE : +49 8331 86078 |
+------------------------------+----------------------------------------------+
More information about the Comp.unix.questions
mailing list