[hackers] [ubase] Convert mountpoint(1) to use mntent || sin

From: <git_AT_suckless.org>
Date: Sat, 15 Feb 2014 19:35:03 +0100

commit 6fd1d4c80992788fdc14e11689096ee3ba14a8fb
Author: sin <sin_AT_2f30.org>
Date: Sat Feb 15 18:34:06 2014 +0000

    Convert mountpoint(1) to use mntent

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

This archive was generated by hypermail 2.3.0 : Sat Feb 15 2014 - 19:36:27 CET