* mount.cc (compare_flags): New function.

(read_flags): Replace loop with bsearch.  Simplify error check.
This commit is contained in:
Corinna Vinschen 2010-04-28 15:35:52 +00:00
parent 8f47a15cef
commit f00bc469e2
2 changed files with 29 additions and 16 deletions

View File

@ -1,3 +1,8 @@
2010-04-28 Corinna Vinschen <corinna@vinschen.de>
* mount.cc (compare_flags): New function.
(read_flags): Replace loop with bsearch. Simplify error check.
2010-04-28 Corinna Vinschen <corinna@vinschen.de> 2010-04-28 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump API minor version. * include/cygwin/version.h: Bump API minor version.

View File

@ -944,9 +944,20 @@ struct opt
{"user", MOUNT_SYSTEM, 1} {"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 static bool
read_flags (char *options, unsigned &flags) read_flags (char *options, unsigned &flags)
{ {
opt key;
while (*options) while (*options)
{ {
char *p = strchr (options, ','); char *p = strchr (options, ',');
@ -955,21 +966,18 @@ read_flags (char *options, unsigned &flags)
else else
p = strchr (options, '\0'); p = strchr (options, '\0');
for (opt *o = oopts; key.name = options;
o < (oopts + (sizeof (oopts) / sizeof (oopts[0]))); opt *o = (opt *) bsearch (&key, oopts, sizeof oopts / sizeof (opt),
o++) sizeof (opt), compare_flags);
if (strcmp (options, o->name) == 0) if (!o)
{ {
system_printf ("invalid fstab option - '%s'", options);
return false;
}
if (o->clear) if (o->clear)
flags &= ~o->val; flags &= ~o->val;
else else
flags |= o->val; flags |= o->val;
goto gotit;
}
system_printf ("invalid fstab option - '%s'", options);
return false;
gotit:
options = p; options = p;
} }
return true; return true;