Wheefun I/O Library  0.0.5
Useful I/O Primitives.
fd.h
Go to the documentation of this file.
1 /* WFIO - the Wheefun IO Library
2  Copyright (C) 2018 Phillip Kilgore
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <https://www.gnu.org/licenses/>.
16 
17  Additionally, you should have recieved a copy of the GNU Classpath
18  exception, which amends the license to generally permit linking against
19  the software provided herein.
20 */
21 
30 #ifndef WFIO_FD_H
31 #define WFIO_FD_H
32 
33 #include <wfio/type.h>
34 #include <stdarg.h>
35 
37 
51  int* error);
52 
59 WFIO_DLL wfio_fd_t wfio_fd_open(const char* path, const char* mode,
60  int* error);
61 
68 WFIO_DLL wfio_fd_t wfio_fd_openEx(const char* path, wfio_openmode_t mode,
69  int* error);
70 
77 
91 WFIO_DLL_FASTCALL size_t wfio_fd_read(wfio_fd_t fd, void* buf, size_t len,
92  int* error);
93 
107 WFIO_DLL_FASTCALL size_t wfio_fd_write(wfio_fd_t fd, const void* buf,
108  size_t len, int* error);
109 
121  wfio_whence_t whence, int* error);
122 
132 
139 
159 WFIO_DLL_FASTCALL int wfio_fd_vioctl(wfio_fd_t fd, int cmd, int* error,
160  va_list va);
161 
183 WFIO_INLINE int wfio_fd_ioctl(wfio_fd_t fd, int cmd, int* error, ...) {
184  register int ret;
185  va_list va;
186  va_start(va, error);
187  ret = wfio_fd_vioctl(fd, cmd, error, va);
188  va_end(va);
189  return ret;
190 }
191 
201 WFIO_DLL int wfio_fd_setflags(wfio_fd_t fd, int flags, int* error);
202 
213 WFIO_DLL int wfio_fd_getflags(wfio_fd_t fd, int* error);
214 
225 WFIO_DLL int wfio_fd_truncate(wfio_fd_t fd, size_t sz, int* error);
226 
228 
229 #ifdef __cplusplus
230 
231 #include <wfio/device.h>
232 
233 namespace wfio {
241  class FDDevice : public Device {
242  public:
243 
250  inline FDDevice(wfio_fd_t fd, int* error = NULL) : Device(
251  ::wfio_device_from_fd(fd, error), false) {}
252  };
253 }
254 
255 #endif
256 
257 #endif
The root namespace for WFIO.
Definition: bin.h:879
WFIO_DLL_FASTCALL wfio_off_t wfio_fd_tell(wfio_fd_t fd, int *error)
Determine the current stream position of this file descriptor.
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.
#define WFIO_DLL
Mark the symbol as an element of the library.
Definition: host.h:397
WFIO_C_BEGIN typedef long int wfio_off_t
An integer corresponding to a device offset.
Definition: iotype.h:48
#define WFIO_C_BEGIN
Definition: host.h:477
#define WFIO_DLL_FASTCALL
Shorthand for WFIO_DLL WFIO_FASTCALL.
Definition: host.h:425
WFIO_DLL int wfio_fd_getflags(wfio_fd_t fd, int *error)
Obtain the device flags corresponding to the file descriptor fd.
wfio_whence_t
The type corresponding to the point of reference in a seek operation.
Definition: iotype.h:60
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.
Definition: fd.h:183
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. ...
FDDevice(wfio_fd_t fd, int *error=NULL)
Construct a new FDDevice from a file descriptor.
Definition: fd.h:250
int wfio_fd_t
The type corresponding a file descriptor.
Definition: iotype.h:108
WFIO_DLL_FASTCALL wfio_fd_t wfio_fd_dup(wfio_fd_t fd, int *error)
Duplicate a file descriptor.
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&#39;s stream.
A C++ wrapper for a wfio_device_t.
Definition: device.h:783
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.
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.
WFIO_DLL void wfio_fd_close(wfio_fd_t fd)
Close a presently open file descriptor.
#define WFIO_INLINE
Mark this symbol for inlining.
Definition: host.h:377
#define WFIO_C_END
Definition: host.h:485
A simple, byte-oriented channel.
Definition: device.h:164
A Device wrapping a file descriptor.
Definition: fd.h:241
WFIO_DLL int wfio_fd_setflags(wfio_fd_t fd, int flags, int *error)
Update the device flags of the file descriptor fd.
int flags
This device&#39;s flags.
Definition: device.h:178
Byte-oriented devices.
WFIO_DLL_FASTCALL size_t wfio_fd_read(wfio_fd_t fd, void *buf, size_t len, int *error)
Read from a file descriptor.
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.
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.
Shared type definitions.
int wfio_openmode_t
The type corresponding to an openmode.
Definition: iotype.h:103