Use nix for libc functions

This commit is contained in:
topjohnwu
2025-09-08 23:59:29 -07:00
parent 17082af438
commit ef4e230258
31 changed files with 457 additions and 475 deletions
+3 -2
View File
@@ -6,8 +6,9 @@ use argh::{EarlyExit, FromArgs, MissingRequirements};
use base::libc::PROP_VALUE_MAX;
use base::{
BufReadExt, CmdArgs, EarlyExitExt, LogLevel, LoggedResult, ResultExt, Utf8CStr, Utf8CStrBuf,
Utf8CString, cstr, debug, libc, log_err, set_log_level_state,
Utf8CString, cstr, debug, log_err, set_log_level_state,
};
use nix::fcntl::OFlag;
use std::collections::BTreeMap;
use std::ffi::c_char;
use std::io::BufReader;
@@ -211,7 +212,7 @@ impl ResetProp {
}
fn load_file(&self, file: &Utf8CStr) -> LoggedResult<()> {
let fd = file.open(libc::O_RDONLY | libc::O_CLOEXEC)?;
let fd = file.open(OFlag::O_RDONLY | OFlag::O_CLOEXEC)?;
let mut key = cstr::buf::dynamic(128);
let mut val = cstr::buf::dynamic(128);
BufReader::new(fd).for_each_prop(|k, v| {
+3 -4
View File
@@ -1,3 +1,5 @@
use nix::fcntl::OFlag;
use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Writer};
use std::io::Read;
use std::{
fs::File,
@@ -5,14 +7,11 @@ use std::{
os::fd::FromRawFd,
};
use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Writer};
use crate::resetprop::PropReader;
use crate::resetprop::proto::persistent_properties::{
PersistentProperties, mod_PersistentProperties::PersistentPropertyRecord,
};
use base::const_format::concatcp;
use base::libc::{O_CLOEXEC, O_RDONLY};
use base::{
Directory, FsPathBuilder, LibcReturn, LoggedResult, MappedFile, SilentLogExt, Utf8CStr,
Utf8CStrBuf, WalkResult, clone_attr, cstr, debug, libc::mkstemp, log_err,
@@ -46,7 +45,7 @@ fn file_get_prop(name: &Utf8CStr) -> LoggedResult<String> {
let path = cstr::buf::default()
.join_path(PERSIST_PROP_DIR)
.join_path(name);
let mut file = path.open(O_RDONLY | O_CLOEXEC).silent()?;
let mut file = path.open(OFlag::O_RDONLY | OFlag::O_CLOEXEC).silent()?;
debug!("resetprop: read prop from [{}]", path);
let mut s = String::new();
file.read_to_string(&mut s)?;