summaryrefslogtreecommitdiff
path: root/src/common/file.cpp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-20 01:50:14 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-07-20 01:50:14 -0300
commit8693eef8febde4df90b7fbd1fb9ac813b132fa50 (patch)
tree088258d6333d54a6b90f331d3b723ae824110679 /src/common/file.cpp
parent7620a0b1c080f7b6315e796d29e324bdca98484b (diff)
downloadjet-8693eef8febde4df90b7fbd1fb9ac813b132fa50.tar.gz
jet-8693eef8febde4df90b7fbd1fb9ac813b132fa50.zip
Wrap external functionality into classes
Diffstat (limited to 'src/common/file.cpp')
-rw-r--r--src/common/file.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/common/file.cpp b/src/common/file.cpp
new file mode 100644
index 0000000..a9d8c2b
--- /dev/null
+++ b/src/common/file.cpp
@@ -0,0 +1,30 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+class File {
+ int descriptor;
+
+ public:
+
+ File(const char *filepath, int flags) {
+ descriptor = open(filepath, flags);
+ }
+
+ File(const char *filepath, int flags, mode_t mode) {
+ descriptor = open(filepath, flags, mode);
+ }
+
+ size_t send(void *msg, size_t length) {
+ return write(descriptor, msg, length);
+ }
+
+ size_t recv(void *msg, size_t length) {
+ return read(descriptor, msg, length);
+ }
+
+ ~File() {
+ close(descriptor);
+ }
+};