Debian Codegraph @

tests/API/probes/test_fsdev_is_local_fs.c

raw symbols SCIP
1 /*
2 * Copyright 2019 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * "Jan Černý" <[email protected]m>
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdio.h>
28 #include <string.h>
29 #include "fsdev.h"
30 #include "fsdev.c"
31
32 #if defined(OS_LINUX) || defined(OS_AIX)
33 #include <mntent.h>
34
35 static int test_single_call()
36 {
37 struct mntent ment = {0};
38 ment.mnt_type = "autofs";
39 int ret = is_local_fs(&ment);
40 /* autofs entry is never considered local */
41 return (ret == 0);
42 }
43
44 static int test_multiple_calls(const char *fake_mtab)
45 {
46 /*
47 * fake mtab contains only 3 local filesystems:
48 * /, /tmp, and /home
49 */
50 FILE *f = setmntent(fake_mtab, "r");
51 if (f == NULL) {
52 fprintf(stderr, "fake_mtab could not be open\n");
53 return 0;
54 }
55 struct mntent *ment;
56 unsigned int locals = 0;
57 while ((ment = getmntent(f)) != NULL) {
58 if (is_local_fs(ment)) {
59 locals++;
60 }
61 }
62 endmntent(f);
63 return (locals == 3);
64 }
65
66 int main(int argc, char *argv[])
67 {
68 if (!test_single_call()) {
69 fprintf(stderr, "test_single_call has failed\n");
70 return 1;
71 }
72 if (!test_multiple_calls(argv[1])) {
73 fprintf(stderr, "test_multiple_calls has failed\n");
74 return 1;
75 }
76 return 0;
77 }
78
79 #else
80
81 int main(int argc, char *argv[])
82 {
83 fprintf(stderr, "is_local is only defined and used by Linux and AIX\n");
84 return 0;
85 }
86
87 #endif