Wheefun I/O Library  0.0.5
Useful I/O Primitives.
file.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 
22 #ifndef WFIO_FILE_H
23 #define WFIO_FILE_H
24 
25 #include <wfio/type.h>
26 
38 
46 WFIO_DLL struct wfio_device_t* wfio_device_open_file(const char* path,
47  const char* mode, int* error);
48 
56 WFIO_DLL struct wfio_device_t* wfio_device_open_fileEx(const char* path,
57  wfio_openmode_t mode, int* error);
58 
67 WFIO_DLL wfio_openmode_t wfio_stdio_parseMode(const char* mode, int* error);
68 
78  int* error);
79 
80 /* Filesystem Functions */
81 
91 WFIO_DLL_FASTCALL const char* wfio_file_cwd(char* path, size_t len,
92  int* error);
93 
102 WFIO_DLL_FASTCALL int wfio_file_cd(const char* path, int* error);
103 
112 WFIO_DLL_FASTCALL int wfio_file_unlink(const char* path, int* error);
113 
122 WFIO_DLL_FASTCALL int wfio_file_exists(const char* path, int* error);
123 
133 WFIO_DLL_FASTCALL int wfio_file_rename(const char* src, const char* dest,
134  int* error);
135 
145 WFIO_DLL int wfio_file_truncate(const char* path, size_t sz, int* error);
146 
148 
149 #ifdef __cplusplus
150 namespace wfio {
154  class FileDevice : public Device {
155  public:
156 
163  inline FileDevice(const char* path, ::wfio_openmode_t mode,
164  int* error = NULL) : Device(
165  ::wfio_device_open_fileEx(path, mode, error),
166  false) {}
167 
174  inline FileDevice(const char* path, const char* mode,
175  int* error = NULL) : Device(
176  ::wfio_device_open_file(path, mode, error),
177  false) {}
178  };
179 }
180 #endif
181 
182 #endif
The root namespace for WFIO.
Definition: bin.h:879
WFIO_DLL const char * wfio_stdio_deriveMode(wfio_openmode_t mode, int *error)
Obtain an STDIO mode string for the provided mode.
WFIO_DLL wfio_openmode_t wfio_stdio_parseMode(const char *mode, int *error)
Obtain an openmode for the specified STDIO mode string.
#define WFIO_DLL
Mark the symbol as an element of the library.
Definition: host.h:397
#define WFIO_C_BEGIN
Definition: host.h:477
#define WFIO_DLL_FASTCALL
Shorthand for WFIO_DLL WFIO_FASTCALL.
Definition: host.h:425
FileDevice(const char *path, const char *mode, int *error=NULL)
Construct a new FDDevice from a file descriptor.
Definition: file.h:174
WFIO_DLL_FASTCALL int wfio_file_exists(const char *path, int *error)
Determine if path exists.
WFIO_DLL_FASTCALL const char * wfio_file_cwd(char *path, size_t len, int *error)
Obtain the path to the current working directory.
FileDevice(const char *path, ::wfio_openmode_t mode, int *error=NULL)
Construct a new FDDevice from a file descriptor.
Definition: file.h:163
WFIO_DLL int wfio_file_truncate(const char *path, size_t sz, int *error)
Trim the file at path to the specified sz.
A C++ wrapper for a wfio_device_t.
Definition: device.h:783
WFIO_DLL_FASTCALL int wfio_file_unlink(const char *path, int *error)
Remove path from the filesystem.
WFIO_DLL_FASTCALL int wfio_file_cd(const char *path, int *error)
Change the current working directory to path.
#define WFIO_C_END
Definition: host.h:485
A simple, byte-oriented channel.
Definition: device.h:164
WFIO_DLL struct wfio_device_t * wfio_device_open_fileEx(const char *path, wfio_openmode_t mode, int *error)
Open a file located at path using extended syntax.
WFIO_DLL_FASTCALL int wfio_file_rename(const char *src, const char *dest, int *error)
Rename the path supplied by src to dest.
A Device wrapping a file stream.
Definition: file.h:154
WFIO_C_BEGIN WFIO_DLL struct wfio_device_t * wfio_device_open_file(const char *path, const char *mode, int *error)
Open a file located at path.
Shared type definitions.
int wfio_openmode_t
The type corresponding to an openmode.
Definition: iotype.h:103