-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.hpp
More file actions
117 lines (111 loc) · 5.19 KB
/
File.hpp
File metadata and controls
117 lines (111 loc) · 5.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*******************************************************************************
* libunix++: C++ wrapper for Linux system calls
* File operations
*
* © 2019—2025, Sauron <libunixpp@saur0n.science>
******************************************************************************/
#ifndef __UNIXPP_FILE_HPP
#define __UNIXPP_FILE_HPP
#include <fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
#include "Stream.hpp"
namespace upp {
class File : public Stream {
friend class Directory;
public:
/** **/
const int REMOVEDIR=AT_REMOVEDIR;
/** Open file for reading **/
explicit File(const char * filename);
/** Open and possibly create a file **/
File(const char * filename, int flags, int mode=0600);
/** Open file for reading relative to this directory **/
File(const File &dir, const char * filename);
/** Open file for reading relative to this directory **/
File(const File &dir, const char * filename, int flags);
/** Set an extended attribute value **/
void setAttribute(const char * name, const char * value, size_t size, int flags=0);
/** Retrieve an extended attribute value **/
size_t getAttribute(const char * name, char * value, size_t size);
/** List extended attribute names **/
void listAttributes(char * list, size_t size);
/** Remove an extended attribute **/
void removeAttribute(const char * name);
/** Get filesystem statistics **/
void statfs(struct statfs &buf);
/** Truncate a file to a specified length **/
void truncate(off_t length=0);
/** Manipulate file space **/
void allocate(int mode, off_t offset, off_t len);
/** Change working directory to this directory **/
void chdir();
/** Apply or remove an advisory lock on an open file **/
void lock(int operation);
/** Apply, test or remove a POSIX lock on an open file **/
void lock(int cmd, off_t len);
/** Create a special file relative to this directory **/
void mknod(const char * pathname, mode_t mode, dev_t device);
/** Make directory relative to this directory **/
void mkdir(const char * pathname, mode_t mode);
/** Delete a file relative to this directory **/
void unlink(const char * pathname, int flags=0);
/** Make a new name for a file relative to this directory **/
void symlink(const char * target, const char * linkpath);
/** Make a new name for a file relative to this directory **/
void link(const char * oldpath, const char * newpath, int flags=0);
/** Change the name/location of a file relative to this directory **/
void rename(const char * oldpath, const char * newpath);
#ifndef PLATFORM_MUSL
/** Change the name/location of a file relative to this directory **/
void rename(const char * oldpath, const char * newpath, int flags);
#endif
/** Check user's permissions for a file relative to this directory **/
bool access(const char * pathname, int mode, int flags=0);
/** Change permissions of a file **/
void chmod(mode_t mode);
/** Change permissions of a file relative to this directory **/
void chmod(const char * pathname, mode_t mode, int flags=0);
/** Change ownership of a file **/
void chown(uid_t owner, gid_t group);
/** Change ownership of a file relative to this directory **/
void chown(const char * pathname, uid_t owner, gid_t group, int flags=0);
/** Read value of a symbolic link relative to this directory **/
size_t readlink(const char * pathname, char * buffer, size_t length);
/** Get file status **/
void stat(struct stat &statbuf);
/** Get file status relative to this directory **/
void stat(const char * pathname, struct stat &statbuf, int flags=0);
/** Synchronize a file's in-core state with storage device **/
void sync();
/** Synchronize a file's in-core state with storage device **/
void syncData();
/** Sync a file segment with disk **/
void sync(off_t offset, off_t nbytes, unsigned int flags=0);
/** Initiate file readahead into page cache **/
void readAhead(off_t offset, size_t count);
/** Commit filesystem caches to disk **/
void syncFileSystem();
/** Change file timestamps **/
void utime(const struct timespec times[2]);
/** Change file timestamps relative to this directory **/
void utime(const char * pathname, const struct timespec times[2], int flags=0);
/** **/
void exec(const char * pathname, char ** const argv, char ** const envp, int flags=0);
#ifndef PLATFORM_MUSL
/** Get file status (extended) relative to this directory **/
void stat(const char * pathname, unsigned int mask, struct statx &statxbuf, int flags=0);
#endif
/** Set file mode creation mask **/
static mode_t umask(mode_t mask);
/** Copy a range of file to another file **/
size_t copyRange(File &out, size_t length, unsigned flags=0);
/** Copy a range of file to another file **/
size_t copyRange(File &out, off_t &offOut, size_t length, unsigned flags=0);
/** Copy a range of file to another file **/
size_t copyRange(off_t &offIn, File &out, size_t length, unsigned flags=0);
/** Copy a range of file to another file **/
size_t copyRange(off_t &offIn, File &out, off_t &offOut, size_t length, unsigned flags=0);
};
}
#endif