Auto merge of #29546 - alexcrichton:new-libc, r=brson
This commit replaces the in-tree liblibc with the [external clone](https://github.com/rust-lang-nursery/libc) which has no evolved beyond the in-tree version in light of its [recent redesign](https://github.com/rust-lang/rfcs/pull/1291). The primary changes here are: * `src/liblibc/lib.rs` was deleted * `src/liblibc` is now a submodule pointing at the external repository * `src/libstd/sys/unix/{c.rs,sync.rs}` were both deleted having all bindings folded into the external liblibc. * Many ad-hoc `extern` blocks in the standard library were removed in favor of bindings now being in the external liblibc. * Many functions/types were added to `src/libstd/sys/windows/c.rs`, and the scattered definitions throughout the standard library were consolidated here. At the API level this commit is **not a breaking change**, although it is only very lightly tested on the *BSD variants and is probably going to break almost all of their builds! Follow-up commits to liblibc should in theory be all that's necessary to get the build working on the *BSDs again.
This commit is contained in:
commit
6aee7c5d2c
65 changed files with 1893 additions and 9615 deletions
|
|
@ -14,8 +14,9 @@ extern crate libc;
|
|||
|
||||
#[cfg(windows)]
|
||||
mod imp {
|
||||
use libc::{c_void, LPVOID, DWORD};
|
||||
use libc::types::os::arch::extra::LPWSTR;
|
||||
type LPVOID = *mut u8;
|
||||
type DWORD = u32;
|
||||
type LPWSTR = *mut u16;
|
||||
|
||||
extern "system" {
|
||||
fn FormatMessageW(flags: DWORD,
|
||||
|
|
@ -24,15 +25,15 @@ mod imp {
|
|||
langId: DWORD,
|
||||
buf: LPWSTR,
|
||||
nsize: DWORD,
|
||||
args: *const c_void)
|
||||
args: *const u8)
|
||||
-> DWORD;
|
||||
}
|
||||
|
||||
pub fn test() {
|
||||
let mut buf: [u16; 50] = [0; 50];
|
||||
let ret = unsafe {
|
||||
FormatMessageW(0x1000, 0 as *mut c_void, 1, 0x400,
|
||||
buf.as_mut_ptr(), buf.len() as u32, 0 as *const c_void)
|
||||
FormatMessageW(0x1000, 0 as *mut _, 1, 0x400,
|
||||
buf.as_mut_ptr(), buf.len() as u32, 0 as *const _)
|
||||
};
|
||||
// On some 32-bit Windowses (Win7-8 at least) this will panic with segmented
|
||||
// stacks taking control of pvArbitrary
|
||||
|
|
|
|||
|
|
@ -11,15 +11,19 @@
|
|||
|
||||
extern crate libc;
|
||||
|
||||
type DWORD = u32;
|
||||
type HANDLE = *mut u8;
|
||||
type BOOL = i32;
|
||||
|
||||
#[cfg(windows)]
|
||||
extern "system" {
|
||||
fn SetStdHandle(nStdHandle: libc::DWORD, nHandle: libc::HANDLE) -> libc::BOOL;
|
||||
fn SetStdHandle(nStdHandle: DWORD, nHandle: HANDLE) -> BOOL;
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn close_stdout() {
|
||||
const STD_OUTPUT_HANDLE: libc::DWORD = -11i32 as libc::DWORD;
|
||||
unsafe { SetStdHandle(STD_OUTPUT_HANDLE, 0 as libc::HANDLE); }
|
||||
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
|
||||
unsafe { SetStdHandle(STD_OUTPUT_HANDLE, 0 as HANDLE); }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
|
|
|||
|
|
@ -11,20 +11,24 @@
|
|||
|
||||
extern crate libc;
|
||||
|
||||
type DWORD = u32;
|
||||
type HANDLE = *mut u8;
|
||||
|
||||
#[cfg(windows)]
|
||||
extern "system" {
|
||||
pub fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE;
|
||||
fn GetStdHandle(which: DWORD) -> HANDLE;
|
||||
fn CloseHandle(handle: HANDLE) -> i32;
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn close_stdout() {
|
||||
const STD_OUTPUT_HANDLE: libc::DWORD = -11i32 as libc::DWORD;
|
||||
unsafe { libc::CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); }
|
||||
const STD_OUTPUT_HANDLE: DWORD = -11i32 as DWORD;
|
||||
unsafe { CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); }
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn close_stdout() {
|
||||
unsafe { libc::close(libc::STDOUT_FILENO); }
|
||||
unsafe { libc::close(1); }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ extern crate libc;
|
|||
|
||||
use std::process::Command;
|
||||
|
||||
use libc::funcs::posix88::unistd;
|
||||
|
||||
// The output from "ps -A -o pid,ppid,args" should look like this:
|
||||
// PID PPID COMMAND
|
||||
// 1 0 /sbin/init
|
||||
|
|
@ -34,7 +32,7 @@ use libc::funcs::posix88::unistd;
|
|||
|
||||
#[cfg(unix)]
|
||||
fn find_zombies() {
|
||||
let my_pid = unsafe { unistd::getpid() };
|
||||
let my_pid = unsafe { libc::getpid() };
|
||||
|
||||
// http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ps.html
|
||||
let ps_cmd_output = Command::new("ps").args(&["-A", "-o", "pid,ppid,args"]).output().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue