Use mntent in df(1)

I am slowly going to remove grabmntinfo and friends.
This commit is contained in:
sin 2014-02-15 18:24:07 +00:00
parent 4b72fcf421
commit 005e90a7ff

23
df.c
View File

@ -1,8 +1,8 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
#include <sys/statvfs.h> #include <mntent.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "grabmntinfo.h" #include <sys/statvfs.h>
#include "util.h" #include "util.h"
static void mnt_show(const char *fsname, const char *dir); static void mnt_show(const char *fsname, const char *dir);
@ -16,8 +16,8 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
struct mntinfo *minfo = NULL; struct mntent *me = NULL;
int siz, i; FILE *fp;
ARGBEGIN { ARGBEGIN {
case 'a': case 'a':
@ -31,16 +31,13 @@ main(int argc, char *argv[])
} ARGEND; } ARGEND;
printf("Filesystem 512-blocks Used Avail Capacity Mounted on\n"); printf("Filesystem 512-blocks Used Avail Capacity Mounted on\n");
siz = grabmntinfo(&minfo);
if (!siz)
eprintf("grabmntinfo:");
for (i = 0; i < siz; i++) { fp = setmntent("/proc/mounts", "r");
mnt_show(minfo[i].fsname, minfo[i].mntdir); if (!fp)
free(minfo[i].fsname); eprintf("setmntent %s:", "/proc/mounts");
free(minfo[i].mntdir); while ((me = getmntent(fp)) != NULL)
} mnt_show(me->mnt_fsname, me->mnt_dir);
free(minfo); endmntent(fp);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }