Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ close(S) — OpenDesktop Software Development System 3.0.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

creat(S)

dup(S)

exec(S)

fcntl(S)

Intro(S)

open(S)

pipe(S)

signal(S)

sigset(S)


 close(S)                       6 January 1993                       close(S)


 Name

    close - close a file descriptor

 Syntax


    cc  . . .  -lc


    int close (fildes)
    int fildes;


 Description

    The close function breaks the connection between a file descriptor and an
    open file, and frees the file descriptor for use with some other file.

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

    If a STREAMS file is closed, and the calling process had previously
    registered to receive a SIGPOLL signal (see signal(S) and sigset(S)) 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 fildes to be dismantled.  If ONONBLOCK is not set
    and there have been no signals posted for the stream, close waits up to
    15 seconds, for each module and driver, for any output to drain before
    dismantling the stream.  If the ONONBLOCK flag is set or if there are
    any pending signals, close does not wait for output to drain and disman-
    tles the stream immediately.

    The named file is closed unless one or more of the following is true:

    [EBADF]     The fildes argument is not a valid open file descriptor.

    [EINTR]     A signal was caught during the close system call.

    [ENOLINK]   fildes is on a remote machine and the link to that machine is
                no longer active.


 Diagnostics

    Upon successful completion, a value of 0 is returned.  Otherwise, a value
    of -1 is returned, and errno is set to indicate the error.

 Example

    The function is typically used to close files that are no longer needed.
    For example, the following program fragment closes the standard input if
    the argument count is greater than 1.

       int fd;

       if (argc >1)
               close(0);

    Note that all open files in a program are closed when a program ter-
    minates normally or when the exit function is called, so no explicit call
    to close is required.

 See also

    creat(S), dup(S), exec(S), fcntl(S), Intro(S), open(S), pipe(S),
    signal(S), sigset(S)

 Standards conformance

    close is conformant with:
    AT&T SVID Issue 2;
    X/Open Portability Guide, Issue 3, 1989;
    Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2);
    IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C
    Language] (ISO/IEC 9945-1);
    and NIST FIPS 151-1.


Typewritten Software • bear@typewritten.org • Edmonds, WA 98026