Close a file
#include <unistd.h> int close( int filedes );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The close() function closes the file specified by the given file descriptor.
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 |