1 /* Copyright 2021, Google Inc. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 *
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following disclaimer
11 * in the documentation and/or other materials provided with the
12 * distribution.
13 * * Neither the name of Google Inc. nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include "test_skel.h"
31
main(int argc,char * argv[])32 int main(int argc, char *argv[]) {
33 int exit_status = 0;
34
35 // Get two unique paths to play with.
36 char foo[] = "tempfile.XXXXXX";
37 int fd_foo = mkstemp(foo);
38 assert(fd_foo != -1);
39
40 // Make sure it exists.
41 assert(access(foo, F_OK) == 0);
42
43 // Make sure sys_stat() and a libc stat() implementation return the same
44 // information.
45 struct stat libc_stat;
46 assert(stat(foo, &libc_stat) == 0);
47
48 struct kernel_stat raw_stat;
49 // We need to check our stat syscall for EOVERFLOW, as sometimes the integer
50 // types used in the stat structures are too small to fit the actual value.
51 // E.g. on some systems st_ino is 32-bit, but some filesystems have 64-bit
52 // inodes.
53 int rc = sys_stat(foo, &raw_stat);
54 if (rc < 0 && errno == EOVERFLOW) {
55 // Bail out since we had an overflow in the stat structure.
56 exit_status = SKIP_TEST_EXIT_STATUS;
57 goto cleanup;
58 }
59 assert(rc == 0);
60
61 assert(libc_stat.st_ino == raw_stat.st_ino);
62
63
64 cleanup:
65 sys_unlink(foo);
66 return exit_status;
67 }
68