close -- Close a File or Socket

SYNOPSIS

 #include <unistd.h>

 int close(int fn);
 

DESCRIPTION

close closes a socket or a file opened for UNIX style I/O. fn is the file descriptor for the file or socket.

When close is called for an HFS file, any record locks for the file owned by the closing process are released. When the last open descriptor for a pipe or FIFO file is closed, any remaining data are lost. Also, when the last open descriptor for a file is closed, if its link count is now zero, the file is inaccessible and its disk space is released.

For a socket, close indicates that the program is finished using the socket; close breaks the connection between the socket descriptor and the socket. The status of undelivered output data is determined by the SO_LINGER socket option, as defined with the setsockopt function.

RETURN VALUE

close returns 0 if it is successful or - 1 if it is unsuccessful. Even if close returns - 1, any further attempts to use the file descriptor (unless it is reopened) will fail.

IMPLEMENTATION

Any unclosed files and sockets are automatically closed at normal program termination.

EXAMPLE

See the example for open.

RELATED FUNCTIONS

fclose, fsync

SEE ALSO


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.