[Previous]
[Contents]
[Next]

close()

close a file at the operating-system level

Synopsis:

#include <unistd.h>
int close( int filedes );

Description:

The close() function closes a file at the operating-system level. The filedes value is the file descriptor returned by a successful execution of one of the creat(), dup(), dup2(), fcntl(), open() or sopen() functions.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EBADF
The filedes argument is not a valid file descriptor.
EINTR
The close() function was interrupted by a signal.
EIO
An I/O error occurred while updating the directory information.
ENOSPC
A previous buffered write call has failed.

Examples:

#include <fcntl.h>
#include <unistd.h>

void main()
  {
    int filedes;

    filedes = open( "file", O_RDONLY );
    if( filedes != -1 ) {
      /* process file */
      close( filedes );
    }
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

creat(), dup(), dup2(), errno, fcntl(), open(), sopen()


[Previous]
[Contents]
[Next]