Wheefun I/O Library  0.0.5
Useful I/O Primitives.
Classes | Namespaces | Functions
fd.h File Reference

File descriptor wrappers. More...

#include <wfio/type.h>
#include <stdarg.h>
#include <wfio/device.h>

Go to the source code of this file.

Classes

class  wfio::FDDevice
 A Device wrapping a file descriptor. More...
 

Namespaces

 wfio
 The root namespace for WFIO.
 

Functions

WFIO_C_BEGIN WFIO_DLL struct wfio_device_twfio_device_from_fd (wfio_fd_t handle, int *error)
 Wrap the device with the given file descriptor handle. More...
 
WFIO_DLL wfio_fd_t wfio_fd_open (const char *path, const char *mode, int *error)
 Open a new file descriptor for the given path and in the specified STDIO mode mode. More...
 
WFIO_DLL wfio_fd_t wfio_fd_openEx (const char *path, wfio_openmode_t mode, int *error)
 Open a new file descriptor for the given path and in the specified openmode mode. More...
 
WFIO_DLL void wfio_fd_close (wfio_fd_t fd)
 Close a presently open file descriptor. More...
 
WFIO_DLL_FASTCALL size_t wfio_fd_read (wfio_fd_t fd, void *buf, size_t len, int *error)
 Read from a file descriptor. More...
 
WFIO_DLL_FASTCALL size_t wfio_fd_write (wfio_fd_t fd, const void *buf, size_t len, int *error)
 Write to a file descriptor. More...
 
WFIO_DLL_FASTCALL int wfio_fd_seek (wfio_fd_t fd, wfio_off_t offset, wfio_whence_t whence, int *error)
 Seek to a position in the file descriptor's stream. More...
 
WFIO_DLL_FASTCALL wfio_off_t wfio_fd_tell (wfio_fd_t fd, int *error)
 Determine the current stream position of this file descriptor. More...
 
WFIO_DLL_FASTCALL wfio_fd_t wfio_fd_dup (wfio_fd_t fd, int *error)
 Duplicate a file descriptor. More...
 
WFIO_DLL_FASTCALL int wfio_fd_vioctl (wfio_fd_t fd, int cmd, int *error, va_list va)
 Perform device-dependent I/O control on the supplied file descriptor. More...
 
WFIO_INLINE int wfio_fd_ioctl (wfio_fd_t fd, int cmd, int *error,...)
 Perform device-dependent I/O control on the supplied file descriptor. More...
 
WFIO_DLL int wfio_fd_setflags (wfio_fd_t fd, int flags, int *error)
 Update the device flags of the file descriptor fd. More...
 
WFIO_DLL int wfio_fd_getflags (wfio_fd_t fd, int *error)
 Obtain the device flags corresponding to the file descriptor fd. More...
 
WFIO_DLL int wfio_fd_truncate (wfio_fd_t fd, size_t sz, int *error)
 Resize the resource represented by the file descriptor fd to be no greater than sz. More...
 

Detailed Description

File descriptor wrappers.

Author
Phillip Kilgore
Since
0.0.1

Function Documentation

◆ wfio_device_from_fd()

WFIO_C_BEGIN WFIO_DLL struct wfio_device_t* wfio_device_from_fd ( wfio_fd_t  handle,
int *  error 
)

Wrap the device with the given file descriptor handle.

This function creates a new device which wraps around a file descriptor. It shall behave as if the wfio_fd_* functions corresponding to each operation was used.

Parameters
handleThe file handle to wrap.
errorAn optional error indicator.
Returns
An open wfar_device_t on success; otherwise, NULL.

◆ wfio_fd_close()

WFIO_DLL void wfio_fd_close ( wfio_fd_t  fd)

Close a presently open file descriptor.

Parameters
fdThe file descriptor to close.

◆ wfio_fd_dup()

WFIO_DLL_FASTCALL wfio_fd_t wfio_fd_dup ( wfio_fd_t  fd,
int *  error 
)

Duplicate a file descriptor.

Parameters
fdThe file descriptor to duplicate.

◆ wfio_fd_getflags()

WFIO_DLL int wfio_fd_getflags ( wfio_fd_t  fd,
int *  error 
)

Obtain the device flags corresponding to the file descriptor fd.

Parameters
fdThe file descriptor to manipulate.
flagsThe device flags to set.
errorAn optional error indicator.
Returns
Nonzero on success; otherwise, failure.

◆ wfio_fd_ioctl()

WFIO_INLINE int wfio_fd_ioctl ( wfio_fd_t  fd,
int  cmd,
int *  error,
  ... 
)

Perform device-dependent I/O control on the supplied file descriptor.

Calling this function occurs in a purely implementation-defined manner. On UNIX systems, the behavior shall be the same as if ioctl() was called.

Parameters
fdThe file descriptor to ioctl.
cmdThe command to send to the file descriptor.
errorAn optional error indicator.
...Additional arguments to the ioctl.
Returns
A value peculiar to cmd.
Note
It is not sufficient to look at the return value from this function to determine failure because the return value is dependent on the ioctl command. Instead, check he value of error; if the value is WFIO_E_SUCCESS, then no error has occurred.

◆ wfio_fd_open()

WFIO_DLL wfio_fd_t wfio_fd_open ( const char *  path,
const char *  mode,
int *  error 
)

Open a new file descriptor for the given path and in the specified STDIO mode mode.

Parameters
pathThe pathname to open.

◆ wfio_fd_openEx()

WFIO_DLL wfio_fd_t wfio_fd_openEx ( const char *  path,
wfio_openmode_t  mode,
int *  error 
)

Open a new file descriptor for the given path and in the specified openmode mode.

Parameters
pathThe pathname to open.

◆ wfio_fd_read()

WFIO_DLL_FASTCALL size_t wfio_fd_read ( wfio_fd_t  fd,
void *  buf,
size_t  len,
int *  error 
)

Read from a file descriptor.

This function reads from a file descriptor by wrapping the host's method of doing so.

Parameters
fdThe file descriptor to read.
bufThe buffer to read into.
lenThe maximum number of bytes to read.
errorAn optional error indicator.
Thenumber of bytes read on success; otherwise, WFIO_NPOS.

◆ wfio_fd_seek()

WFIO_DLL_FASTCALL int wfio_fd_seek ( wfio_fd_t  fd,
wfio_off_t  offset,
wfio_whence_t  whence,
int *  error 
)

Seek to a position in the file descriptor's stream.

Parameters
fdThe file descriptor to seek.
offsetThe offset relative to whence to seek to.
whenceThe origin from whence to seek.
errorAn optional error indicator.
Returns
Nonzero on success; otherwise, zero.

◆ wfio_fd_setflags()

WFIO_DLL int wfio_fd_setflags ( wfio_fd_t  fd,
int  flags,
int *  error 
)

Update the device flags of the file descriptor fd.

Parameters
fdThe file descriptor to manipulate.
flagsThe device flags to set.
errorAn optional error indicator.
Returns
Nonzero on success; otherwise, failure.

◆ wfio_fd_tell()

WFIO_DLL_FASTCALL wfio_off_t wfio_fd_tell ( wfio_fd_t  fd,
int *  error 
)

Determine the current stream position of this file descriptor.

Parameters
fdThe file descriptor to seek.
errorAn optional error indicator.
Returns
The current stream position on success; otherwise, WFIO_NPOS.

◆ wfio_fd_truncate()

WFIO_DLL int wfio_fd_truncate ( wfio_fd_t  fd,
size_t  sz,
int *  error 
)

Resize the resource represented by the file descriptor fd to be no greater than sz.

Parameters
fdThe file descriptor to manipulate.
szThe desired size of the file descriptor.
errorAn optional error indicator.
Returns
Nonzero on success; otherwise, failure.

◆ wfio_fd_vioctl()

WFIO_DLL_FASTCALL int wfio_fd_vioctl ( wfio_fd_t  fd,
int  cmd,
int *  error,
va_list  va 
)

Perform device-dependent I/O control on the supplied file descriptor.

This function is like wfio_fd_ioctl(), except that it operates on a va_list instead.

Parameters
fdThe file descriptor to ioctl.
cmdThe command to send to the file descriptor.
errorAn optional error indicator.
vaAdditional arguments to the ioctl.
Returns
A value peculiar to cmd.
Note
It is not sufficient to look at the return value from this function to determine failure because the return value is dependent on the ioctl command. Instead, check he value of error; if the value is WFIO_E_SUCCESS, then no error has occurred.

◆ wfio_fd_write()

WFIO_DLL_FASTCALL size_t wfio_fd_write ( wfio_fd_t  fd,
const void *  buf,
size_t  len,
int *  error 
)

Write to a file descriptor.

This function write from a file descriptor by wrapping the host's method of doing so.

Parameters
fdThe file descriptor to write.
bufThe buffer to write from.
lenThe maximum number of bytes to write.
errorAn optional error indicator.
Thenumber of bytes read on success; otherwise, WFIO_NPOS.