<lib/fdio/fdio.h> in fdio

Header source code

fdio_t typedef {:#fdio_t}

Declaration source code

An opaque structure that represents the object to which a file descriptor refers.

WARNING: These interfaces exist to allow integration of fdio file descriptors with handle-centric message loops. If used incorrectly they can seriously mess up the state of fdio, fds, etc.

zxio_t typedef {:#zxio_t}

Declaration source code

Access the zxio_t field within an fdio_t.

zxio_storage_t typedef {:#zxio_storage_t}

Declaration source code

Storage for a ZXIO object.

See lib/zxio/ops.h for more information.

fdio_bind_to_fd(…) {:#fdio_bind_to_fd}

Declaration source code

Install an fdio_t in the file descriptor table for this process.

If fd >= 0, request a specific fd, and starting_fd is ignored.

If fd < 0, request the first available fd >= starting_fd.

Upon success, returns the allocated file descriptor. Returns -1 on failure.

Always takes ownership of the given reference to the fdio_t. Upon success, that reference is owned by the file descriptor table. Upon failure, the reference is released.

fdio_create(…) {:#fdio_create}

Declaration source code

Creates an fdio_t from a zx_handle_t.

The handle must be to a channel, socket, vmo, or debuglog object. The handle is always consumed by this function.

If the zx_handle_t is a channel, then the channel must implement the fuchsia.unknown/Queryable protocol.

Errors

  • ZX_ERR_BAD_HANDLE: The input handle is invalid.

  • ZX_ERR_ACCESS_DENIED: Then input handle does not have the necessary rights.

  • ZX_ERR_NO_MEMORY: Memory allocation failed.

  • ZX_ERR_NOT_SUPPORTED: The kernel object type is not valid for an FD.

fdio_default_create() {:#fdio_default_create}

Declaration source code

Creates an fdio_t that does nothing.

fdio_fd_create_null() {:#fdio_fd_create_null}

Declaration source code

Creates a file descriptor that does nothing.

Returns -1 and sets errno if the function is unable to create the file descriptor (e.g., if the file descriptor table is full).

fdio_get_service_handle(…) {:#fdio_get_service_handle}

Declaration source code

Returns a handle to the channel backing a file descriptor.

Upon success, a handle to the backing channel is returned in out, and the caller receives ownership of that handle.

Always removes the file descriptor from the file descriptor table for this process.

Errors

  • ZX_ERR_INVALID_ARGS: fd is not a valid file descriptor.

  • ZX_ERR_NOT_SUPPORTED: fd is not backed by a channel.

  • ZX_ERR_UNAVAILABLE: fd is busy or has been dup'ed and therefore is referenced by multiple entries in the file descriptor table.

fdio_get_zxio(…) {:#fdio_get_zxio}

Declaration source code

fdio_null_create() {:#fdio_null_create}

Declaration source code

Creates an fdio_t that acts as /dev/null.

fdio_unbind_from_fd(…) {:#fdio_unbind_from_fd}

Declaration source code

Removes a file descriptor from the file descriptor table for this process.

Upon success, the fdio_t underlying the file descriptor is returned in io_out, and the caller receives ownership of one reference to fdio_t. Specifically, the caller is responsible for calling fdio_unsafe_release upon success.

Errors

  • ZX_ERR_INVALID_ARGS: fd is not a valid file descriptor.

  • ZX_ERR_UNAVAILABLE: fd is busy or has been dup'ed and therefore is referenced by multiple entries in the file descriptor table.

fdio_zxio_create(…) {:#fdio_zxio_create}

Declaration source code

Creates an fdio_t that is backed by a zxio_t.

The zxio_t is initialized with a null ops table. The zxio_storage_t for the zxio_t is returned via out_storage. The client can re-initialize the zxio_storage_t to customize the behavior of the zxio_t.

The returned zxio_storage_t is valid for the lifetime of the returned fdio_t.

To bind the fdio_t to a file descriptor, use fdio_bind_to_fd.

Upon success, the caller receives ownership of one reference to fdio_t. Specifically, the caller is responsible for calling fdio_unsafe_release() upon success.

Upon failure, returns NULL.