Mercurial > crates > nonstick
comparison src/libpam/environ.rs @ 143:ebb71a412b58
Turn everything into OsString and Just Walk Out! for strings with nul.
To reduce the hazard surface of the API, this replaces most uses of &str
with &OsStr (and likewise with String/OsString).
Also, I've decided that instead of dealing with callers putting `\0`
in their parameters, I'm going to follow the example of std::env and
Just Walk Out! (i.e., panic!()).
This makes things a lot less annoying for both me and (hopefully) users.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 05 Jul 2025 22:12:46 -0400 |
parents | a508a69c068a |
children | 56b559b7ecea |
comparison
equal
deleted
inserted
replaced
142:5c1e315c18ff | 143:ebb71a412b58 |
---|---|
197 } | 197 } |
198 | 198 |
199 #[test] | 199 #[test] |
200 fn test_split_kv() { | 200 fn test_split_kv() { |
201 fn test(input: &str, key: &str, value: &str) { | 201 fn test(input: &str, key: &str, value: &str) { |
202 let data = CHeapString::new(input).unwrap(); | 202 let data = CHeapString::new(input); |
203 let key = os(key); | 203 let key = os(key); |
204 let value = os(value); | 204 let value = os(value); |
205 | 205 |
206 assert_eq!(EnvVar(data).as_kv(), (key, value)); | 206 assert_eq!(EnvVar(data).as_kv(), (key, value)); |
207 } | 207 } |
214 | 214 |
215 fn env_list(strings: &[&'static str]) -> EnvList<'static> { | 215 fn env_list(strings: &[&'static str]) -> EnvList<'static> { |
216 let ptrs: NonNull<Option<CHeapString>> = memory::calloc(strings.len() + 1); | 216 let ptrs: NonNull<Option<CHeapString>> = memory::calloc(strings.len() + 1); |
217 unsafe { | 217 unsafe { |
218 for (idx, &text) in strings.iter().enumerate() { | 218 for (idx, &text) in strings.iter().enumerate() { |
219 ptr::write( | 219 ptr::write(ptrs.as_ptr().add(idx), Some(CHeapString::new(text))) |
220 ptrs.as_ptr().add(idx), | |
221 Some(CHeapString::new(text).unwrap()), | |
222 ) | |
223 } | 220 } |
224 ptr::write(ptrs.as_ptr().add(strings.len()), None); | 221 ptr::write(ptrs.as_ptr().add(strings.len()), None); |
225 EnvList::from_ptr(ptrs.cast()) | 222 EnvList::from_ptr(ptrs.cast()) |
226 } | 223 } |
227 } | 224 } |