Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2010-04-28 19:35:52 +0400
committerCorinna Vinschen <corinna@vinschen.de>2010-04-28 19:35:52 +0400
commitf00bc469e2a13b2a966a51de7dc3c094829a6ea6 (patch)
tree5acb3078d35566b4a8358b24c348f26f90b41ee1 /winsup/cygwin/mount.cc
parent8f47a15cef72e29e9249f4b49167830264a2d6b4 (diff)
* mount.cc (compare_flags): New function.
(read_flags): Replace loop with bsearch. Simplify error check.
Diffstat (limited to 'winsup/cygwin/mount.cc')
-rw-r--r--winsup/cygwin/mount.cc40
1 files changed, 24 insertions, 16 deletions
diff --git a/winsup/cygwin/mount.cc b/winsup/cygwin/mount.cc
index ee9c94f19..528c8b65a 100644
--- a/winsup/cygwin/mount.cc
+++ b/winsup/cygwin/mount.cc
@@ -944,9 +944,20 @@ struct opt
{"user", MOUNT_SYSTEM, 1}
};
+static int
+compare_flags (const void *a, const void *b)
+{
+ const opt *oa = (const opt *) a;
+ const opt *ob = (const opt *) b;
+
+ return strcmp (oa->name, ob->name);
+}
+
static bool
read_flags (char *options, unsigned &flags)
{
+ opt key;
+
while (*options)
{
char *p = strchr (options, ',');
@@ -954,22 +965,19 @@ read_flags (char *options, unsigned &flags)
*p++ = '\0';
else
p = strchr (options, '\0');
-
- for (opt *o = oopts;
- o < (oopts + (sizeof (oopts) / sizeof (oopts[0])));
- o++)
- if (strcmp (options, o->name) == 0)
- {
- if (o->clear)
- flags &= ~o->val;
- else
- flags |= o->val;
- goto gotit;
- }
- system_printf ("invalid fstab option - '%s'", options);
- return false;
-
- gotit:
+
+ key.name = options;
+ opt *o = (opt *) bsearch (&key, oopts, sizeof oopts / sizeof (opt),
+ sizeof (opt), compare_flags);
+ if (!o)
+ {
+ system_printf ("invalid fstab option - '%s'", options);
+ return false;
+ }
+ if (o->clear)
+ flags &= ~o->val;
+ else
+ flags |= o->val;
options = p;
}
return true;