2016-06-14 23:32:35 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
namespace file_util {
|
|
|
|
/**
|
|
|
|
* RAII file wrapper
|
|
|
|
*/
|
|
|
|
class file_ptr {
|
|
|
|
public:
|
|
|
|
explicit file_ptr(const string& path, const string& mode = "a+")
|
|
|
|
: m_path(string(path)), m_mode(string(mode)) {
|
|
|
|
m_ptr = fopen(m_path.c_str(), m_mode.c_str());
|
|
|
|
}
|
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
~file_ptr();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
operator bool();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
FILE* operator()();
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
FILE* m_ptr = nullptr;
|
|
|
|
string m_path;
|
|
|
|
string m_mode;
|
|
|
|
};
|
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
bool exists(string filename);
|
|
|
|
string get_contents(string filename);
|
|
|
|
void set_block(int fd);
|
|
|
|
void set_nonblock(int fd);
|
|
|
|
bool is_fifo(string filename);
|
2016-06-14 23:32:35 -04:00
|
|
|
}
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|