Debian Codegraph @

tests/empty_mounts.c

raw symbols SCIP
1 /*
2 * libhugetlbfs - Easy use of Linux hugepages
3 * Copyright (C) 2005-2006 David Gibson & Adam Litke, IBM Corporation.
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 License
7 * as published by the Free Software Foundation; either version 2.1 of
8 * the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but
11 * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #define _GNU_SOURCE
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <dlfcn.h>
28 #include <stdarg.h>
29
30 #include <hugetlbfs.h>
31
32 #include "hugetests.h"
33
34 /* We override the normal open, so libhugetlbfs gets an apparently
35 * empty /proc/mounts or /etc/mtab */
36 int open(const char *path, int flags, ...)
37 {
38 int (*old_open)(const char *, int, ...);
39 int fd;
40
41 if ((strcmp(path, "/proc/mounts") == 0)
42 || (strcmp(path, "/etc/mtab") == 0))
43 path = "/dev/null";
44
45 old_open = dlsym(RTLD_NEXT, "open");
46 if (flags & O_CREAT) {
47 va_list ap;
48
49 va_start(ap, flags);
50 fd = (*old_open)(path, flags, va_arg(ap, mode_t));
51 va_end(ap);
52 return fd;
53 } else {
54 return (*old_open)(path, flags);
55 }
56 }
57
58 int main(int argc, char *argv[])
59 {
60 int fd;
61
62 test_init(argc, argv);
63
64 fd = hugetlbfs_unlinked_fd();
65 if (fd < 0)
66 PASS();
67
68 FAIL("Mysteriously found a mount");
69 }