Skip to content

Commit fab2d30

Browse files
committed
Remove cfg_if from src/unix/mod.rs
- Copy 17 functions definitions from src/unix/mod.rs to src/unix/bsd/mod.rs src/unix/haiku/mod.rs src/unix/notbsd/linux/mod.rs and src/unix/solaris/mod.rs - Add some functions to android that was cfged out - Remove cf* and tc* functions implementations for android (they are available with api >= 12, which was release in 2011)
1 parent 1175c66 commit fab2d30

File tree

8 files changed

+212
-113
lines changed

8 files changed

+212
-113
lines changed

src/unix/bsd/mod.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,74 @@ extern {
359359
pub fn getpeereid(socket: ::c_int,
360360
euid: *mut ::uid_t,
361361
egid: *mut ::gid_t) -> ::c_int;
362+
363+
#[cfg_attr(target_os = "macos", link_name = "glob$INODE64")]
364+
#[cfg_attr(target_os = "netbsd", link_name = "__glob30")]
365+
pub fn glob(pattern: *const c_char,
366+
flags: ::c_int,
367+
errfunc: Option<extern fn(epath: *const c_char,
368+
errno: ::c_int) -> ::c_int>,
369+
pglob: *mut glob_t) -> ::c_int;
370+
#[cfg_attr(target_os = "netbsd", link_name = "__globfree30")]
371+
pub fn globfree(pglob: *mut glob_t);
372+
373+
pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
374+
-> ::c_int;
375+
376+
pub fn shm_unlink(name: *const c_char) -> ::c_int;
377+
378+
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
379+
link_name = "seekdir$INODE64")]
380+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
381+
link_name = "seekdir$INODE64$UNIX2003")]
382+
pub fn seekdir(dirp: *mut ::DIR, loc: c_long);
383+
384+
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
385+
link_name = "telldir$INODE64")]
386+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
387+
link_name = "telldir$INODE64$UNIX2003")]
388+
pub fn telldir(dirp: *mut ::DIR) -> c_long;
389+
pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
390+
-> ::c_int;
391+
392+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
393+
link_name = "msync$UNIX2003")]
394+
#[cfg_attr(target_os = "netbsd", link_name = "__msync13")]
395+
pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
396+
397+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
398+
link_name = "recvfrom$UNIX2003")]
399+
pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
400+
flags: ::c_int, addr: *mut sockaddr,
401+
addrlen: *mut socklen_t) -> ::ssize_t;
402+
pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
403+
pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
404+
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;
405+
406+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
407+
link_name = "bind$UNIX2003")]
408+
pub fn bind(socket: ::c_int, address: *const sockaddr,
409+
address_len: socklen_t) -> ::c_int;
410+
411+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
412+
link_name = "writev$UNIX2003")]
413+
pub fn writev(fd: ::c_int,
414+
iov: *const ::iovec,
415+
iovcnt: ::c_int) -> ::ssize_t;
416+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
417+
link_name = "readv$UNIX2003")]
418+
pub fn readv(fd: ::c_int,
419+
iov: *const ::iovec,
420+
iovcnt: ::c_int) -> ::ssize_t;
421+
422+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
423+
link_name = "sendmsg$UNIX2003")]
424+
pub fn sendmsg(fd: ::c_int,
425+
msg: *const msghdr,
426+
flags: ::c_int) -> ::ssize_t;
427+
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
428+
link_name = "recvmsg$UNIX2003")]
429+
pub fn recvmsg(fd: ::c_int, msg: *mut msghdr, flags: ::c_int) -> ::ssize_t;
362430
}
363431

364432
cfg_if! {

src/unix/haiku/mod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,48 @@ extern {
760760
abstime: *const ::timespec) -> ::c_int;
761761
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
762762
options: ::c_int) -> ::c_int;
763+
764+
pub fn glob(pattern: *const c_char,
765+
flags: ::c_int,
766+
errfunc: Option<extern fn(epath: *const c_char,
767+
errno: ::c_int) -> ::c_int>,
768+
pglob: *mut glob_t) -> ::c_int;
769+
pub fn globfree(pglob: *mut glob_t);
770+
771+
pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
772+
-> ::c_int;
773+
774+
pub fn shm_unlink(name: *const c_char) -> ::c_int;
775+
776+
pub fn seekdir(dirp: *mut ::DIR, loc: c_long);
777+
778+
pub fn telldir(dirp: *mut ::DIR) -> c_long;
779+
pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
780+
-> ::c_int;
781+
782+
pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
783+
784+
pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
785+
flags: ::c_int, addr: *mut sockaddr,
786+
addrlen: *mut socklen_t) -> ::ssize_t;
787+
pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
788+
pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
789+
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;
790+
791+
pub fn bind(socket: ::c_int, address: *const sockaddr,
792+
address_len: socklen_t) -> ::c_int;
793+
794+
pub fn writev(fd: ::c_int,
795+
iov: *const ::iovec,
796+
iovcnt: ::c_int) -> ::ssize_t;
797+
pub fn readv(fd: ::c_int,
798+
iov: *const ::iovec,
799+
iovcnt: ::c_int) -> ::ssize_t;
800+
801+
pub fn sendmsg(fd: ::c_int,
802+
msg: *const msghdr,
803+
flags: ::c_int) -> ::ssize_t;
804+
pub fn recvmsg(fd: ::c_int, msg: *mut msghdr, flags: ::c_int) -> ::ssize_t;
763805
}
764806

765807
cfg_if! {

src/unix/mod.rs

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -747,83 +747,11 @@ extern {
747747

748748
#[cfg_attr(target_os = "netbsd", link_name = "__timegm50")]
749749
pub fn timegm(tm: *mut ::tm) -> time_t;
750-
}
751-
752-
// Android has some weirdness in this definition
753-
// See weirdness in src/unix/notbsd/android/mod.rs
754-
#[cfg(any(not(target_os = "android"), // " if " -- appease style checker
755-
not(target_arch = "aarch64")))]
756-
extern {
757-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
758-
link_name = "bind$UNIX2003")]
759-
pub fn bind(socket: ::c_int, address: *const sockaddr,
760-
address_len: socklen_t) -> ::c_int;
761-
762-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
763-
link_name = "writev$UNIX2003")]
764-
pub fn writev(fd: ::c_int,
765-
iov: *const ::iovec,
766-
iovcnt: ::c_int) -> ::ssize_t;
767-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
768-
link_name = "readv$UNIX2003")]
769-
pub fn readv(fd: ::c_int,
770-
iov: *const ::iovec,
771-
iovcnt: ::c_int) -> ::ssize_t;
772-
773-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
774-
link_name = "sendmsg$UNIX2003")]
775-
pub fn sendmsg(fd: ::c_int,
776-
msg: *const msghdr,
777-
flags: ::c_int) -> ::ssize_t;
778-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
779-
link_name = "recvmsg$UNIX2003")]
780-
pub fn recvmsg(fd: ::c_int, msg: *mut msghdr, flags: ::c_int) -> ::ssize_t;
781-
}
782-
783-
// TODO: get rid of this cfg(not(...))
784-
#[cfg(not(target_os = "android"))] // " if " -- appease style checker
785-
extern {
786-
#[cfg_attr(target_os = "macos", link_name = "glob$INODE64")]
787-
#[cfg_attr(target_os = "netbsd", link_name = "__glob30")]
788-
pub fn glob(pattern: *const c_char,
789-
flags: ::c_int,
790-
errfunc: Option<extern fn(epath: *const c_char,
791-
errno: ::c_int) -> ::c_int>,
792-
pglob: *mut glob_t) -> ::c_int;
793-
#[cfg_attr(target_os = "netbsd", link_name = "__globfree30")]
794-
pub fn globfree(pglob: *mut glob_t);
795-
796-
pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
797-
-> ::c_int;
798-
799-
pub fn shm_unlink(name: *const c_char) -> ::c_int;
800-
801-
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
802-
link_name = "seekdir$INODE64")]
803-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
804-
link_name = "seekdir$INODE64$UNIX2003")]
805-
pub fn seekdir(dirp: *mut ::DIR, loc: c_long);
806-
807-
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
808-
link_name = "telldir$INODE64")]
809-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
810-
link_name = "telldir$INODE64$UNIX2003")]
811-
pub fn telldir(dirp: *mut ::DIR) -> c_long;
812750

813751
pub fn getsid(pid: pid_t) -> pid_t;
814-
pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
815-
-> ::c_int;
816752

817-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
818-
link_name = "msync$UNIX2003")]
819-
#[cfg_attr(target_os = "netbsd", link_name = "__msync13")]
820-
pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
821-
pub fn sysconf(name: ::c_int) -> c_long;
822-
#[cfg_attr(all(target_os = "macos", target_arch = "x86"),
823-
link_name = "recvfrom$UNIX2003")]
824-
pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
825-
flags: ::c_int, addr: *mut sockaddr,
826-
addrlen: *mut socklen_t) -> ::ssize_t;
753+
pub fn sysconf(name: ::c_int) -> ::c_long;
754+
827755
pub fn mkfifo(path: *const c_char, mode: mode_t) -> ::c_int;
828756

829757
#[cfg_attr(all(target_os = "macos", target_arch = "x86_64"),
@@ -856,10 +784,7 @@ extern {
856784
pub fn tcflush(fd: ::c_int, action: ::c_int) -> ::c_int;
857785
pub fn tcsendbreak(fd: ::c_int, duration: ::c_int) -> ::c_int;
858786
pub fn mkstemp(template: *mut ::c_char) -> ::c_int;
859-
pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
860787
pub fn mkdtemp(template: *mut ::c_char) -> *mut ::c_char;
861-
pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
862-
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;
863788

864789
pub fn openlog(ident: *const ::c_char, logopt: ::c_int, facility: ::c_int);
865790
pub fn closelog();

src/unix/notbsd/android/b32/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,21 @@ pub const UT_NAMESIZE: usize = 8;
164164
pub const UT_HOSTSIZE: usize = 16;
165165

166166
extern {
167+
pub fn bind(socket: ::c_int, address: *const ::sockaddr,
168+
address_len: socklen_t) -> ::c_int;
169+
170+
pub fn writev(fd: ::c_int,
171+
iov: *const ::iovec,
172+
iovcnt: ::c_int) -> ::ssize_t;
173+
pub fn readv(fd: ::c_int,
174+
iov: *const ::iovec,
175+
iovcnt: ::c_int) -> ::ssize_t;
176+
177+
pub fn sendmsg(fd: ::c_int,
178+
msg: *const ::msghdr,
179+
flags: ::c_int) -> ::ssize_t;
180+
pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::ssize_t;
181+
167182
pub fn timegm64(tm: *const ::tm) -> ::time64_t;
168183
}
169184

src/unix/notbsd/android/b64/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,3 @@ extern {
200200
// the return type should be ::ssize_t, but it is c_int!
201201
pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::c_int;
202202
}
203-

src/unix/notbsd/android/mod.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -678,40 +678,6 @@ pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER);
678678
pub const SIGEV_THREAD_ID: ::c_int = 4;
679679

680680
f! {
681-
pub fn cfgetispeed(termios: *const ::termios) -> ::speed_t {
682-
(*termios).c_cflag & ::CBAUD
683-
}
684-
pub fn cfgetospeed(termios: *const ::termios) -> ::speed_t {
685-
(*termios).c_cflag & ::CBAUD
686-
}
687-
pub fn cfsetispeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int {
688-
let cbaud = ::CBAUD;
689-
(*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud);
690-
return 0
691-
}
692-
pub fn cfsetospeed(termios: *mut ::termios, speed: ::speed_t) -> ::c_int {
693-
let cbaud = ::CBAUD;
694-
(*termios).c_cflag = ((*termios).c_cflag & !cbaud) | (speed & cbaud);
695-
return 0
696-
}
697-
pub fn tcgetattr(fd: ::c_int, termios: *mut ::termios) -> ::c_int {
698-
ioctl(fd, ::TCGETS, termios)
699-
}
700-
pub fn tcsetattr(fd: ::c_int,
701-
optional_actions: ::c_int,
702-
termios: *const ::termios) -> ::c_int {
703-
ioctl(fd, optional_actions, termios)
704-
}
705-
pub fn tcflow(fd: ::c_int, action: ::c_int) -> ::c_int {
706-
ioctl(fd, ::TCXONC, action as *mut ::c_void)
707-
}
708-
pub fn tcflush(fd: ::c_int, action: ::c_int) -> ::c_int {
709-
ioctl(fd, ::TCFLSH, action as *mut ::c_void)
710-
}
711-
pub fn tcsendbreak(fd: ::c_int, duration: ::c_int) -> ::c_int {
712-
ioctl(fd, TCSBRKP, duration as *mut ::c_void)
713-
}
714-
715681
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
716682
for slot in cpuset.__bits.iter_mut() {
717683
*slot = 0;
@@ -755,7 +721,6 @@ extern {
755721
flags: ::c_int) -> ::c_int;
756722
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int)
757723
-> ::c_int;
758-
pub fn sysconf(name: ::c_int) -> ::c_long;
759724
pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
760725
flags: ::c_int, addr: *const ::sockaddr,
761726
addrlen: *mut ::socklen_t) -> ::ssize_t;

src/unix/notbsd/linux/mod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,48 @@ extern {
900900
new_len: ::size_t,
901901
flags: ::c_int,
902902
...) -> *mut ::c_void;
903+
904+
pub fn glob(pattern: *const c_char,
905+
flags: ::c_int,
906+
errfunc: Option<extern fn(epath: *const c_char,
907+
errno: ::c_int) -> ::c_int>,
908+
pglob: *mut glob_t) -> ::c_int;
909+
pub fn globfree(pglob: *mut glob_t);
910+
911+
pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
912+
-> ::c_int;
913+
914+
pub fn shm_unlink(name: *const c_char) -> ::c_int;
915+
916+
pub fn seekdir(dirp: *mut ::DIR, loc: c_long);
917+
918+
pub fn telldir(dirp: *mut ::DIR) -> c_long;
919+
pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
920+
-> ::c_int;
921+
922+
pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
923+
924+
pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
925+
flags: ::c_int, addr: *mut sockaddr,
926+
addrlen: *mut socklen_t) -> ::ssize_t;
927+
pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
928+
pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
929+
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;
930+
931+
pub fn bind(socket: ::c_int, address: *const sockaddr,
932+
address_len: socklen_t) -> ::c_int;
933+
934+
pub fn writev(fd: ::c_int,
935+
iov: *const ::iovec,
936+
iovcnt: ::c_int) -> ::ssize_t;
937+
pub fn readv(fd: ::c_int,
938+
iov: *const ::iovec,
939+
iovcnt: ::c_int) -> ::ssize_t;
940+
941+
pub fn sendmsg(fd: ::c_int,
942+
msg: *const msghdr,
943+
flags: ::c_int) -> ::ssize_t;
944+
pub fn recvmsg(fd: ::c_int, msg: *mut msghdr, flags: ::c_int) -> ::ssize_t;
903945
}
904946

905947
cfg_if! {

src/unix/solaris/mod.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,4 +1094,47 @@ extern {
10941094
abstime: *const ::timespec) -> ::c_int;
10951095
pub fn waitid(idtype: idtype_t, id: id_t, infop: *mut ::siginfo_t,
10961096
options: ::c_int) -> ::c_int;
1097+
1098+
pub fn glob(pattern: *const c_char,
1099+
flags: ::c_int,
1100+
errfunc: Option<extern fn(epath: *const c_char,
1101+
errno: ::c_int) -> ::c_int>,
1102+
pglob: *mut glob_t) -> ::c_int;
1103+
1104+
pub fn globfree(pglob: *mut glob_t);
1105+
1106+
pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
1107+
-> ::c_int;
1108+
1109+
pub fn shm_unlink(name: *const c_char) -> ::c_int;
1110+
1111+
pub fn seekdir(dirp: *mut ::DIR, loc: c_long);
1112+
1113+
pub fn telldir(dirp: *mut ::DIR) -> c_long;
1114+
pub fn madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int)
1115+
-> ::c_int;
1116+
1117+
pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
1118+
1119+
pub fn recvfrom(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
1120+
flags: ::c_int, addr: *mut sockaddr,
1121+
addrlen: *mut socklen_t) -> ::ssize_t;
1122+
pub fn mkstemps(template: *mut ::c_char, suffixlen: ::c_int) -> ::c_int;
1123+
pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
1124+
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;
1125+
1126+
pub fn bind(socket: ::c_int, address: *const sockaddr,
1127+
address_len: socklen_t) -> ::c_int;
1128+
1129+
pub fn writev(fd: ::c_int,
1130+
iov: *const ::iovec,
1131+
iovcnt: ::c_int) -> ::ssize_t;
1132+
pub fn readv(fd: ::c_int,
1133+
iov: *const ::iovec,
1134+
iovcnt: ::c_int) -> ::ssize_t;
1135+
1136+
pub fn sendmsg(fd: ::c_int,
1137+
msg: *const msghdr,
1138+
flags: ::c_int) -> ::ssize_t;
1139+
pub fn recvmsg(fd: ::c_int, msg: *mut msghdr, flags: ::c_int) -> ::ssize_t;
10971140
}

0 commit comments

Comments
 (0)