Skip to content

Commit 1d61311

Browse files
Elie-KhJohnTitor
authored andcommitted
unix: add preadv2 and pwritev2 to android and linux.
Add preadv2 and pwrite2 to linux and Android, to allow using the new flags introduced in #4452. Add flags to Android too Move definitions from musl and gnu to linux/mod.rs instead of each separate system alone. Skip test on Android due to the definitions being introduced in API 33
1 parent f228f26 commit 1d61311

5 files changed

Lines changed: 43 additions & 30 deletions

File tree

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,9 @@ fn test_android(target: &str) {
22052205
// Added in API level 30, but tests use level 28.
22062206
"memfd_create" | "mlock2" | "renameat2" | "statx" | "statx_timestamp" => true,
22072207

2208+
// Added in API level 33, but tests use level 28.
2209+
"preadv2" | "pwritev2" => true,
2210+
22082211
// Added in glibc 2.25.
22092212
"getentropy" => true,
22102213

src/unix/linux_like/android/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,6 +3276,16 @@ pub const AT_MINSIGSTKSZ: c_ulong = 51;
32763276
pub const SI_DETHREAD: c_int = -7;
32773277
pub const TRAP_PERF: c_int = 6;
32783278

3279+
// Flags for preadv2/pwritev2
3280+
pub const RWF_HIPRI: c_int = 0x00000001;
3281+
pub const RWF_DSYNC: c_int = 0x00000002;
3282+
pub const RWF_SYNC: c_int = 0x00000004;
3283+
pub const RWF_NOWAIT: c_int = 0x00000008;
3284+
pub const RWF_APPEND: c_int = 0x00000010;
3285+
pub const RWF_NOAPPEND: c_int = 0x00000020;
3286+
pub const RWF_ATOMIC: c_int = 0x00000040;
3287+
pub const RWF_DONTCACHE: c_int = 0x00000080;
3288+
32793289
// Most `*_SUPER_MAGIC` constants are defined at the `linux_like` level; the
32803290
// following are only available on newer Linux versions than the versions
32813291
// currently used in CI in some configurations, so we define them here.
@@ -3747,6 +3757,20 @@ extern "C" {
37473757
newpath: *const c_char,
37483758
flags: c_uint,
37493759
) -> c_int;
3760+
pub fn preadv2(
3761+
fd: c_int,
3762+
iov: *const crate::iovec,
3763+
iovcnt: c_int,
3764+
offset: off_t,
3765+
flags: c_int,
3766+
) -> ssize_t;
3767+
pub fn pwritev2(
3768+
fd: c_int,
3769+
iov: *const crate::iovec,
3770+
iovcnt: c_int,
3771+
offset: off_t,
3772+
flags: c_int,
3773+
) -> ssize_t;
37503774
}
37513775

37523776
cfg_if! {

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,22 +1029,6 @@ extern "C" {
10291029
dirfd: c_int,
10301030
path: *const c_char,
10311031
) -> c_int;
1032-
#[cfg_attr(gnu_file_offset_bits64, link_name = "preadv64v2")]
1033-
pub fn preadv2(
1034-
fd: c_int,
1035-
iov: *const crate::iovec,
1036-
iovcnt: c_int,
1037-
offset: off_t,
1038-
flags: c_int,
1039-
) -> ssize_t;
1040-
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwritev64v2")]
1041-
pub fn pwritev2(
1042-
fd: c_int,
1043-
iov: *const crate::iovec,
1044-
iovcnt: c_int,
1045-
offset: off_t,
1046-
flags: c_int,
1047-
) -> ssize_t;
10481032
pub fn preadv64v2(
10491033
fd: c_int,
10501034
iov: *const crate::iovec,

src/unix/linux_like/linux/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4360,6 +4360,22 @@ extern "C" {
43604360
flags: c_int,
43614361
) -> c_int;
43624362
pub fn open_by_handle_at(mount_fd: c_int, handle: *mut file_handle, flags: c_int) -> c_int;
4363+
#[cfg_attr(gnu_file_offset_bits64, link_name = "preadv64v2")]
4364+
pub fn preadv2(
4365+
fd: c_int,
4366+
iov: *const crate::iovec,
4367+
iovcnt: c_int,
4368+
offset: off_t,
4369+
flags: c_int,
4370+
) -> ssize_t;
4371+
#[cfg_attr(gnu_file_offset_bits64, link_name = "pwritev64v2")]
4372+
pub fn pwritev2(
4373+
fd: c_int,
4374+
iov: *const crate::iovec,
4375+
iovcnt: c_int,
4376+
offset: off_t,
4377+
flags: c_int,
4378+
) -> ssize_t;
43634379
}
43644380

43654381
// LFS64 extensions

src/unix/linux_like/linux/musl/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -780,20 +780,6 @@ extern "C" {
780780
dirfd: c_int,
781781
path: *const c_char,
782782
) -> c_int;
783-
pub fn preadv2(
784-
fd: c_int,
785-
iov: *const crate::iovec,
786-
iovcnt: c_int,
787-
offset: off_t,
788-
flags: c_int,
789-
) -> ssize_t;
790-
pub fn pwritev2(
791-
fd: c_int,
792-
iov: *const crate::iovec,
793-
iovcnt: c_int,
794-
offset: off_t,
795-
flags: c_int,
796-
) -> ssize_t;
797783
pub fn getauxval(type_: c_ulong) -> c_ulong;
798784
pub fn renameat2(
799785
olddirfd: c_int,

0 commit comments

Comments
 (0)