All pastes #33912 Raw Edit

Unnamed

public text v1 · immutable
#33912 ·published 2005-12-16 19:36 UTC
rendered paste body
typedef std::pair<std::string, std::string> CPointTypePair;
std::vector<CPointTypePair> GetMountPoints()
{
	std::vector<CPointTypePair> mpoints;

#ifdef __BSD__
	#if defined(HAVE_SYS_STATVFS_H) && !defined(__FREEBSD__)	
		struct statvfs* mntbuf;
	#else
		struct statfs* mntbuf;
	#endif

		long size = getmntinfo(&mntbuf, MNT_NOWAIT);
		for (long i = 0; i < size; i++) {
			std::string mpoint(mntbuf[i].f_mntonname);
			std::string mtype(mntbuf[i].f_fstypename);
			mpoints.push_back(CPointTypePair(mpoint, mtype));
		}
#elif defined(__SOLARIS__)
		FILE* mnt_tab = fopen("/etc/mntab", "r");
		if (mnt_tab) {
			struct mntent* entries = getmntent(mnt_tab);
			while ( entries ) {
				std::string mpoint(entries->mnt_mountp);
				std::string mtype(entries->mnt_type);
				
				mpoints.push_back(CPointTypePair(mpoint, mtype));
	
				entries = getmntent(mnt_tab);
			}
			
			flose(mnt_tab);
		}
#else
		FILE* mnt_tab = setmntent(_PATH_FSTAB, "r");
		if (mnt_tab) {
			struct mntent* entries = getmntent(mnt_tab);
			while ( entries ) {
				std::string mpoint(entries->mnt_dir);
				std::string mtype(entries->mnt_type);
				
				mpoints.push_back(CPointTypePair(mpoint, mtype));
	
				entries = getmntent(mnt_tab);
			}
			
			endmntent(mnt_tab);
		}
#endif

	return mpoints;
}