diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sbuild/mntstream.cc | 57 | ||||
-rw-r--r-- | lib/sbuild/mntstream.h | 19 |
2 files changed, 75 insertions, 1 deletions
diff --git a/lib/sbuild/mntstream.cc b/lib/sbuild/mntstream.cc index 7f5e7d46..6b61670e 100644 --- a/lib/sbuild/mntstream.cc +++ b/lib/sbuild/mntstream.cc @@ -23,6 +23,26 @@ #include <cerrno> #include <cstring> +#ifdef HAVE_MNTTAB +#ifdef __stringify +# undef __stringify +#endif +#define __stringify(x) #x +static const char* mnttab_errors[] = { + "no error", + "entry exceeds MNT_LINE_MAX (" __stringify(MNT_LINE_MAX) ")", + "too many fields in line", + "too few fields in line" +}; +static const char * mnttab_strerror(unsigned int e) +{ + if (e < sizeof(mnttab_errors)) + return mnttab_errors[e]; + else + return "unknown error"; +} +#endif + namespace sbuild { @@ -36,6 +56,7 @@ namespace sbuild {mntstream::MNT_READ, N_("Failed to read mount file ‘%1%’")} }; +#ifdef HAVE_MNTENT mntstream::mntentry::mntentry (const struct mntent& entry): filesystem_name(entry.mnt_fsname), directory(entry.mnt_dir), @@ -45,6 +66,18 @@ namespace sbuild fsck_pass(entry.mnt_passno) { } +#endif +#ifdef HAVE_MNTTAB + mntstream::mntentry::mntentry (const struct mnttab& entry): + filesystem_name(entry.mnt_special), + directory(entry.mnt_mountp), + type(entry.mnt_fstype), + options(entry.mnt_mntopts), + dump_frequency(0), + fsck_pass(0) + { + } +#endif mntstream::mntstream(const std::string& file): @@ -66,7 +99,11 @@ namespace sbuild void mntstream::open(const std::string& file) { +#ifdef HAVE_SETMNTENT this->mntfile = setmntent(file.c_str(), "r"); +#else + this->mntfile = fopen(file.c_str(), "r"); +#endif if (this->mntfile == 0) { this->file.clear(); @@ -90,6 +127,7 @@ namespace sbuild for (i = 0; i < quantity; ++i) { +#ifdef HAVE_MNTENT struct mntent* entry; errno = 0; entry = getmntent(mntfile); @@ -106,6 +144,20 @@ namespace sbuild } mntentry newentry(*entry); // make a mntentry +#elif HAVE_MNTTAB + struct mnttab entry; + int rc = getmntent(mntfile, &entry); + if (rc < 0) { + return; // EOF + } else if (rc > 0) { + this->error_status = true; + throw error(this->file, MNT_READ, mnttab_strerror(rc)); + } + + mntentry newentry(entry); // make a mntentry +#else +#error Neither HAVE_MNTTAB nor HAVE_MNTENT is defined +#endif this->data.push_back(newentry); // push onto the end of the list } } @@ -113,8 +165,13 @@ namespace sbuild void mntstream::close() { +#ifdef HAVE_ENDMNTENT if (this->mntfile) endmntent(this->mntfile); // don't throw an exception on failure +#else + if (this->mntfile) + fclose(this->mntfile); // don't throw an exception on failure +#endif // -- it could be called in the // destructor this->mntfile = 0; diff --git a/lib/sbuild/mntstream.h b/lib/sbuild/mntstream.h index a406d6ed..b1d27741 100644 --- a/lib/sbuild/mntstream.h +++ b/lib/sbuild/mntstream.h @@ -27,7 +27,14 @@ #include <stdio.h> #include <sys/types.h> -#include <mntent.h> + +#ifdef HAVE_MNTENT_H +# include <mntent.h> +#endif + +#ifdef HAVE_SYS_MNTTAB_H +# include <sys/mnttab.h> +#endif namespace sbuild { @@ -68,12 +75,22 @@ namespace sbuild mntentry () {}; +#ifdef HAVE_MNTENT /** * The contructor. * * @param entry the mntent structure to wrap. */ mntentry (const struct mntent& entry); +#endif +#ifdef HAVE_MNTTAB + /** + * The contructor. + * + * @param entry the mnttab structure to wrap. + */ + mntentry (const struct mnttab& entry); +#endif /// Name of mounted filesystem. std::string filesystem_name; |