Closes a file.
#include <io.h> | Required only for function declarations | |
#include <errno.h> |
int _close( int handle );
handle | Handle referring to open file |
The _close function closes the file associated with handle.
The _close function returns 0 if the file was successfully closed. A return value of –1 indicates an error, and errno is set to EBADF, indicating an invalid file-handle argument.
Standards:UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
Use _close for compatibility with ANSI naming conventions of non-ANSI functions. Use close and link with OLDNAMES.LIB for UNIX compatibility.
_chsize, _creat, _dup, _dup2, _open, _unlink
/* OPEN.C: This program uses _open to open a file named OPEN.C for input
* and a file named OPEN.OUT for output. The files are then closed.
*/
#include <fcntl.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <io.h>
#include <stdio.h>
void main( void )
{
int fh1, fh2;
fh1 = _open( "OPEN.C", _O_RDONLY );
if( fh1 == -1 )
perror( "open failed on input file" );
else
{
printf( "open succeeded on input file\n" );
_close( fh1 );
}
fh2 = _open( "OPEN.OUT", _O_WRONLY | _O_CREAT, _S_IREAD | _S_IWRITE );
if( fh2 == -1 )
perror( "open failed on output file" );
else
{
printf( "open succeeded on output file\n" );
_close( fh2 );
}
}
open succeeded on input file
open succeeded on output file