From 005e90a7ff7a81a0383ff5b0c0e501b98391b06c Mon Sep 17 00:00:00 2001 From: sin Date: Sat, 15 Feb 2014 18:24:07 +0000 Subject: [PATCH] Use mntent in df(1) I am slowly going to remove grabmntinfo and friends. --- df.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/df.c b/df.c index d886b2f..dc3411f 100644 --- a/df.c +++ b/df.c @@ -1,8 +1,8 @@ /* See LICENSE file for copyright and license details. */ -#include +#include #include #include -#include "grabmntinfo.h" +#include #include "util.h" static void mnt_show(const char *fsname, const char *dir); @@ -16,8 +16,8 @@ usage(void) int main(int argc, char *argv[]) { - struct mntinfo *minfo = NULL; - int siz, i; + struct mntent *me = NULL; + FILE *fp; ARGBEGIN { case 'a': @@ -31,16 +31,13 @@ main(int argc, char *argv[]) } ARGEND; printf("Filesystem 512-blocks Used Avail Capacity Mounted on\n"); - siz = grabmntinfo(&minfo); - if (!siz) - eprintf("grabmntinfo:"); - for (i = 0; i < siz; i++) { - mnt_show(minfo[i].fsname, minfo[i].mntdir); - free(minfo[i].fsname); - free(minfo[i].mntdir); - } - free(minfo); + fp = setmntent("/proc/mounts", "r"); + if (!fp) + eprintf("setmntent %s:", "/proc/mounts"); + while ((me = getmntent(fp)) != NULL) + mnt_show(me->mnt_fsname, me->mnt_dir); + endmntent(fp); return EXIT_SUCCESS; }