regify utility  2.0.0-0
io.h
1 /*
2  * Copyright regify
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
29 #ifndef REGIFY_UTIL_IO_H
30 #define REGIFY_UTIL_IO_H
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 
34 /* Only need to export C interface if used by C++ source code */
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38 
44 RUAPI bool ruFileExists(trans_chars filename);
45 
53 RUAPI bool ruIsFile(trans_chars filename);
54 
62 RUAPI bool ruIsDir(trans_chars filename);
63 
74 RUAPI bool ruIsExecutable(trans_chars filename);
75 
76 #ifndef _WIN32
82 RUAPI bool ruIsSymlink(trans_chars filename);
83 #endif
84 
93 RUAPI int32_t ruDiskFree(trans_chars path, uint64_t* total, uint64_t* avail);
94 
98 typedef struct stat ruStat_t;
99 
111 RUAPI int32_t ruStat(trans_chars filepath, ruStat_t *dest);
112 
124 RUAPI rusize ruFileSize(trans_chars filePath, int32_t* code);
125 
137 RUAPI sec_t ruFileUtcTime(trans_chars filePath, int32_t* code);
138 
145 RUAPI int32_t ruFileSetUtcTime(trans_chars filePath, sec_t date);
146 
156 RUAPI int ruOpen(trans_chars filepath, int flags, int mode, int32_t* code);
157 
165 RUAPI FILE* ruFOpen(trans_chars filepath, trans_chars mode, int32_t* code);
166 
181 RUAPI int ruOpenTmp(char *pathTemplate, int flags, int mode, int32_t *code);
182 
190 RUAPI rusize_s ruWrite(int oh, trans_ptr contents, rusize length);
191 
203 RUAPI int32_t ruFileSetContents(trans_chars filename, trans_chars contents, rusize length);
204 
214 RUAPI int ruFileGetContents(trans_chars filename, alloc_chars* contents, rusize* length);
215 
222 RUAPI int ruFileCopy(trans_chars srcpath, trans_chars destpath);
223 
231 RUAPI int ruFileRename(trans_chars oldName, trans_chars newName);
232 
240 RUAPI int ruFileTryRename(trans_chars oldName, trans_chars newName);
241 
247 RUAPI int ruFileRemove(trans_chars filename);
248 
252 #define RU_WALK_FOLDER_FIRST 0x1
256 #define RU_WALK_FOLDER_LAST 0x2
260 #define RU_WALK_NO_RECURSE 0x4
264 #define RU_WALK_NO_SELF 0x8
269 #define RU_WALK_UNIX_SLASHES 0x10
270 
271 
285 typedef bool (*entryFilter) (trans_chars folderPath, trans_chars fileName, bool isFolder, ptr ctx);
286 
295 typedef int32_t (*entryMgr) (trans_chars fullPath, bool isFolder, ptr ctx);
296 
309 RUAPI int32_t ruFilteredFolderWalk(trans_chars folder, uint32_t flags,
310  entryFilter filter, entryMgr actor, ptr ctx);
311 
322 RUAPI int32_t ruFolderWalk(trans_chars folder, uint32_t flags, entryMgr actor, ptr ctx);
323 
332 
340 RUAPI int32_t ruFolderRemove(trans_chars folder);
341 
349 RUAPI int32_t ruMkdir(trans_chars pathname, int mode, bool deep);
350 
360 
368 
376 
387 
395 
403 
416 RUAPI alloc_chars ruPathMultiJoin(int parts, ...);
417 
430 RUAPI alloc_chars ruPathMultiJoinNative(int parts, ...);
431 
435 #ifdef __cplusplus
436 }
437 #endif /* __cplusplus */
438 #endif //REGIFY_UTIL_IO_H
RUAPI int32_t ruFilteredFolderWalk(trans_chars folder, uint32_t flags, entryFilter filter, entryMgr actor, ptr ctx)
Like ruFolderWalk with additional filtering capability. Folder entries . and .. are not passed to fil...
RUAPI int32_t ruFolderWalk(trans_chars folder, uint32_t flags, entryMgr actor, ptr ctx)
Decends into given folder depth first and calls actor on each entry. Folder entries ....
RUAPI ru_int ruFolderEntries(trans_chars folder)
Returns the number of folder entries including itself.
RUAPI int ruFileTryRename(trans_chars oldName, trans_chars newName)
Renames a given file like ruFileRename, but fails when newName already exists instead of overwriting ...
RUAPI int32_t ruStat(trans_chars filepath, ruStat_t *dest)
RUAPI int ruFileRename(trans_chars oldName, trans_chars newName)
RUAPI bool ruIsSymlink(trans_chars filename)
RUAPI int ruFileCopy(trans_chars srcpath, trans_chars destpath)
Copies srcpath to destpath.
RUAPI bool ruIsDir(trans_chars filename)
RUAPI bool ruIsExecutable(trans_chars filename)
RUAPI bool ruIsFile(trans_chars filename)
RUAPI sec_t ruFileUtcTime(trans_chars filePath, int32_t *code)
Return the UTC modification date of the given file if it exists.
RUAPI rusize_s ruWrite(int oh, trans_ptr contents, rusize length)
RUAPI rusize ruFileSize(trans_chars filePath, int32_t *code)
Return the size of the given file if it exists.
RUAPI alloc_chars ruFullPath(trans_chars filePath)
Returns an absolute filepath leading to the given relative path.
RUAPI alloc_chars ruPathJoin(trans_chars base, trans_chars file)
Returns base and file joined with the a unix filesystem slash in a new string.
RUAPI int32_t ruFileSetContents(trans_chars filename, trans_chars contents, rusize length)
bool(* entryFilter)(trans_chars folderPath, trans_chars fileName, bool isFolder, ptr ctx)
A function that is called with each entry of a ruFolderWalk to decide whether that entry should be pr...
Definition: io.h:285
RUAPI alloc_chars ruPathJoinNative(trans_chars base, trans_chars file)
Returns base and file joined with the filesystem slash in a new string.
RUAPI alloc_chars ruPathMultiJoin(int parts,...)
Return a path by concatenating the given parts number of parameters using a unix style directory slas...
RUAPI bool ruFileExists(trans_chars filename)
RUAPI int32_t ruFileSetUtcTime(trans_chars filePath, sec_t date)
Set UTC access and mod time of given filePath to given date.
RUAPI alloc_chars ruPathMultiJoinNative(int parts,...)
Return a path by concatenating the given parts number of parameters using the platform native directo...
RUAPI FILE * ruFOpen(trans_chars filepath, trans_chars mode, int32_t *code)
RUAPI perm_chars ruBaseName(perm_chars filePath)
Returns the filename of a path with the preceding path removed.
RUAPI perm_chars ruFileExtension(perm_chars filePath)
Returns the extension part of the given file name if there is one.
RUAPI int32_t ruFolderRemove(trans_chars folder)
Recursively delete given folder and all it's sub contents. If given path is a file or symlink,...
RUAPI alloc_chars ruDirName(trans_chars filePath)
Returns the dirname part of a full path without the trailing slash.
RUAPI int ruOpen(trans_chars filepath, int flags, int mode, int32_t *code)
RUAPI int ruFileGetContents(trans_chars filename, alloc_chars *contents, rusize *length)
RUAPI int ruOpenTmp(char *pathTemplate, int flags, int mode, int32_t *code)
struct stat ruStat_t
Definition: io.h:98
int32_t(* entryMgr)(trans_chars fullPath, bool isFolder, ptr ctx)
A function that is called with each entry of a ruFolderWalk.
Definition: io.h:295
RUAPI int32_t ruDiskFree(trans_chars path, uint64_t *total, uint64_t *avail)
RUAPI int32_t ruMkdir(trans_chars pathname, int mode, bool deep)
RUAPI int ruFileRemove(trans_chars filename)
intptr_t ru_int
A pointer sized integer type for collections like ruMap or ruList.
Definition: regify-util.h:328
const void * trans_ptr
A transient pointer.
Definition: regify-util.h:287
const char * trans_chars
A transient NULL terminated string pointer.
Definition: regify-util.h:186
const char * perm_chars
A permanent NULL terminated string pointer.
Definition: regify-util.h:176
long sec_t
A signed type for expressing seconds.
Definition: regify-util.h:312
char * alloc_chars
An allocated NULL terminated string pointer.
Definition: regify-util.h:199
size_t rusize
Abstracted version of size_t.
Definition: regify-util.h:338
void * ptr
A generic pointer.
Definition: regify-util.h:304
signed long rusize_s
Abstracted version of size_t but signed.
Definition: regify-util.h:152