sbuild
1.7.1
|
Access mounts. More...
#include <mntstream.h>
Classes | |
struct | mntentry |
An entry in a mntstream. More... | |
Public Types | |
enum | error_code { MNT_OPEN, MNT_READ } |
Error codes. More... | |
typedef sbuild::custom_error < error_code > | error |
Exception type. | |
Public Member Functions | |
mntstream (const std::string &file) | |
The constructor. More... | |
virtual | ~mntstream () |
The destructor. | |
void | open (const std::string &file) |
Open a mount file for reading. More... | |
void | close () |
Close the mount file. More... | |
bool | eof () const |
Check for End Of File. More... | |
bool | bad () const |
Check for errors. More... | |
operator bool () | |
Check if the mntstream status is good. More... | |
bool | operator! () |
Check if the mntstream status is bad. More... | |
Private Member Functions | |
void | read (int quantity=1) |
Read mntents from the underlying FILE stream into the data deque. More... | |
Private Attributes | |
std::string | file |
The file name. | |
FILE * | mntfile |
The underlying FILE stream. | |
std::deque< mntentry > | data |
A list of mntentries represents the mount file stream as a LIFO stack. | |
bool | error_status |
Error status. | |
bool | eof_status |
End of File status. | |
Friends | |
mntstream & | operator>> (mntstream &stream, mntentry &entry) |
The overloaded extraction operator. More... | |
Access mounts.
This is a wrapper around the setmntent(3), getmntent(3) and endmntent(3) functions, which are used to read a stream of "mntents" through multiple getmntent() calls.
mntstream calls setmntent() and endmntent() automatically, and represents each mntent as a mntstream::mntentry. Like reading from and istream by pulling data out with the >> "extraction operator", mntentries are also extracted from the mntstream with the >> operator.
sbuild::mntstream::mntstream | ( | const std::string & | file) |
bool sbuild::mntstream::bad | ( | ) | const |
Check for errors.
If there is an error, the mntstream is unusable until the next open() call.
References error_status.
Referenced by operator!().
void sbuild::mntstream::close | ( | ) |
Close the mount file.
This uses the closemnt(3) call to close the underlying FILE stream. All cached data is deleted and the error state set until open() is called.
References data, eof_status, error_status, file, and mntfile.
Referenced by ~mntstream().
bool sbuild::mntstream::eof | ( | ) | const |
Check for End Of File.
Note that the end of file status is only set adter a read fails, so this should be checked after each read.
References eof_status.
Referenced by operator!().
void sbuild::mntstream::open | ( | const std::string & | file) |
Open a mount file for reading.
This uses the openmnt(3) call to open the underlying FILE stream. Any previously open mount file is closed before opening the new one. The mntstream error state is set if the open fails, and an exception will be thrown.
file | the file to read. |
References eof_status, error_status, file, MNT_OPEN, mntfile, and read().
Referenced by mntstream().
sbuild::mntstream::operator bool | ( | ) |
bool sbuild::mntstream::operator! | ( | ) |
|
private |
Read mntents from the underlying FILE stream into the data deque.
If the read fails, the error state will be set, and an exception will be thrown.
quantity | the number of mntents to read. |
References data, error_status, file, MNT_READ, and mntfile.
Referenced by open(), and sbuild::operator>>().
The overloaded extraction operator.
This is used to pull mntentries from a mntstream.
stream | the mntstream to get input from. |
entry | the mntentry to set. |