polybar-dwm/include/utils/mtab.hpp
2016-11-19 06:26:07 +01:00

37 lines
561 B
C++

#pragma once
#include <mntent.h>
#include "common.hpp"
POLYBAR_NS
namespace mtab_util {
/**
* Wrapper for reading mtab entries
*/
class reader {
public:
explicit reader() {
if ((m_ptr = setmntent("/etc/mtab", "r")) == nullptr) {
throw system_error("Failed to read mtab");
}
}
~reader() {
if (m_ptr != nullptr) {
endmntent(m_ptr);
}
}
bool next(mntent** dst) {
return (*dst = getmntent(m_ptr)) != nullptr;
}
protected:
FILE* m_ptr = nullptr;
};
}
POLYBAR_NS_END