MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / test_openat2

Function test_openat2

tests/fs/openat2.rs:24–192  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22
23#[test]
24fn test_openat2() {
25 let tmp = tempfile::tempdir().unwrap();
26 let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
27
28 // Detect whether `openat2` is available.
29 match openat2(
30 &dir,
31 ".",
32 OFlags::RDONLY | OFlags::CLOEXEC,
33 Mode::empty(),
34 ResolveFlags::empty(),
35 ) {
36 Ok(_file) => (),
37 Err(io::Errno::NOSYS) => return,
38 Err(_err) => return,
39 }
40
41 // Create a file.
42 let _ = openat2_more(
43 &dir,
44 "test.txt",
45 OFlags::WRONLY | OFlags::CREATE | OFlags::TRUNC | OFlags::CLOEXEC,
46 Mode::RUSR,
47 ResolveFlags::empty(),
48 )
49 .unwrap();
50
51 // Test `NO_SYMLINKS`.
52 symlinkat("test.txt", &dir, "symlink.txt").unwrap();
53 let _ = openat2_more(
54 &dir,
55 "symlink.txt",
56 OFlags::RDONLY | OFlags::CLOEXEC,
57 Mode::empty(),
58 ResolveFlags::empty(),
59 )
60 .unwrap();
61 let _ = openat2_more(
62 &dir,
63 "symlink.txt",
64 OFlags::RDONLY | OFlags::CLOEXEC,
65 Mode::empty(),
66 ResolveFlags::NO_MAGICLINKS,
67 )
68 .unwrap();
69 let _ = openat2_more(
70 &dir,
71 "symlink.txt",
72 OFlags::RDONLY | OFlags::CLOEXEC,
73 Mode::empty(),
74 ResolveFlags::NO_SYMLINKS,
75 )
76 .unwrap_err();
77
78 // Test with `O_PATH`.
79 let _ = openat2_more(
80 &dir,
81 "test.txt",

Callers

nothing calls this directly

Calls 6

openat2_moreFunction · 0.85
openatFunction · 0.50
openat2Function · 0.50
symlinkatFunction · 0.50
mkdiratFunction · 0.50
pathMethod · 0.45

Tested by

no test coverage detected