我如何使用与C打开功能匹配的i32打开带有标志的文件?

问题描述 投票:0回答:1

我需要打开一个文件,并且我的标志有&Pathi32。我可以用File::open(path)打开文件,但这不能让我设置选项。文档说我应该使用OpenOptions,但是我看不出有什么方法可以从OpenOptions中获取i32。我的标志的内容定义为open(2)

我要使用的标志是526338,如果您想自己对其进行测试。

rust libc
1个回答
3
投票

假设您使用的是类似Unix的系统,则可以使用OpenOptionsExt设置标志:

OpenOptionsExt

注意,您必须分别设置访问模式标志(例如,通过调用use std::fs::OpenOptions; use std::os::unix::fs::OpenOptionsExt; let file = OpenOptions::new() .read(true) .custom_flags(flags) .open(&path)?; read),因此,如果需要它们,则必须自己处理。例如:

write
© www.soinside.com 2019 - 2024. All rights reserved.