Middleware, development tools, realtime operating system
software and services for superior embedded design


Home
QNX Community Resources
Developer Support
QNX Documentation Library
QNX Developer Support

QNX Developer Support

QNX Software Systems
Developer Resources
Blogs
Board support packages
Foundry27 projects
Forums
Hardware support listing
Online video tutorials
Product documentation
Technical Articles

[Previous] [Contents] [Index] [Next]

close()

Close a file

Synopsis:

#include <unistd.h>

int close( int filedes );

Arguments:

filedes
The file descriptor of the file you want to close. This can be a file descriptor returned by a successful call to accept(), creat(), dup(), dup2(), fcntl(), modem_open(), open(), shm_open(), socket() or sopen().

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The close() function closes the file specified by the given file descriptor.

Returns:

Zero for success, or -1 if an error occurs (errno is set).

Errors:

EBADF
Invalid file descriptor filedes.
EINTR
The close() call was interrupted by a signal.
EIO
An I/O error occurred while updating the directory information.
ENOSPC
A previous buffered write call has failed.
ENOSYS
The close() function isn't implemented for the filesystem specified by filedes.

Examples:

#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>

int main( void )
{
    int filedes;

    filedes = open( "file", O_RDONLY );
    if( filedes != -1 ) {
        /* process file */
        close( filedes );

        return EXIT_SUCCESS;
    }

    return EXIT_FAILURE;
}

Classification:

POSIX 1003.1

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

accept(), creat(), dup(), dup2(), errno, fcntl(), modem_open(), open(), shm_open(), socket(), sopen()


[Previous] [Contents] [Index] [Next]