UNISTDX_IO_FILDES
enum pipe_flag: int

File descriptor pipe flags.

  • no_sigpipe = F_SETNOSIGPIPE
enum fd_flag: int

File descriptor flags.

  • fd_close_on_exec = FD_CLOEXEC
enum seek_origin: int

Origin of file seek operations.

  • start =SEEK_SET
  • current =SEEK_CUR
  • end =SEEK_END
  • data =SEEK_DATA
  • hole =SEEK_HOLE
class sys::file_descriptor_view
Fields
  • fd_type _fd
  • constexpr const fd_type bad

    Invalid file descriptor constant.

Methods
class sys::fildes

File descriptor wrapper.

Derived classes
Enumerations
  • enum operation
Fields
  • fd_type _fd

    File descriptor number.

  • constexpr const fd_type bad

    Invalid file descriptor constant.

Methods
  • attributes() const -> file_attributes
  • remove_attribute(c_string name) -> void
  • attribute(c_string name, const_string value, file_attribute_flags f1 = file_attribute_flags{}) -> void
  • attribute(c_string name) const -> std::string
  • call(operation op) -> void
  • template <class T>
    call(operation op, T & argument) -> void
  • status() const -> file_status

    Get file status for this file descriptor.

  • open(const char * filename, open_flag flags = open_flag(), mode_type mode = 0) -> void

    Init file descriptor by opening file filename with open flags flags and mode mode.

    bad_call

  • validate() -> void

    Check if this file descriptor exists in the kernel by trying to get its flags.

    bad_call

  • swap(fildes & rhs) -> void

    Swap with rhs.

  • operator!() const -> bool

    Returns true, if file descriptor is invalid.

  • operator bool() constexplicit

    Returns true, if file descriptor is valid.

  • operator!=(const fildes & rhs) const -> bool

    Compare file descriptors.

  • operator==(const fildes & rhs) const -> bool

    Compare file descriptors.

  • pipe_buffer_size(int new_size) -> int

    Get pipe buffer size.

    bad_call

    See
    fcntl(2)
  • pipe_buffer_size() const -> int

    Get pipe buffer size.

    bad_call

    See
    fcntl(2)
  • unsetf(fd_flag rhs) -> void

    Unset file descriptor flags.

    bad_call

    See
    fcntl(2)
  • setf(fd_flag rhs) -> void

    Set file descriptor flags.

    bad_call

    See
    fcntl(2)
  • unsetf(pipe_flag rhs) -> void

    Unset file descriptor pipe flags.

    bad_call

    See
    fcntl(2)
  • setf(pipe_flag rhs) -> void

    Set file descriptor pipe flags.

    bad_call

    See
    fcntl(2)
  • unsetf(open_flag rhs) -> void

    Unset file descriptor open flags.

    bad_call

    See
    fcntl(2)
  • setf(open_flag rhs) -> void

    Set file descriptor open flags.

    bad_call

    See
    fcntl(2)
  • fd_flags() const -> fd_flag

    Get file descriptor flags.

    bad_call

    See
    fcntl(2)
  • flags() const -> open_flag

    Get file descriptor open flags.

    bad_call

    See
    fcntl(2)
  • get() const -> fd_type

    Get bare file descriptor.

  • fd() const -> fd_type

    Get bare file descriptor.

  • sync_file_system() -> void

    Write file system cache to disk.

    bad_call

    See
    syncfs(2)
  • sync_data() -> void

    Write file data (but not metadata) from system memory to the disk.

    bad_call

    See
    fdatasync(2)
  • sync() -> void

    Write file data and metadata from system memory to the disk.

    bad_call

    See
    fsync(2)
  • truncate(offset_type length) -> void

    Set file size in bytes.

    bad_call

    See
    ftruncate(2)
  • offset(offset_type nbytes, seek_origin origin) -> offset_type

    Set the current file offset in bytes starting from the specified origin.

    bad_call

    See
    lseek(2)
  • offset(offset_type rhs) -> offset_type

    Set the current file offset in bytes.

    bad_call

    See
    lseek(2)
  • offset() const -> offset_type

    Get the current file offset in bytes.

    bad_call

    See
    lseek(2)
  • write(const io_vector * buffers, size_t n) -> ssize_t
  • read(const io_vector * buffers, size_t n) const -> ssize_t
  • write(const void * buf, size_t n) const -> ssize_t

    Write n bytes to file descriptor copying them from the array pointer by buf.

    bad_call
    if system error occurs, except std::errc::resource_unavailable_try_again and std::errc::operation_in_progress

    See
    std::errc
    See
    write(2)
  • read(void * buf, size_t n) const -> ssize_t

    Read n bytes from file descriptor and store them in the array pointed by buf.

    bad_call
    if system error occurs, except std::errc::resource_unavailable_try_again and std::errc::operation_in_progress

    See
    std::errc
    See
    read(2)
  • release() -> fd_type

    Release and return raw file descriptor. After the release you have to manually close the file descriptor.

  • close() -> void

    Close file descriptor.

    bad_call
    if close(2) system call fails

    See
    close(2)
  • operator=(fildes && rhs) -> fildes &

    Move-assignment.

  • ~fildes()

    Close file descriptor. The method ignores errors reported by close(2) system call.

  • fildes(const char * filename, open_flag flags = open_flag(), mode_type mode = 0)

    Construct file descriptor by opening file filename with open flags flags and mode mode.

  • fildes(fildes && rhs)

    Move-constructor.

  • fildes(fd_type rhs)explicit

    Construct file descriptor by wrapping rhs.

  • operator=(const fildes & rhs) -> fildes &

    Change file descriptor number of rhs to this->fd() by duplicating it with dup2(2) system call.

    bad_call

    See
    dup2(2)
  • fildes(fd_type old_fd, const fildes & new_fd, open_flag flags = open_flag::close_on_exec)
  • fildes(fildes && old_fd, const fildes & new_fd, open_flag flags = open_flag::close_on_exec)

    Rename file descriptor number of rhs to this->fd() by duplicating it with dup2(2) system call.

    bad_call

    See
    dup2(2)
  • fildes(const fildes & rhs)

    Change file descriptor number to an arbitrrary one by duplicating it with dup(2) system call.

    bad_call

    See
    dup(2)
  • fildes()
Friends
  • operator<<

    Output file descriptor number.

struct sys::is_flag< fd_flag >
Base classes
  • public std::true_type
struct sys::is_flag< pipe_flag >
Base classes
  • public std::true_type
struct sys::io_vector
Base classes
  • public iovec
Methods
  • operator=(io_vector &&) -> io_vector &
  • io_vector(io_vector &&)
  • operator=(const io_vector &) -> io_vector &
  • io_vector(const io_vector &)
  • ~io_vector()
  • io_vector()
  • empty() const -> bool
  • size() const -> size_t
  • data() const -> const void *
  • data() -> void *
  • io_vector(void * data, size_t size)
struct sys::streambuf_traits< fd_type >

Stream buffer traits for bare fd_type.

Types
  • using char_type = void

    Character type.

Methods
  • read(fd_type src, char_type * s, std::streamsize n) -> std::streamsize

    Read n bytes to array pointed by s from file descriptor src.

  • write(fd_type sink, const char_type * s, std::streamsize n) -> std::streamsize

    Write n bytes from array pointed by s to file descriptor sink.

template <class T>
struct sys::fildes_streambuf_traits

Base class for File descriptor streambuf_traits.

Types
  • using char_type = void

    Character type.

Methods
  • in_avail(T & rhs) -> std::streamsize

    Determine how many bytes are available for reading from kernel buffer.

  • is_blocking(const T & rhs) -> bool

    Determine if file descriptor is in bloking mode by checking its flags.

  • read(T & src, char_type * s, std::streamsize n) -> std::streamsize

    Read n bytes to array pointed by s from buffer buf.

  • write(T & sink, const char_type * s, std::streamsize n) -> std::streamsize

    Write n bytes from array pointed by s to buffer buf.

struct sys::streambuf_traits< fildes >

Stream buffer traits for fildes.

Base classes
operator!=(fd_type lhs, const fildes & rhs) -> bool

Compare file descriptors.

operator!=(const fildes & lhs, fd_type rhs) -> bool

Compare file descriptors.

operator==(fd_type lhs, const fildes & rhs) -> bool

Compare file descriptors.

operator==(const fildes & lhs, fd_type rhs) -> bool

Compare file descriptors.

swap(fildes & lhs, fildes & rhs) -> void

Overload of std::swap for fildes.

sync_file_systems() -> void

Write file system cache to disk. Affects all mounted file systems.