Convert mountpoint(1) to use mntent

This commit is contained in:
sin 2014-02-15 18:34:06 +00:00
parent 3bb0f0fbdd
commit 6fd1d4c809
1 changed files with 13 additions and 19 deletions

View File

@ -1,11 +1,11 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <sys/types.h> #include <mntent.h>
#include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "grabmntinfo.h" #include <sys/stat.h>
#include <sys/types.h>
#include "util.h" #include "util.h"
static void static void
@ -17,10 +17,9 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int i;
int qflag = 0, dflag = 0, xflag = 0; int qflag = 0, dflag = 0, xflag = 0;
struct mntinfo *minfo = NULL; struct mntent *me = NULL;
int siz; FILE *fp;
int ret = 0; int ret = 0;
struct stat st1, st2; struct stat st1, st2;
@ -62,24 +61,19 @@ main(int argc, char *argv[])
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
siz = grabmntinfo(&minfo); fp = setmntent("/proc/mounts", "r");
if (!siz) if (!fp)
eprintf("grabmntinfo:"); eprintf("setmntent %s:", "/proc/mounts");
for (i = 0; i < siz; i++) { while ((me = getmntent(fp)) != NULL) {
if (stat(minfo[i].mntdir, &st2) < 0) if (stat(me->mnt_dir, &st2) < 0)
eprintf("stat %s:", minfo[i].mntdir); eprintf("stat %s:", me->mnt_dir);
if (st1.st_dev == st2.st_dev && if (st1.st_dev == st2.st_dev &&
st1.st_ino == st2.st_ino) st1.st_ino == st2.st_ino)
break; break;
} }
endmntent(fp);
for (i = 0; i < siz; i++) { if (me == NULL)
free(minfo[i].fsname);
free(minfo[i].mntdir);
}
free(minfo);
if (i == siz)
ret = 1; ret = 1;
if (!qflag) if (!qflag)