Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 2 KB

File metadata and controls

63 lines (44 loc) · 2 KB
description title ms.date api_name api_location api_type topic_type f1_keywords helpviewer_keywords ms.assetid
Learn more about: _close
_close
4/2/2020
_close
_o__close
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-stdio-l1-1-0.dll
DLLExport
apiref
_close
_close function
close function
files [C++], closing
4708a329-8acf-4cd9-b7b0-a952e1897247

_close

Closes a file.

Syntax

int _close(
   int fd
);

Parameters

fd
File descriptor referring to the open file.

Return value

_close returns 0 if the file was successfully closed. A return value of -1 indicates an error.

Remarks

The _close function closes the file associated with fd.

The file descriptor and the underlying OS file handle are closed. Thus, it isn't necessary to call CloseHandle if the file was originally opened using the Win32 function CreateFile and converted to a file descriptor using _open_osfhandle.

This function validates its parameters. If fd is a bad file descriptor, the invalid parameter handler is invoked, as described in Parameter validation. If execution is allowed to continue, the functions returns -1 and errno is set to EBADF.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Requirements

Routine Required header Optional header
_close <io.h> <errno.h>

For more compatibility information, see Compatibility.

Example

See the example for _open.

See also

Low-level I/O
_chsize
_creat, _wcreat
_dup, _dup2
_open, _wopen
_unlink, _wunlink