Borland C++ reference

_close, close

raw OCR

Closes a file.

Defined in header <io.h>

Syntax

#include <io.h>
int _close(int handle);
int close(int handle);

Portability

DOSUNIXWindowsANSI CC++ only
_close ■■
close ■■■

Remarks

_close and close close the file associated with handle, a file handle obtained from a _creat, creat, creatnew, creattemp, dup, dup2, _open, or open call.

b~^

These functions do not write a Ctrl-Z character at the end of the file. If you want to terminate the file with a Cirl-Z, you must explicitly output one.

Return value

Upon successful completion, _close and close return 0. Otherwise, these functions return a value of -1.

_close and close fail if handle is not the handle of a valid, open file, and the global variable errno is set to

EBADF Bad file number

See also

Example

#include <string.h>
#include <fcntl.h>
#include <io.h>
int main(void)
{
   int handle;
   char buf[ll] =  "0123456789";

   /* create a file containing  10 bytes */
   handle = open("DUfflY.FIL", 0_CREAT);
   write(handle, buf, strlen(buf ));

   /* close the file */
   close(handle);
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `close, close` read as `_close, close`