Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refactoring the Linux module: first try. #373

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ pub const DT_REG: u8 = 8;
pub const DT_LNK: u8 = 10;
pub const DT_SOCK: u8 = 12;

pub const FD_CLOEXEC: ::c_int = 0x1;

pub const USRQUOTA: ::c_int = 0;
pub const GRPQUOTA: ::c_int = 1;

Expand Down Expand Up @@ -198,6 +196,9 @@ pub const PRIO_USER: ::c_int = 2;
pub const PRIO_MIN: ::c_int = -20;
pub const PRIO_MAX: ::c_int = 20;

/* Header <fcntl.h> */
pub const FD_CLOEXEC: ::c_int = 0x1;

cfg_if! {
if #[cfg(dox)] {
// on dox builds don't pull in anything
Expand Down Expand Up @@ -318,16 +319,6 @@ extern {
pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE;
pub fn fileno(stream: *mut ::FILE) -> ::c_int;

#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "open$UNIX2003")]
pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "creat$UNIX2003")]
pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "fcntl$UNIX2003")]
pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int;

#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
link_name = "opendir$INODE64")]
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
Expand Down Expand Up @@ -715,6 +706,17 @@ extern {
pshared: ::c_int,
value: ::c_uint)
-> ::c_int;

/* Header <fcntl.h> */
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "creat$UNIX2003")]
pub fn creat(path: *const c_char, mode: mode_t) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "fcntl$UNIX2003")]
pub fn fcntl(fd: ::c_int, cmd: ::c_int, ...) -> ::c_int;
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
link_name = "open$UNIX2003")]
pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int;
}

// TODO: get rid of this cfg(not(...))
Expand Down
5 changes: 5 additions & 0 deletions src/unix/notbsd/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@ pub const ICANON: ::tcflag_t = 0x00000002;
pub const PENDIN: ::tcflag_t = 0x00004000;
pub const NOFLSH: ::tcflag_t = 0x00000080;

pub const LOCK_SH: ::c_int = 0x1;
pub const LOCK_EX: ::c_int = 0x2;
pub const LOCK_NB: ::c_int = 0x4;
pub const LOCK_UN: ::c_int = 0x8;

f! {
pub fn sigemptyset(set: *mut sigset_t) -> ::c_int {
*set = 0;
Expand Down
60 changes: 60 additions & 0 deletions src/unix/notbsd/linux/common/b32/arm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Native C types
pub type c_char = u8;

/* Header <fcntl.h> */
cfg_if! {
if #[cfg(any(feature = "file_offset64", target_env = "musl"))] {
type flock = ::flock64;
} else {
s! {
pub struct flock {
pub l_type: ::c_short,
pub l_whence: ::c_short,
pub l_start: ::off_t,
pub l_len: ::off_t,
pub l_pid: ::pid_t,
}
}
}
}

/* Header <fcntl.h> */
cfg_if! {
if #[cfg(not(any(feature = "file_offset64", target_env = "musl")))] {
pub const F_GETLK: ::c_int = 5;
pub const F_SETLK: ::c_int = 6;
pub const F_SETLKW: ::c_int = 7;
} else {

}
}
pub const F_GETOWN: ::c_int = 9;
pub const F_SETOWN: ::c_int = 8;

pub const F_GETLK64: ::c_int = 12;
pub const F_SETLK64: ::c_int = 13;
pub const F_SETLKW64: ::c_int = 14;

// O_CLOEXEC is defined in notbsd/mod.rs
pub const O_CREAT: ::c_int = 0x40;
pub const O_DIRECTORY: ::c_int = 0x4000;
pub const O_EXCL: ::c_int = 0x80;
pub const O_NOCTTY: ::c_int = 0x100;
pub const O_NOFOLLOW: ::c_int = 0x8000;
// O_TRUNC is defined in notbsd/mod.rs

pub const O_APPEND: ::c_int = 0x400;
pub const O_DSYNC: ::c_int = 0x1000;
pub const O_NONBLOCK: ::c_int = 0x800;
pub const O_RSYNC: ::c_int = 0x101000;
pub const O_SYNC: ::c_int = 0x101000;

// Here start non POSIX definitions.
pub const O_ASYNC: ::c_int = 0x2000;
pub const O_DIRECT: ::c_int = 0x10000;
pub const O_LARGEFILE: ::c_int = 0x20000;
pub const O_NOATIME: ::c_int = 0x40000;
pub const O_PATH: ::c_int = 0x200000;
pub const O_TMPFILE: ::c_int = 0x404000;
pub const O_NDELAY: ::c_int = ::O_NONBLOCK;

61 changes: 61 additions & 0 deletions src/unix/notbsd/linux/common/b32/mips.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Native C types
pub type c_char = i8;

/* Header <fcntl.h> */
cfg_if! {
if #[cfg(any(feature = "file_offset64", target_env = "musl"))] {
type flock = ::flock64;
} else {
s! {
pub struct flock {
pub l_type: ::c_short,
pub l_whence: ::c_short,
pub l_start: ::off_t,
pub l_len: ::off_t,
pub l_sysid: ::c_long,
pub l_pid: ::pid_t,
pad: [::c_long; 4],
}
}
}
}

/* Header <fcntl.h> */
cfg_if! {
if #[cfg(not(any(feature = "file_offset64", target_env = "musl")))] {
pub const F_GETLK: ::c_int = 14;
pub const F_SETLK: ::c_int = 6;
pub const F_SETLKW: ::c_int = 7;
} else {

}
}
pub const F_GETOWN: ::c_int = 23;
pub const F_SETOWN: ::c_int = 24;

pub const F_GETLK64: ::c_int = 33;
pub const F_SETLK64: ::c_int = 34;
pub const F_SETLKW64: ::c_int = 35;

// O_CLOEXEC is defined in notbsd/mod.rs
pub const O_CREAT: ::c_int = 0x100;
pub const O_DIRECTORY: ::c_int = 0x10000;
pub const O_EXCL: ::c_int = 0x400;
pub const O_NOCTTY: ::c_int = 0x800;
pub const O_NOFOLLOW: ::c_int = 0x20000;
// O_TRUNC is defined in notbsd/mod.rs

pub const O_APPEND: ::c_int = 0x8;
pub const O_DSYNC: ::c_int = 0x10;
pub const O_NONBLOCK: ::c_int = 0x80;
pub const O_RSYNC: ::c_int = 0x4010;
pub const O_SYNC: ::c_int = 0x4010;

pub const O_ASYNC: ::c_int = 0x1000;
pub const O_DIRECT: ::c_int = 0x8000;
pub const O_LARGEFILE: ::c_int = 0x2000;
pub const O_NOATIME: ::c_int = 0x40000;
pub const O_PATH: ::c_int = 0x200000;
pub const O_TMPFILE: ::c_int = 0x410000;
pub const O_NDELAY: ::c_int = ::O_NONBLOCK;

33 changes: 33 additions & 0 deletions src/unix/notbsd/linux/common/b32/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Native C types
pub type c_long = i32;
pub type c_ulong = u32;

/* Header <fcntl.h> */
cfg_if! {
if #[cfg(any(feature = "file_offset64", target_env = "musl"))] {
pub const F_GETLK: ::c_int = ::F_GETLK64;
pub const F_SETLK: ::c_int = ::F_SETLK64;
pub const F_SETLKW: ::c_int = ::F_SETLKW64;
} else {

}
}

cfg_if! {
if #[cfg(target_arch = "x86")] {
mod x86;
pub use self::x86::*;
} else if #[cfg(target_arch = "arm")] {
mod arm;
pub use self::arm::*;
} else if #[cfg(target_arch = "mips")] {
mod mips;
pub use self::mips::*;
} else if #[cfg(target_arch = "powerpc")] {
mod powerpc;
pub use self::powerpc::*;
} else {
// Unknown target_arch
}
}

60 changes: 60 additions & 0 deletions src/unix/notbsd/linux/common/b32/powerpc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Native C types
pub type c_char = u8;

/* Header <fcntl.h> */
cfg_if! {
if #[cfg(any(feature = "file_offset64", target_env = "musl"))] {
type flock = ::flock64;
} else {
s! {
pub struct flock {
pub l_type: ::c_short,
pub l_whence: ::c_short,
pub l_start: ::off_t,
pub l_len: ::off_t,
pub l_pid: ::pid_t,
}
}
}
}

/* Header <fcntl.h> */
cfg_if! {
if #[cfg(not(any(feature = "file_offset64", target_env = "musl")))] {
pub const F_GETLK: ::c_int = 5;
pub const F_SETLK: ::c_int = 6;
pub const F_SETLKW: ::c_int = 7;
} else {

}
}
pub const F_GETOWN: ::c_int = 9;
pub const F_SETOWN: ::c_int = 8;

pub const F_GETLK64: ::c_int = 12;
pub const F_SETLK64: ::c_int = 13;
pub const F_SETLKW64: ::c_int = 14;

// O_CLOEXEC is defined in notbsd/mod.rs
pub const O_CREAT: ::c_int = 0x40;
pub const O_DIRECTORY: ::c_int = 0x4000;
pub const O_EXCL: ::c_int = 0x80;
pub const O_NOCTTY: ::c_int = 0x100;
pub const O_NOFOLLOW: ::c_int = 0x8000;
// O_TRUNC is defined in notbsd/mod.rs

pub const O_APPEND: ::c_int = 0x400;
pub const O_DSYNC: ::c_int = 0x1000;
pub const O_NONBLOCK: ::c_int = 0x800;
pub const O_RSYNC: ::c_int = 0x101000;
pub const O_SYNC: ::c_int = 0x101000;

// Here start non POSIX definitions.
pub const O_ASYNC: ::c_int = 0x2000;
pub const O_DIRECT: ::c_int = 0x20000;
pub const O_LARGEFILE: ::c_int = 0x10000;
pub const O_NOATIME: ::c_int = 0x40000;
pub const O_PATH: ::c_int = 0x200000;
pub const O_TMPFILE: ::c_int = 0x404000;
pub const O_NDELAY: ::c_int = ::O_NONBLOCK;

60 changes: 60 additions & 0 deletions src/unix/notbsd/linux/common/b32/x86.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Native C types
pub type c_char = i8;

/* Header <fcntl.h> */
cfg_if! {
if #[cfg(any(feature = "file_offset64", target_env = "musl"))] {
type flock = ::flock64;
} else {
s! {
pub struct flock {
pub l_type: ::c_short,
pub l_whence: ::c_short,
pub l_start: ::off_t,
pub l_len: ::off_t,
pub l_pid: ::pid_t,
}
}
}
}

/* Header <fcntl.h> */
cfg_if! {
if #[cfg(not(any(feature = "file_offset64", target_env = "musl")))] {
pub const F_GETLK: ::c_int = 5;
pub const F_SETLK: ::c_int = 6;
pub const F_SETLKW: ::c_int = 7;
} else {

}
}
pub const F_GETOWN: ::c_int = 9;
pub const F_SETOWN: ::c_int = 8;

pub const F_GETLK64: ::c_int = 12;
pub const F_SETLK64: ::c_int = 13;
pub const F_SETLKW64: ::c_int = 14;

// O_CLOEXEC is defined in notbsd/mod.rs
pub const O_CREAT: ::c_int = 0x40;
pub const O_DIRECTORY: ::c_int = 0x10000;
pub const O_EXCL: ::c_int = 0x80;
pub const O_NOCTTY: ::c_int = 0x100;
pub const O_NOFOLLOW: ::c_int = 0x20000;
// O_TRUNC is defined in notbsd/mod.rs

pub const O_APPEND: ::c_int = 0x400;
pub const O_DSYNC: ::c_int = 0x1000;
pub const O_NONBLOCK: ::c_int = 0x800;
pub const O_RSYNC: ::c_int = 0x101000;
pub const O_SYNC: ::c_int = 0x101000;

// Here start non POSIX definitions.
pub const O_ASYNC: ::c_int = 0x2000;
pub const O_DIRECT: ::c_int = 0x4000;
pub const O_LARGEFILE: ::c_int = 0x8000;
pub const O_NOATIME: ::c_int = 0x40000;
pub const O_PATH: ::c_int = 0x200000;
pub const O_TMPFILE: ::c_int = 0x410000;
pub const O_NDELAY: ::c_int = ::O_NONBLOCK;

33 changes: 33 additions & 0 deletions src/unix/notbsd/linux/common/b64/aarch64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Native C types
pub type c_char = u8;

/* Header <fcntl.h> */
pub const F_GETLK: ::c_int = 5;
pub const F_SETLK: ::c_int = 6;
pub const F_SETLKW: ::c_int = 7;
pub const F_GETOWN: ::c_int = 9;
pub const F_SETOWN: ::c_int = 8;

// O_CLOEXEC is defined in notbsd/mod.rs
pub const O_CREAT: ::c_int = 0x40;
pub const O_DIRECTORY: ::c_int = 0x4000;
pub const O_EXCL: ::c_int = 0x80;
pub const O_NOCTTY: ::c_int = 0x100;
pub const O_NOFOLLOW: ::c_int = 0x8000;
// O_TRUNC is defined in notbsd/mod.rs

pub const O_APPEND: ::c_int = 0x400;
pub const O_DSYNC: ::c_int = 0x1000;
pub const O_NONBLOCK: ::c_int = 0x800;
pub const O_RSYNC: ::c_int = 0x101000;
pub const O_SYNC: ::c_int = 0x101000;

// Here start non POSIX definitions.
pub const O_ASYNC: ::c_int = 0x2000;
pub const O_DIRECT: ::c_int = 0x10000;
pub const O_LARGEFILE: ::c_int = 0;
pub const O_NOATIME: ::c_int = 0x40000;
pub const O_PATH: ::c_int = 0x200000;
pub const O_TMPFILE: ::c_int = 0x404000;
pub const O_NDELAY: ::c_int = ::O_NONBLOCK;

Loading