1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* telldir.c -- Android compatibility hack because bionic doesn't
* support hasmntopt()
*/
#include <stdio.h>
#include <string.h>
#include <mntent.h>
char *hasmntopt(const struct mntent *mnt, const char *opt)
{
char *cp = mnt->mnt_opts;
int len = strlen(opt);
if (!mnt->mnt_opts)
return 0;
while (1) {
if (!(cp = strstr(cp, opt)))
break;
if ((cp == mnt->mnt_opts || cp[-1]==',') &&
(cp[len] == 0 || cp[len] == ',' || cp[len] == '='))
return cp;
cp += (len + 1);
}
return 0;
}
#ifdef DEBUG
struct test_list {
const char *opt;
int expected;
} tst[] = {
{ "foo", 1 },
{ "bar", 1 },
{ "baz", 1 },
{ "quux", 0 },
{ "zork", 0 },
{ NULL, 0 }
};
int main(int argc, char **argv)
{
struct mntent m;
struct test_list *t;
int errors = 0;
memset(&m, 0, sizeof(m));
m.mnt_opts = "foo,bar=quux,baz";
for (t = tst; t->opt; t++) {
char *cp;
int actual;
cp = hasmntopt(&m, t->opt);
actual = (cp != NULL);
printf("hasmntopt(m, %s) returned %s: %s\n",
t->opt, cp ? cp : "NULL", actual == t->expected ?
"OK" : "FAIL");
if (actual != t->expected)
errors++;
}
return errors;
}
#endif
|