[hackers] [ubase] Use mntent in df(1) || sin
commit 005e90a7ff7a81a0383ff5b0c0e501b98391b06c
Author: sin <sin_AT_2f30.org>
Date: Sat Feb 15 18:24:07 2014 +0000
Use mntent in df(1)
I am slowly going to remove grabmntinfo and friends.
diff --git a/df.c b/df.c
index d886b2f..dc3411f 100644
--- a/df.c
+++ b/df.c
_AT_@ -1,8 +1,8 @@
/* See LICENSE file for copyright and license details. */
-#include <sys/statvfs.h>
+#include <mntent.h>
#include <stdio.h>
#include <stdlib.h>
-#include "grabmntinfo.h"
+#include <sys/statvfs.h>
#include "util.h"
static void mnt_show(const char *fsname, const char *dir);
_AT_@ -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':
_AT_@ -31,16 +31,13 @@ main(int argc, char *argv[])
} ARGEND;
printf("Filesystem 512-blocks Used Avail Capacity Mounted on
");
- 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;
}
Received on Sat Feb 15 2014 - 19:27:44 CET
This archive was generated by hypermail 2.3.0
: Sat Feb 15 2014 - 19:36:19 CET