32 #include "libpbd-config.h"
38 struct mntent_sorter {
39 bool operator() (
const mntent *a,
const mntent *b) {
40 return strcmp (a->mnt_dir, b->mnt_dir);
49 unsigned int maxmatch = 0;
50 unsigned int matchlen;
51 const char *cpath = path.c_str();
54 if ((mntf = setmntent (
"/etc/mtab",
"r")) == 0) {
60 while ((mnt = getmntent (mntf))) {
70 while (cpath[n] && mnt->mnt_dir[n]) {
71 if (cpath[n] != mnt->mnt_dir[n]) {
78 if (cpath[matchlen] ==
'\0') {
85 if (matchlen > maxmatch) {
86 snprintf (best,
sizeof(best),
"%s", mnt->mnt_dir);
97 #elif defined(PLATFORM_WINDOWS)
110 #else // !HAVE_GETMNTENT
112 #include <sys/param.h>
113 #include <sys/ucred.h>
114 #include <sys/mount.h>
119 struct statfs *mntbufp = 0;
121 unsigned int maxmatch = 0;
122 unsigned int matchlen;
123 const char *cpath = path.c_str();
132 if ((count = getmntinfo(&mntbufp, MNT_NOWAIT)) == 0) {
138 for (
int i = 0; i < count; ++i) {
146 while (cpath[n] && mntbufp[i].f_mntonname[n]) {
147 if (cpath[n] != mntbufp[i].f_mntonname[n]) {
154 if (cpath[matchlen] ==
'\0') {
155 snprintf(best,
sizeof(best),
"%s", mntbufp[i].f_mntonname);
160 if (matchlen > maxmatch) {
161 snprintf (best,
sizeof(best),
"%s", mntbufp[i].f_mntonname);
169 #endif // HAVE_GETMNTENT
171 #ifdef TEST_MOUNTPOINT
173 main (
int argc,
char *argv[])
175 printf (
"mp of %s = %s\n", argv[1],
mountpoint (argv[1]).c_str());
179 #endif // TEST_MOUNTPOINT
181 #else // COMPILER_MSVC
182 const char*
pbd_mountpoint =
"pbd/msvc/mountpoint.cc takes precedence over this file";
183 #endif // COMPILER_MSVC
string mountpoint(string path)
const char * pbd_mountpoint
int main(int argc, char *argv[])