Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 434c916

Browse files
drinkcattgross35
authored andcommitted
newlib/espidf: Add espidf_picolibc cfg for picolibc O_* flag values
ESP-IDF v6.0 switched from newlib to picolibc as default C library. Picolibc uses Linux-compatible O_APPEND/O_CREAT/O_TRUNC values which differ from newlib. Add espidf_picolibc cfg to select the correct values.
1 parent 9b6bf99 commit 434c916

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::{
1313
// make sure to add it to this list as well.
1414
const ALLOWED_CFGS: &[&str] = &[
1515
"emscripten_old_stat_abi",
16+
// Should be enabled by users if esp-idf (>=6.0) is build with picolibc instead of newlib.
17+
"espidf_picolibc",
1618
"espidf_time32",
1719
"freebsd10",
1820
"freebsd11",

src/unix/newlib/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,17 @@ pub const F_DUPFD_CLOEXEC: c_int = 14;
514514
pub const O_RDONLY: c_int = 0;
515515
pub const O_WRONLY: c_int = 1;
516516
pub const O_RDWR: c_int = 2;
517-
pub const O_APPEND: c_int = 8;
518-
pub const O_CREAT: c_int = 512;
519-
pub const O_TRUNC: c_int = 1024;
517+
cfg_if! {
518+
if #[cfg(espidf_picolibc)] {
519+
pub const O_APPEND: c_int = 1024;
520+
pub const O_CREAT: c_int = 64;
521+
pub const O_TRUNC: c_int = 512;
522+
} else {
523+
pub const O_APPEND: c_int = 8;
524+
pub const O_CREAT: c_int = 512;
525+
pub const O_TRUNC: c_int = 1024;
526+
}
527+
}
520528
pub const O_EXCL: c_int = 2048;
521529
pub const O_SYNC: c_int = 8192;
522530
pub const O_NONBLOCK: c_int = 16384;

0 commit comments

Comments
 (0)