Skip to content

Commit 6c5ef4f

Browse files
notgullsunfishcode
authored andcommitted
Remove linux-raw-sys and libc from public API (#956)
* Remove linux-raw-sys and libc from public API This prevents libc and linux-raw-sys from affecting the semver status of this crate. Signed-off-by: John Nunley <[email protected]> * Fix compile errors Signed-off-by: John Nunley <[email protected]> --------- Signed-off-by: John Nunley <[email protected]>
1 parent 777fbc6 commit 6c5ef4f

File tree

26 files changed

+187
-208
lines changed

26 files changed

+187
-208
lines changed

src/backend/libc/fs/syscalls.rs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use crate::backend::c;
99
use crate::backend::conv::ret_usize;
1010
use crate::backend::conv::{borrowed_fd, c_str, ret, ret_c_int, ret_off_t, ret_owned_fd};
1111
use crate::fd::{BorrowedFd, OwnedFd};
12-
use crate::ffi::CStr;
1312
#[cfg(all(apple, feature = "alloc"))]
1413
use crate::ffi::CString;
14+
use crate::ffi::{self, CStr};
1515
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
1616
use crate::fs::Access;
1717
#[cfg(not(any(
@@ -89,7 +89,7 @@ use {
8989
};
9090

9191
#[cfg(all(target_env = "gnu", fix_y2038))]
92-
weak!(fn __utimensat64(c::c_int, *const c::c_char, *const LibcTimespec, c::c_int) -> c::c_int);
92+
weak!(fn __utimensat64(c::c_int, *const ffi::c_char, *const LibcTimespec, c::c_int) -> c::c_int);
9393
#[cfg(all(target_env = "gnu", fix_y2038))]
9494
weak!(fn __futimens64(c::c_int, *const LibcTimespec) -> c::c_int);
9595

@@ -122,7 +122,7 @@ fn open_via_syscall(path: &CStr, oflags: OFlags, mode: Mode) -> io::Result<Owned
122122
unsafe {
123123
syscall! {
124124
fn open(
125-
pathname: *const c::c_char,
125+
pathname: *const ffi::c_char,
126126
oflags: c::c_int,
127127
mode: c::mode_t
128128
) via SYS_open -> c::c_int
@@ -182,7 +182,7 @@ fn openat_via_syscall(
182182
syscall! {
183183
fn openat(
184184
base_dirfd: c::c_int,
185-
pathname: *const c::c_char,
185+
pathname: *const ffi::c_char,
186186
oflags: c::c_int,
187187
mode: c::mode_t
188188
) via SYS_openat -> c::c_int
@@ -277,9 +277,11 @@ pub(crate) fn statvfs(filename: &CStr) -> io::Result<StatVfs> {
277277
#[inline]
278278
pub(crate) fn readlink(path: &CStr, buf: &mut [u8]) -> io::Result<usize> {
279279
unsafe {
280-
ret_usize(
281-
c::readlink(c_str(path), buf.as_mut_ptr().cast::<c::c_char>(), buf.len()) as isize,
282-
)
280+
ret_usize(c::readlink(
281+
c_str(path),
282+
buf.as_mut_ptr().cast::<ffi::c_char>(),
283+
buf.len(),
284+
) as isize)
283285
}
284286
}
285287

@@ -294,7 +296,7 @@ pub(crate) fn readlinkat(
294296
ret_usize(c::readlinkat(
295297
borrowed_fd(dirfd),
296298
c_str(path),
297-
buf.as_mut_ptr().cast::<c::c_char>(),
299+
buf.as_mut_ptr().cast::<ffi::c_char>(),
298300
buf.len(),
299301
) as isize)
300302
}
@@ -354,9 +356,9 @@ pub(crate) fn linkat(
354356
weak! {
355357
fn linkat(
356358
c::c_int,
357-
*const c::c_char,
359+
*const ffi::c_char,
358360
c::c_int,
359-
*const c::c_char,
361+
*const ffi::c_char,
360362
c::c_int
361363
) -> c::c_int
362364
}
@@ -411,7 +413,7 @@ pub(crate) fn unlinkat(dirfd: BorrowedFd<'_>, path: &CStr, flags: AtFlags) -> io
411413
weak! {
412414
fn unlinkat(
413415
c::c_int,
414-
*const c::c_char,
416+
*const ffi::c_char,
415417
c::c_int
416418
) -> c::c_int
417419
}
@@ -464,9 +466,9 @@ pub(crate) fn renameat(
464466
weak! {
465467
fn renameat(
466468
c::c_int,
467-
*const c::c_char,
469+
*const ffi::c_char,
468470
c::c_int,
469-
*const c::c_char
471+
*const ffi::c_char
470472
) -> c::c_int
471473
}
472474
// If we have `renameat`, use it.
@@ -508,9 +510,9 @@ pub(crate) fn renameat2(
508510
weak_or_syscall! {
509511
fn renameat2(
510512
olddirfd: c::c_int,
511-
oldpath: *const c::c_char,
513+
oldpath: *const ffi::c_char,
512514
newdirfd: c::c_int,
513-
newpath: *const c::c_char,
515+
newpath: *const ffi::c_char,
514516
flags: c::c_uint
515517
) via SYS_renameat2 -> c::c_int
516518
}
@@ -547,9 +549,9 @@ pub(crate) fn renameat2(
547549
syscall! {
548550
fn renameat2(
549551
olddirfd: c::c_int,
550-
oldpath: *const c::c_char,
552+
oldpath: *const ffi::c_char,
551553
newdirfd: c::c_int,
552-
newpath: *const c::c_char,
554+
newpath: *const ffi::c_char,
553555
flags: c::c_uint
554556
) via SYS_renameat2 -> c::c_int
555557
}
@@ -750,7 +752,7 @@ pub(crate) fn accessat(
750752
weak! {
751753
fn faccessat(
752754
c::c_int,
753-
*const c::c_char,
755+
*const ffi::c_char,
754756
c::c_int,
755757
c::c_int
756758
) -> c::c_int
@@ -857,14 +859,14 @@ pub(crate) fn utimensat(
857859
weak! {
858860
fn utimensat(
859861
c::c_int,
860-
*const c::c_char,
862+
*const ffi::c_char,
861863
*const c::timespec,
862864
c::c_int
863865
) -> c::c_int
864866
}
865867
extern "C" {
866868
fn setattrlist(
867-
path: *const c::c_char,
869+
path: *const ffi::c_char,
868870
attr_list: *const Attrlist,
869871
attr_buf: *const c::c_void,
870872
attr_buf_size: c::size_t,
@@ -1051,7 +1053,7 @@ pub(crate) fn chmodat(
10511053
syscall! {
10521054
fn fchmodat(
10531055
base_dirfd: c::c_int,
1054-
pathname: *const c::c_char,
1056+
pathname: *const ffi::c_char,
10551057
mode: c::mode_t
10561058
) via SYS_fchmodat -> c::c_int
10571059
}
@@ -1081,7 +1083,7 @@ pub(crate) fn fclonefileat(
10811083
fn fclonefileat(
10821084
srcfd: BorrowedFd<'_>,
10831085
dst_dirfd: BorrowedFd<'_>,
1084-
dst: *const c::c_char,
1086+
dst: *const ffi::c_char,
10851087
flags: c::c_int
10861088
) via SYS_fclonefileat -> c::c_int
10871089
}
@@ -1713,15 +1715,15 @@ pub(crate) fn memfd_create(name: &CStr, flags: MemfdFlags) -> io::Result<OwnedFd
17131715
#[cfg(target_os = "freebsd")]
17141716
weakcall! {
17151717
fn memfd_create(
1716-
name: *const c::c_char,
1718+
name: *const ffi::c_char,
17171719
flags: c::c_uint
17181720
) -> c::c_int
17191721
}
17201722

17211723
#[cfg(linux_kernel)]
17221724
weak_or_syscall! {
17231725
fn memfd_create(
1724-
name: *const c::c_char,
1726+
name: *const ffi::c_char,
17251727
flags: c::c_uint
17261728
) via SYS_memfd_create -> c::c_int
17271729
}
@@ -1742,7 +1744,7 @@ pub(crate) fn openat2(
17421744
syscall! {
17431745
fn openat2(
17441746
base_dirfd: c::c_int,
1745-
pathname: *const c::c_char,
1747+
pathname: *const ffi::c_char,
17461748
how: *mut open_how,
17471749
size: usize
17481750
) via SYS_OPENAT2 -> c::c_int
@@ -1910,12 +1912,12 @@ fn stat64_to_stat(s64: c::stat64) -> io::Result<Stat> {
19101912
#[cfg(linux_kernel)]
19111913
#[allow(non_upper_case_globals)]
19121914
mod sys {
1913-
use super::{c, BorrowedFd, Statx};
1915+
use super::{c, ffi, BorrowedFd, Statx};
19141916

19151917
weak_or_syscall! {
19161918
pub(super) fn statx(
19171919
dirfd_: BorrowedFd<'_>,
1918-
path: *const c::c_char,
1920+
path: *const ffi::c_char,
19191921
flags: c::c_int,
19201922
mask: c::c_uint,
19211923
buf: *mut Statx
@@ -2442,7 +2444,7 @@ pub(crate) fn fsetxattr(
24422444
}
24432445

24442446
#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
2445-
pub(crate) fn listxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize> {
2447+
pub(crate) fn listxattr(path: &CStr, list: &mut [ffi::c_char]) -> io::Result<usize> {
24462448
#[cfg(not(apple))]
24472449
unsafe {
24482450
ret_usize(c::listxattr(path.as_ptr(), list.as_mut_ptr(), list.len()))
@@ -2460,7 +2462,7 @@ pub(crate) fn listxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize
24602462
}
24612463

24622464
#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
2463-
pub(crate) fn llistxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usize> {
2465+
pub(crate) fn llistxattr(path: &CStr, list: &mut [ffi::c_char]) -> io::Result<usize> {
24642466
#[cfg(not(apple))]
24652467
unsafe {
24662468
ret_usize(c::llistxattr(path.as_ptr(), list.as_mut_ptr(), list.len()))
@@ -2478,7 +2480,7 @@ pub(crate) fn llistxattr(path: &CStr, list: &mut [c::c_char]) -> io::Result<usiz
24782480
}
24792481

24802482
#[cfg(any(apple, linux_kernel, target_os = "hurd"))]
2481-
pub(crate) fn flistxattr(fd: BorrowedFd<'_>, list: &mut [c::c_char]) -> io::Result<usize> {
2483+
pub(crate) fn flistxattr(fd: BorrowedFd<'_>, list: &mut [ffi::c_char]) -> io::Result<usize> {
24822484
let fd = borrowed_fd(fd);
24832485

24842486
#[cfg(not(apple))]

src/backend/libc/mount/types.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::backend::c;
2+
use crate::ffi;
23
use bitflags::bitflags;
34

45
#[cfg(linux_kernel)]
@@ -8,7 +9,7 @@ bitflags! {
89
/// [`mount`]: crate::mount::mount
910
#[repr(transparent)]
1011
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
11-
pub struct MountFlags: c::c_ulong {
12+
pub struct MountFlags: ffi::c_ulong {
1213
/// `MS_BIND`
1314
const BIND = c::MS_BIND;
1415

@@ -90,7 +91,7 @@ bitflags! {
9091
/// [`fsopen`]: crate::mount::fsopen
9192
#[repr(transparent)]
9293
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
93-
pub struct FsOpenFlags: c::c_uint {
94+
pub struct FsOpenFlags: ffi::c_uint {
9495
/// `FSOPEN_CLOEXEC`
9596
const FSOPEN_CLOEXEC = 0x0000_0001;
9697

@@ -107,7 +108,7 @@ bitflags! {
107108
/// [`fsmount`]: crate::mount::fsmount
108109
#[repr(transparent)]
109110
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
110-
pub struct FsMountFlags: c::c_uint {
111+
pub struct FsMountFlags: ffi::c_uint {
111112
/// `FSMOUNT_CLOEXEC`
112113
const FSMOUNT_CLOEXEC = 0x0000_0001;
113114

@@ -155,7 +156,7 @@ bitflags! {
155156
/// [`fsmount`]: crate::mount::fsmount
156157
#[repr(transparent)]
157158
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
158-
pub struct MountAttrFlags: c::c_uint {
159+
pub struct MountAttrFlags: ffi::c_uint {
159160
/// `MOUNT_ATTR_RDONLY`
160161
const MOUNT_ATTR_RDONLY = 0x0000_0001;
161162

@@ -205,7 +206,7 @@ bitflags! {
205206
/// [`move_mount`]: crate::mount::move_mount
206207
#[repr(transparent)]
207208
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
208-
pub struct MoveMountFlags: c::c_uint {
209+
pub struct MoveMountFlags: ffi::c_uint {
209210
/// `MOVE_MOUNT_F_EMPTY_PATH`
210211
const MOVE_MOUNT_F_SYMLINKS = 0x0000_0001;
211212

@@ -246,7 +247,7 @@ bitflags! {
246247
/// [`open_tree`]: crate::mount::open_tree
247248
#[repr(transparent)]
248249
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
249-
pub struct OpenTreeFlags: c::c_uint {
250+
pub struct OpenTreeFlags: ffi::c_uint {
250251
/// `OPENTREE_CLONE`
251252
const OPEN_TREE_CLONE = 1;
252253

@@ -278,7 +279,7 @@ bitflags! {
278279
/// [`fspick`]: crate::mount::fspick
279280
#[repr(transparent)]
280281
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
281-
pub struct FsPickFlags: c::c_uint {
282+
pub struct FsPickFlags: ffi::c_uint {
282283
/// `FSPICK_CLOEXEC`
283284
const FSPICK_CLOEXEC = 0x0000_0001;
284285

@@ -303,7 +304,7 @@ bitflags! {
303304
/// [`mount_change`]: crate::mount::mount_change
304305
#[repr(transparent)]
305306
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
306-
pub struct MountPropagationFlags: c::c_ulong {
307+
pub struct MountPropagationFlags: ffi::c_ulong {
307308
/// `MS_SILENT`
308309
const SILENT = c::MS_SILENT;
309310
/// `MS_SHARED`

src/backend/libc/thread/syscalls.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ pub(crate) fn clock_nanosleep_relative(id: ClockId, request: &Timespec) -> Nanos
8484
let flags = 0;
8585
let mut remain = MaybeUninit::<Timespec>::uninit();
8686

87-
match c::clock_nanosleep(id as c::clockid_t, flags, request, remain.as_mut_ptr()) {
87+
match c::clock_nanosleep(
88+
id as c::clockid_t,
89+
flags,
90+
request as *const Timespec as *const libc::timespec,
91+
remain.as_mut_ptr().cast(),
92+
) {
8893
0 => NanosleepRelativeResult::Ok,
8994
err if err == io::Errno::INTR.0 => {
9095
NanosleepRelativeResult::Interrupted(remain.assume_init())
@@ -184,7 +189,14 @@ pub(crate) fn clock_nanosleep_absolute(id: ClockId, request: &Timespec) -> io::R
184189
{
185190
let flags = c::TIMER_ABSTIME;
186191

187-
match unsafe { c::clock_nanosleep(id as c::clockid_t, flags as _, request, null_mut()) } {
192+
match unsafe {
193+
c::clock_nanosleep(
194+
id as c::clockid_t,
195+
flags as _,
196+
request as *const Timespec as *const libc::timespec,
197+
null_mut(),
198+
)
199+
} {
188200
0 => Ok(()),
189201
err => Err(io::Errno(err)),
190202
}
@@ -249,7 +261,10 @@ pub(crate) fn nanosleep(request: &Timespec) -> NanosleepRelativeResult {
249261
unsafe {
250262
let mut remain = MaybeUninit::<Timespec>::uninit();
251263

252-
match ret(c::nanosleep(request, remain.as_mut_ptr())) {
264+
match ret(c::nanosleep(
265+
request as *const Timespec as *const libc::timespec,
266+
remain.as_mut_ptr().cast(),
267+
)) {
253268
Ok(()) => NanosleepRelativeResult::Ok,
254269
Err(io::Errno::INTR) => NanosleepRelativeResult::Interrupted(remain.assume_init()),
255270
Err(err) => NanosleepRelativeResult::Err(err),

0 commit comments

Comments
 (0)