From 8693eef8febde4df90b7fbd1fb9ac813b132fa50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 20 Jul 2020 01:50:14 -0300 Subject: Wrap external functionality into classes --- src/common/file.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/common/file.cpp (limited to 'src/common/file.cpp') 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 +#include +#include +#include + +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); + } +}; -- cgit v1.2.3