Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

close - close file

&pagelevel(4)&pagelevel



Syntax

#include <unistd.h>

int close(int fildes) ; 

Description

fildes is a file descriptor obtained from a creat(), open(), dup(), fcntl or pipe()system call.
close() closes the file descriptor indicated by fildes. All existing record locks
owned by the process on the file specified with fildes are removed.

If close() is interrupted by a signal that is to be caught, it will return -1 with errno set to
EINTR, and the state of fildes is unspecified.

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

When all file descriptors associated with a file description have been closed, the file
description will be freed.

If the link count of the file is 0, when all file descriptors associated with the file are closed,
the space occupied by the file will be freed and the file will no longer be accessible.

Extension
If a stream-based file is closed and the calling process was previously registered to receive
a SIGPOLL signal (see signal() and sigset()) for events associated with that stream,
the calling process will be unregistered for events associated with the stream. The last
close() for a stream causes the stream associated with fildes to be dismantled. If
O_NDELAY and O_NONBLOCK are not set and there have been no signals posted for the
stream, close() waits for up to 15 seconds for each module and driver for any queued
output to drain before dismantling the stream. If O_NDELAY or O_NONBLOCK is set, or if there
are any pending signals, close() does not wait for the output to drain and dismantles the
stream immediately. (End) 

Return val.

0

-1

if successful. The specified file is closed.

if an error occurs; errno is set to indicate the error.

Errors

close() will fail if:

EBADF

fildes is not a valid file descriptor. or the BS2000 file is not accessible in the process.

EINTR

close() was interrupted by a signal.

Notes

If the file was opened with fopen(), it must be closed with fclose() instead of close().

When a program is terminated (normally or with exit()), all open files are automatically
closed.

The program environment determines whether close() is executed for a BS2000 or
POSIX file.

See also

creat(), dup(), fcntl(), lseek(), open(), read(), tell(), write(), unistd.h.