close(), exceptions and problems

Jeff Epler jepler at inetnebr.com
Tue Mar 27 21:38:28 EST 2001


On 26 Mar 2001 20:43:13 -0500, David Bolen
 <db3l at fitlinxx.com> wrote:
>Note that close() is often is the point at which buffered data is
>flushed to a file, so there are a variety of ways in which that can
>fail (I/O error, out of disk space, etc...) which will cause the
>close() to fail.

GNU Libc's documentation is fairly explicit about this:
     The normal return value from `close' is 0; a value of -1 is
     returned in case of failure.  The following `errno' error
     conditions are defined for this function:

    `EBADF'
          The FILEDES argument is not a valid file descriptor.

    `EINTR'
          The `close' call was interrupted by a signal.  *Note
          Interrupted Primitives::.  Here is an example of how to
          handle `EINTR' properly:

               TEMP_FAILURE_RETRY (close (desc));

    `ENOSPC'
    `EIO'
    `EDQUOT'
          When the file is accessed by NFS, these errors from `write'
          can sometimes not be detected until `close'.  *Note I/O
          Primitives::, for details on their meaning.

Strangely enough, the section 2 manpage omits this detail and documents
the only errno value of close as EBADF.

Jeff



More information about the Python-list mailing list