Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.


Closes a file.

int _close( 
   int fd 


File descriptor referring to the open file.

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

The _close function closes the file associated with fd.

The file descriptor and the underlying OS file handle are closed. Thus, it is not 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.


Required header

Optional header




For more compatibility information, see Compatibility in the Introduction.

See the example for _open.

Community Additions

© 2015 Microsoft