std: Migrate to the new libc
* Delete `sys::unix::{c, sync}` as these are now all folded into libc itself
* Update all references to use `libc` as a result.
* Update all references to the new flat namespace.
* Moves all windows bindings into sys::c
This commit is contained in:
parent
c8a29c2092
commit
3d28b8b98e
62 changed files with 1889 additions and 2431 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