[Toybox] [PATCH 06/10] lib/getmountlist: setmntent(), getmntent_r() and stpcpy() are not defined in bionic.

Georgi Chorbadzhiyski gf at unixsol.org
Wed Mar 7 16:38:58 PST 2012


Use getmntent() and strcpy() to simulate stpcpy(). This whole
code looks buggy. For example getmntent_r() uses uninitialized
FILE * parameter and the whole stpcpy() business looks strange.
---
 lib/getmountlist.c |   31 ++++++++++++++++++-------------
 1 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/lib/getmountlist.c b/lib/getmountlist.c
index 1b23544..9a3a03d 100644
--- a/lib/getmountlist.c
+++ b/lib/getmountlist.c
@@ -18,26 +18,31 @@ struct mtab_list *getmountlist(int die)
 {
 	FILE *fp;
 	struct mtab_list *mtlist, *mt;
-	struct mntent me;
+//	struct mntent me;
+	struct mntent *me;
 	char evilbuf[2*PATH_MAX];
 
 	mtlist = 0;
-	if (!(fp = setmntent(path_mounts, "r"))) {
-		if (die) error_exit("cannot open %s", path_mounts);
-	} else {
-		while (getmntent_r(fp, &me, evilbuf, sizeof(evilbuf))) {
-			mt = xzalloc(sizeof(struct mtab_list) + strlen(me.mnt_fsname) +
-				strlen(me.mnt_dir) + strlen(me.mnt_type) + 3);
+//	if (!(fp = setmntent(path_mounts, "r"))) {
+//		if (die) error_exit("cannot open %s", path_mounts);
+//	} else {
+//		while (getmntent_r(fp, &me, evilbuf, sizeof(evilbuf))) {
+		fp = fopen(path_mounts, "r");
+		while ( (me = getmntent(fp)) ) {
+			mt = xzalloc(sizeof(struct mtab_list) + strlen(me->mnt_fsname) +
+				strlen(me->mnt_dir) + strlen(me->mnt_type) + 3);
 			mt->next = mtlist;
 			// Get information about this filesystem.  Yes, we need both.
-			stat(me.mnt_dir, &(mt->stat));
-			statvfs(me.mnt_dir, &(mt->statvfs));
+			stat(me->mnt_dir, &(mt->stat));
+			statvfs(me->mnt_dir, &(mt->statvfs));
 			// Remember information from /proc/mounts
-			mt->dir = stpcpy(mt->type, me.mnt_type) + 1;
-			mt->device = stpcpy(mt->dir, me.mnt_dir) + 1;
-			strcpy(mt->device, me.mnt_fsname);
+			strcpy(mt->type, me->mnt_type);
+			strcpy(mt->dir, me->mnt_dir);
+			mt->dir = mt->type + strlen(mt->type) + 1;
+			mt->device = mt->dir + strlen(mt->dir) + 1;
+			strcpy(mt->device, me->mnt_fsname);
 			mtlist = mt;
 		}
-	}
+//	}
 	return mtlist;
 }
-- 
1.7.5.1


 1331167138.0


More information about the Toybox mailing list