ID Number: Q32539
5.10 6.00 6.00a 6.00ax | 5.10 6.00 6.00a
MS-DOS | OS/2
Summary:
In Microsoft C versions 5.1, 6.0, 6.0a, and 6.0ax, if you close an
unopened file with the fclose() function, a protection violation
occurs if the source is compiled in the large- or compact-memory
model. In the small-memory model, fclose() returns an error as
expected.
Closing an unopened file is a user error and is outside the functional
realm of the C run time to check the validity of file handles passed
to the fclose function. It is the responsibility of the user to ensure
that only valid file handles are passed to the fclose() function.
More Information:
The sample code below demonstrates this behavior.
Sample Code
-----------
/* Compile options needed: /AL
*/
#define INCL_BASE
#include <os2.h>
#include <stdio.h>
FILE *myfile;
int status;
main()
{
myfile = fopen("myfile.dat","r");
if (myfile == NULL) printf("file open error\n");
status = fclose(myfile);
printf("file close status = %d\n",status);
}
Additional reference words: 5.10 6.00 6.00a 6.00ax