1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-03 04:33:30 -05:00
polybar/include/utils/mtab.hpp
Michael Carlberg 9a0df75a91 feat(fs): New filesystem module
Module that displays details about
mounted filesystems, #84

Closes #153
2016-11-13 06:14:34 +01:00

36 lines
567 B
C++

#pragma once
#include <mntent.h>
#include "common.hpp"
LEMONBUDDY_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;
};
}
LEMONBUDDY_NS_END