From f00bc469e2a13b2a966a51de7dc3c094829a6ea6 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 28 Apr 2010 15:35:52 +0000 Subject: [PATCH] * mount.cc (compare_flags): New function. (read_flags): Replace loop with bsearch. Simplify error check. --- winsup/cygwin/ChangeLog | 5 +++++ winsup/cygwin/mount.cc | 40 ++++++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 5a13b93f7..f4465b6ea 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,8 @@ +2010-04-28 Corinna Vinschen + + * mount.cc (compare_flags): New function. + (read_flags): Replace loop with bsearch. Simplify error check. + 2010-04-28 Corinna Vinschen * include/cygwin/version.h: Bump API minor version. 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;