close

Closes a file or stream

Local Servers:blocking
Remote Servers:blocking
Classification:POSIX
Platform:NLM
Service:Operating System I/O

Syntax

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

Parameters

handle
(IN) Specifies a file handle.

Return Values

When an error occurs while closing the file, a value of -1 is returned. Otherwise, a value of 0 is returned.

If an error occurs, errno is set to:

4

EBADF

Bad file number.

If the function does not complete successfully, NetWareErrno is set.

Remarks

This function also works on the DOS partition.

The handle value is the file handle returned by a successful execution of the open, sopen, or creat function. After a file is closed, the file handle is no longer valid and should not be reused.

UNIX STREAMS: If a Stream file is closed and the calling process had previously registered to receive a SIGPOLL signal for events associated with that file, the calling process is unregistered for events associated with the file.

The last close for a Stream causes the Stream associated with handle to be dismantled.

  • If O_NDELAY is not set and no signals have been posted for the Stream, the close function waits up to 15 seconds for each module and driver and for any output to drain before dismantling the Stream.
  • If the O_NDELAY flag is set or if there are any pending signals, the close function does not wait for output to drain and dismantles the Stream immediately.

See Also

creat, dup, dup2, open, sopen