1#include <string.h>
2
3static int fsopt_matches(const char *opts_list, const char *opt, size_t optlen)
4{
5 int match = 1;
6
7 if (optlen >= 2 && opt[0] == 'n' && opt[1] == 'o') {
8 match--;
9 opt += 2; optlen -= 2;
10 }
11
12 if (optlen == 0)
13 return 0;
14 if (match && optlen > 1 && *opt == '+') {
15 opt++; optlen--;
16 }
17
18 while (1) {
19 if (strncmp(opts_list, opt, optlen) == 0) {
20 const char *after_opt = opts_list + optlen;
21 if (*after_opt == '\0' || *after_opt == ',')
22 return match;
23 }
24
25 opts_list = strchr(opts_list, ',');
26 if (!opts_list)
27 break;
28 opts_list++;
29 }
30
31 return !match;
32}
33
34int fsopts_matches(const char *opts_list, const char *reqopts_list)
35{
36 if (!reqopts_list)
37 return 1; /* no options requested, match anything */
38
39 while (1) {
40 size_t len;
41 const char *comma = strchr(reqopts_list, ',');
42 if (!comma)
43 len = strlen(reqopts_list);
44 else
45 len = comma - reqopts_list;
46
47 if (len && !fsopt_matches(opts_list, reqopts_list, len))
48 return 0;
49
50 if (!comma)
51 break;
52 reqopts_list = ++comma;
53 }
54
55 return 1;
56}