close

Closes a file or stream.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

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

Parameters

fildes

(IN) Specifies the file descriptor for the file to close.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following values:

Decimal

Constant

Description

4

EBADF

The fildes parameter isn't a valid file descriptor.

28

EIO

An I/O error occurred while reading from or writing to the file system

63

EINTR

A signal interrupted the call.

Remarks

The fildes parameter is returned by a successful execution of the open or creat function. After a file is closed, the file descriptor is no longer valid and should not be reused. The close function deallocates the file descriptor and makes it available for return by functions that allocate file descriptors.

When all file descriptors associated with a pipe or FIFO special file are closed, any data remaining in the pipe or FIFO shall be discarded.

See Also