|
1 | 1 | //! Safe wrappers around functions found in libc "unistd.h" header
|
2 | 2 |
|
3 |
| -#[cfg(not(target_os = "redox"))] |
4 |
| -use cfg_if::cfg_if; |
5 | 3 | use crate::errno::{self, Errno};
|
6 |
| -use crate::{Error, Result, NixPath}; |
7 | 4 | #[cfg(not(target_os = "redox"))]
|
8 | 5 | #[cfg(feature = "fs")]
|
9 |
| -use crate::fcntl::{AtFlags, at_rawfd}; |
10 |
| -use libc::{self, c_char, c_void, c_int, c_long, c_uint, size_t, pid_t, off_t, |
11 |
| - uid_t, gid_t, mode_t, PATH_MAX}; |
| 6 | +use crate::fcntl::{at_rawfd, AtFlags}; |
12 | 7 | #[cfg(feature = "fs")]
|
13 |
| -use crate::fcntl::{FdFlag, OFlag, fcntl, FcntlArg::F_SETFD}; |
14 |
| -use std::{fmt, mem, ptr}; |
| 8 | +use crate::fcntl::{fcntl, FcntlArg::F_SETFD, FdFlag, OFlag}; |
| 9 | +#[cfg(feature = "fs")] |
| 10 | +use crate::sys::stat::Mode; |
| 11 | +use crate::{Error, NixPath, Result}; |
| 12 | +#[cfg(not(target_os = "redox"))] |
| 13 | +use cfg_if::cfg_if; |
| 14 | +use libc::{ |
| 15 | + self, c_char, c_int, c_long, c_uint, c_void, gid_t, mode_t, off_t, pid_t, size_t, uid_t, |
| 16 | + PATH_MAX, |
| 17 | +}; |
15 | 18 | use std::convert::Infallible;
|
16 | 19 | use std::ffi::{CStr, OsString};
|
17 | 20 | #[cfg(not(target_os = "redox"))]
|
18 | 21 | use std::ffi::{CString, OsStr};
|
19 |
| -use std::os::unix::ffi::OsStringExt; |
20 | 22 | #[cfg(not(target_os = "redox"))]
|
21 | 23 | use std::os::unix::ffi::OsStrExt;
|
| 24 | +use std::os::unix::ffi::OsStringExt; |
22 | 25 | use std::os::unix::io::RawFd;
|
23 | 26 | use std::path::PathBuf;
|
24 |
| -#[cfg(feature = "fs")] |
25 |
| -use crate::sys::stat::Mode; |
| 27 | +use std::{fmt, mem, ptr}; |
26 | 28 |
|
27 | 29 | feature! {
|
28 | 30 | #![feature = "fs"]
|
29 | 31 | #[cfg(any(target_os = "android", target_os = "linux"))]
|
30 | 32 | pub use self::pivot_root::*;
|
31 | 33 | }
|
32 | 34 |
|
33 |
| -#[cfg(any(target_os = "android", |
34 |
| - target_os = "dragonfly", |
35 |
| - target_os = "freebsd", |
36 |
| - target_os = "linux", |
37 |
| - target_os = "openbsd"))] |
| 35 | +#[cfg(any( |
| 36 | + target_os = "android", |
| 37 | + target_os = "dragonfly", |
| 38 | + target_os = "freebsd", |
| 39 | + target_os = "linux", |
| 40 | + target_os = "openbsd" |
| 41 | +))] |
38 | 42 | pub use self::setres::*;
|
39 | 43 |
|
40 |
| -#[cfg(any(target_os = "android", |
41 |
| - target_os = "dragonfly", |
42 |
| - target_os = "freebsd", |
43 |
| - target_os = "linux", |
44 |
| - target_os = "openbsd"))] |
| 44 | +#[cfg(any( |
| 45 | + target_os = "android", |
| 46 | + target_os = "dragonfly", |
| 47 | + target_os = "freebsd", |
| 48 | + target_os = "linux", |
| 49 | + target_os = "openbsd" |
| 50 | +))] |
45 | 51 | pub use self::getres::*;
|
46 | 52 |
|
47 | 53 | feature! {
|
@@ -373,6 +379,7 @@ pub fn setpgid(pid: Pid, pgid: Pid) -> Result<()> {
|
373 | 379 | let res = unsafe { libc::setpgid(pid.into(), pgid.into()) };
|
374 | 380 | Errno::result(res).map(drop)
|
375 | 381 | }
|
| 382 | + |
376 | 383 | #[inline]
|
377 | 384 | pub fn getpgid(pid: Option<Pid>) -> Result<Pid> {
|
378 | 385 | let res = unsafe { libc::getpgid(pid.unwrap_or(Pid(0)).into()) };
|
@@ -672,7 +679,7 @@ fn reserve_double_buffer_size<T>(buf: &mut Vec<T>, limit: usize) -> Result<()> {
|
672 | 679 | use std::cmp::min;
|
673 | 680 |
|
674 | 681 | if buf.capacity() >= limit {
|
675 |
| - return Err(Errno::ERANGE) |
| 682 | + return Err(Errno::ERANGE); |
676 | 683 | }
|
677 | 684 |
|
678 | 685 | let capacity = min(buf.capacity() * 2, limit);
|
@@ -2776,11 +2783,13 @@ mod pivot_root {
|
2776 | 2783 | }
|
2777 | 2784 | }
|
2778 | 2785 |
|
2779 |
| -#[cfg(any(target_os = "android", |
2780 |
| - target_os = "dragonfly", |
2781 |
| - target_os = "freebsd", |
2782 |
| - target_os = "linux", |
2783 |
| - target_os = "openbsd"))] |
| 2786 | +#[cfg(any( |
| 2787 | + target_os = "android", |
| 2788 | + target_os = "dragonfly", |
| 2789 | + target_os = "freebsd", |
| 2790 | + target_os = "linux", |
| 2791 | + target_os = "openbsd" |
| 2792 | +))] |
2784 | 2793 | mod setres {
|
2785 | 2794 | feature! {
|
2786 | 2795 | #![feature = "user"]
|
@@ -2823,11 +2832,13 @@ mod setres {
|
2823 | 2832 | }
|
2824 | 2833 | }
|
2825 | 2834 |
|
2826 |
| -#[cfg(any(target_os = "android", |
2827 |
| - target_os = "dragonfly", |
2828 |
| - target_os = "freebsd", |
2829 |
| - target_os = "linux", |
2830 |
| - target_os = "openbsd"))] |
| 2835 | +#[cfg(any( |
| 2836 | + target_os = "android", |
| 2837 | + target_os = "dragonfly", |
| 2838 | + target_os = "freebsd", |
| 2839 | + target_os = "linux", |
| 2840 | + target_os = "openbsd" |
| 2841 | +))] |
2831 | 2842 | mod getres {
|
2832 | 2843 | feature! {
|
2833 | 2844 | #![feature = "user"]
|
@@ -2893,7 +2904,7 @@ mod getres {
|
2893 | 2904 | }
|
2894 | 2905 |
|
2895 | 2906 | #[cfg(feature = "fs")]
|
2896 |
| -libc_bitflags!{ |
| 2907 | +libc_bitflags! { |
2897 | 2908 | /// Options for access()
|
2898 | 2909 | #[cfg_attr(docsrs, doc(cfg(feature = "fs")))]
|
2899 | 2910 | pub struct AccessFlags : c_int {
|
|
0 commit comments