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

Function test_readlinkat_raw

tests/fs/readlinkat.rs:56–98  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54#[cfg(not(target_os = "redox"))]
55#[test]
56fn test_readlinkat_raw() {
57 use core::mem::MaybeUninit;
58 use rustix::fs::{openat, readlinkat_raw, symlinkat, Mode, OFlags, CWD};
59 use std::ffi::OsStr;
60 use std::os::unix::ffi::OsStrExt as _;
61
62 let tmp = tempfile::tempdir().unwrap();
63 let dir = openat(CWD, tmp.path(), OFlags::RDONLY, Mode::empty()).unwrap();
64
65 let _ = openat(&dir, "file", OFlags::CREATE | OFlags::WRONLY, Mode::RUSR).unwrap();
66 symlinkat("file", &dir, "link").unwrap();
67
68 let mut some = [MaybeUninit::<u8>::new(0); 32];
69 let mut short = [MaybeUninit::<u8>::new(0); 2];
70 readlinkat_raw(&dir, "absent", &mut some).unwrap_err();
71 readlinkat_raw(&dir, "file", &mut some).unwrap_err();
72
73 let (yes, no) = readlinkat_raw(&dir, "link", &mut some).unwrap();
74 assert_eq!(OsStr::from_bytes(yes).to_string_lossy(), "file");
75 assert!(!no.is_empty());
76
77 let (yes, no) = readlinkat_raw(&dir, "link", &mut short).unwrap();
78 assert_eq!(yes, b"fi");
79 assert!(no.is_empty());
80
81 symlinkat("link", &dir, "another").unwrap();
82
83 let (yes, no) = readlinkat_raw(&dir, "link", &mut some).unwrap();
84 assert_eq!(OsStr::from_bytes(yes).to_string_lossy(), "file");
85 assert!(!no.is_empty());
86
87 let (yes, no) = readlinkat_raw(&dir, "link", &mut short).unwrap();
88 assert_eq!(yes, b"fi");
89 assert!(no.is_empty());
90
91 let (yes, no) = readlinkat_raw(&dir, "another", &mut some).unwrap();
92 assert_eq!(OsStr::from_bytes(yes).to_string_lossy(), "link");
93 assert!(!no.is_empty());
94
95 let (yes, no) = readlinkat_raw(&dir, "another", &mut short).unwrap();
96 assert_eq!(yes, b"li");
97 assert!(no.is_empty());
98}

Callers

nothing calls this directly

Calls 4

readlinkat_rawFunction · 0.85
openatFunction · 0.50
symlinkatFunction · 0.50
pathMethod · 0.45

Tested by

no test coverage detected