2016-06-15 03:32:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.hpp"
|
2016-12-20 04:05:43 +00:00
|
|
|
#include "utils/factory.hpp"
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-12-20 04:05:43 +00:00
|
|
|
class file_ptr {
|
|
|
|
public:
|
|
|
|
explicit file_ptr(const string& path, const string& mode = "a+");
|
|
|
|
~file_ptr();
|
|
|
|
|
|
|
|
file_ptr(const file_ptr& o) = delete;
|
|
|
|
file_ptr& operator=(const file_ptr& o) = delete;
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-12-20 04:05:43 +00:00
|
|
|
operator bool();
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-12-20 04:05:43 +00:00
|
|
|
FILE* operator()();
|
2016-12-15 02:30:41 +00:00
|
|
|
|
2016-12-20 04:05:43 +00:00
|
|
|
protected:
|
|
|
|
FILE* m_ptr = nullptr;
|
|
|
|
string m_path;
|
|
|
|
string m_mode;
|
|
|
|
};
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-12-20 04:05:43 +00:00
|
|
|
class file_descriptor {
|
|
|
|
public:
|
|
|
|
explicit file_descriptor(const string& path, int flags = 0);
|
|
|
|
explicit file_descriptor(int fd);
|
|
|
|
~file_descriptor();
|
|
|
|
operator int();
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-12-20 04:05:43 +00:00
|
|
|
protected:
|
|
|
|
int m_fd{0};
|
|
|
|
};
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-12-20 04:05:43 +00:00
|
|
|
namespace file_util {
|
2016-11-25 12:55:15 +00:00
|
|
|
bool exists(const string& filename);
|
|
|
|
string get_contents(const string& filename);
|
2016-11-02 19:22:45 +00:00
|
|
|
void set_block(int fd);
|
|
|
|
void set_nonblock(int fd);
|
|
|
|
bool is_fifo(string filename);
|
2016-12-20 04:05:43 +00:00
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
decltype(auto) make_file_descriptor(Args&&... args) {
|
2016-12-23 00:07:00 +00:00
|
|
|
return factory_util::unique<file_descriptor>(forward<Args>(args)...);
|
2016-12-20 04:05:43 +00:00
|
|
|
}
|
2016-06-15 03:32:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|