Close a file
#include <unistd.h> int close( int filedes );
libc
The close() function closes the file specified by the file descriptor specified by filedes.
The filedes argument can be a file descriptor returned by a successful call to creat(), dup(), dup2(), fcntl(), modem_open(), open(), shm_open(), socket() or sopen() functions.
Zero for success, or -1 if an error occurs (errno is set).
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main( void )
{
int filedes;
filedes = open( "file", O_RDONLY );
if( filedes != -1 ) {
/* process file */
close( filedes );
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
| Safety: | |
|---|---|
| Cancellation point | Yes |
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |
creat(), dup(), dup2(), errno, fcntl(), modem_open(), open(), shm_open(), socket(), sopen()