summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoît Dejean <bdejean@src.gnome.org>2005-01-18 21:57:52 +0000
committerBenoît Dejean <bdejean@src.gnome.org>2005-01-18 21:57:52 +0000
commit793807b07e20e5e607393f52bf52c4b3f1308887 (patch)
treeecfac6f37a98f60979a85bbb4b1703d8c0c5a89d
parent9898e7ee58048ec7ebaaffea871a597f2431d5b5 (diff)
downloadlibgtop-793807b07e20e5e607393f52bf52c4b3f1308887.tar.gz
Re-worked with bsearch.
* mountlist.c: (ignore_mount_entry): Re-worked with bsearch.
-rw-r--r--sysdeps/common/ChangeLog4
-rw-r--r--sysdeps/common/mountlist.c32
2 files changed, 19 insertions, 17 deletions
diff --git a/sysdeps/common/ChangeLog b/sysdeps/common/ChangeLog
index 48c01e96..aeba1c4e 100644
--- a/sysdeps/common/ChangeLog
+++ b/sysdeps/common/ChangeLog
@@ -1,3 +1,7 @@
+2005-01-18 Benoît Dejean <TazForEver@dlfp.org>
+
+ * mountlist.c: (ignore_mount_entry): Re-worked with bsearch.
+
2004-12-09 Benoît Dejean <tazforever@dlfp.org>
* mountlist.c: (ignore_mount_entry): Ignores "unkown" file system type.
diff --git a/sysdeps/common/mountlist.c b/sysdeps/common/mountlist.c
index 30ae0b6b..8cf21516 100644
--- a/sysdeps/common/mountlist.c
+++ b/sysdeps/common/mountlist.c
@@ -21,6 +21,7 @@
#include <glib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/types.h>
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
@@ -535,31 +536,28 @@ read_filesystem_list (void)
static gboolean ignore_mount_entry(const struct mount_entry *me)
{
+ /* keep sorted */
static const char ignored[][12] = {
- "proc",
- "procfs",
"autofs",
- "sysfs",
- "usbfs",
- "none",
- "devpts",
- "usbdevfs",
"binfmt_misc",
- "supermount",
+ "devpts",
"mntfs",
+ "none",
"openpromfs",
- "unknown"
+ "proc",
+ "procfs",
+ "supermount",
+ "sysfs",
+ "unknown",
+ "usbdevfs",
+ "usbfs"
};
- const char (*i)[12] = &ignored[0];
-
- while(i != (&ignored[0] + G_N_ELEMENTS(ignored))) {
- if(strcmp(*i, me->me_type) == 0)
- return TRUE;
- ++i;
- }
+ typedef int (*Comparator)(const void*, const void*);
- return FALSE;
+ return bsearch(me->me_type,
+ ignored, G_N_ELEMENTS(ignored), sizeof ignored[0],
+ (Comparator) strcmp) != NULL;
}