File Descriptors

Overview

The classes file_descriptor_source, file_descriptor_sink and file_descriptor provide file access via operating system file handles or file descriptors. These Devices behave much like the File Wrappersbasic_file_source, basic_file_sink and basic_file, with the following important differences:

A file descriptor Device may be constructed from a file descriptor which is already open.

When a file descriptor Device is copied, the result represents the same underlying file descriptor. The underlying file descriptor is not duplicated.

The classes file_descriptor supports 64-bit seek offsets whenever they are supported by the underlying operating system or runtime library. Currently, file descriptor Devices may not work corectly with file descriptors opened in non-blocking mode.

Line-ending conversion can be provided, if desired, using the class newline_filter. Wide-character versions of the file descriptor Devices may be defined as follows, using the template code_converter:

The first member constructs a file_descriptor_source to access the file with the given pathname. The parameter mode has the same interpretation as (mode | std::ios_base::in) in std::basic_filebuf::open.[1]

The second member constructs a file_descriptor_source to access the file with the given operating system or runtime-library file descriptor. If the second argument is true, the file descriptor is closed when the file_descriptor_source being constructed — or one of its copies — is closed.

The third member is the same as the second, except that it accepts a Windows file handle instead of a file descriptor. If the second argument is true, the file descriptor is closed when the file_descriptor_source being constructed — or one of its copies — is closed.

file_descriptor_source::is_open

bool is_open() const;

Returns true if the underlying file was opened successfully.

Class file_descriptor_sink

Description

Model of Sink providing write-only access to a file through an operating system file descriptor.

The first member constructs a file_descriptor_sink to access the file with the given pathname. The parameter mode has the same interpretation as (mode | std::ios_base::out) in std::basic_filebuf::open.[1]

The second member constructs a file_descriptor_sink to access the file with the given operating system or runtime-library file descriptor. If the second argument is true, the file descriptor is closed when the new file_descriptor_sink — or one of its copies — is closed.

The third member is the same as the second, except that it accepts a Windows file handle instead of a file descriptor. If the second argument is true, the file descriptor is closed when the new file_descriptor_sink — or one of its copies — is closed.

file_descriptor_sink::is_open

bool is_open() const;

Returns true if the underlying file was opened successfully.

Class file_descriptor

Description

Model of SeekableDevice providing read-write access to a file through an operating system file descriptor.

The first member constructs a file_descriptor to access the file with the given pathname. The parameter mode has the same interpretation as in std::basic_filebuf::open.[1]

The second member constructs a file_descriptor to access the file with the given operating system or runtime-library file descriptor. If the second argument is true, the file descriptor is closed when the new file_descriptor — or one of its copies — is closed.

The third member is the same as the second, except that it accepts a Windows file handle instead of a file descriptor. If the second argument is true, the file descriptor is closed when the new file_descriptor — or one of its copies — is closed.