| 99 | #[cfg(not(target_os = "android"))] |
| 100 | #[pyfunction] |
| 101 | fn getpwall(vm: &VirtualMachine) -> PyResult<Vec<PyObjectRef>> { |
| 102 | // setpwent, getpwent, etc are not thread safe. Could use fgetpwent_r, but this is easier |
| 103 | static GETPWALL: parking_lot::Mutex<()> = parking_lot::Mutex::new(()); |
| 104 | let _guard = GETPWALL.lock(); |
| 105 | let mut list = Vec::new(); |
| 106 | |
| 107 | unsafe { libc::setpwent() }; |
| 108 | while let Some(ptr) = core::ptr::NonNull::new(unsafe { libc::getpwent() }) { |
| 109 | let user = User::from(unsafe { ptr.as_ref() }); |
| 110 | let passwd = PasswdData::from(user).to_pyobject(vm); |
| 111 | list.push(passwd); |
| 112 | } |
| 113 | unsafe { libc::endpwent() }; |
| 114 | |
| 115 | Ok(list) |
| 116 | } |
| 117 | } |