auto merge of #13315 : alexcrichton/rust/libc, r=alexcrichton,me

Rebasing of #12526 with a very obscure bug fixed on windows.
This commit is contained in:
bors 2014-04-06 02:56:39 -07:00
commit f1f50565a1
124 changed files with 612 additions and 511 deletions

View file

@ -12,7 +12,8 @@ The following is a minimal example of calling a foreign function which will
compile if snappy is installed:
~~~~ {.ignore}
use std::libc::size_t;
extern crate libc;
use libc::size_t;
#[link(name = "snappy")]
extern {
@ -44,7 +45,8 @@ keeping the binding correct at runtime.
The `extern` block can be extended to cover the entire snappy API:
~~~~ {.ignore}
use std::libc::{c_int, size_t};
extern crate libc;
use libc::{c_int, size_t};
#[link(name = "snappy")]
extern {
@ -402,7 +404,7 @@ global state. In order to access these variables, you declare them in `extern`
blocks with the `static` keyword:
~~~{.ignore}
use std::libc;
extern crate libc;
#[link(name = "readline")]
extern {
@ -420,7 +422,7 @@ interface. To do this, statics can be declared with `mut` so rust can mutate
them.
~~~{.ignore}
use std::libc;
extern crate libc;
use std::ptr;
#[link(name = "readline")]
@ -444,11 +446,15 @@ calling foreign functions. Some foreign functions, most notably the Windows API,
conventions. Rust provides a way to tell the compiler which convention to use:
~~~~
extern crate libc;
#[cfg(target_os = "win32", target_arch = "x86")]
#[link(name = "kernel32")]
extern "stdcall" {
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> std::libc::c_int;
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> libc::c_int;
}
# fn main() { }
~~~~
This applies to the entire `extern` block. The list of supported ABI constraints

View file

@ -192,7 +192,8 @@ As an example, we give a reimplementation of owned boxes by wrapping
reimplementation is as safe as the built-in `~` type.
```
use std::libc::{c_void, size_t, malloc, free};
extern crate libc;
use libc::{c_void, size_t, malloc, free};
use std::mem;
use std::ptr;

View file

@ -36,6 +36,7 @@ li {list-style-type: none; }
* [The `glob` file path matching library](glob/index.html)
* [The `green` M:N runtime library](green/index.html)
* [The `hexfloat` library for hexadecimal floating-point literals](hexfloat/index.html)
* [The `libc` bindings](libc/index.html)
* [The `native` 1:1 threading runtime](native/index.html)
* [The `num` arbitrary precision numerics library](num/index.html)
* [The `rand` library for random numbers and distributions](rand/index.html)

View file

@ -1471,11 +1471,13 @@ with the exception that they may not have a body
and are instead terminated by a semicolon.
~~~~
# use std::libc::{c_char, FILE};
extern crate libc;
use libc::{c_char, FILE};
extern {
fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
}
# fn main() {}
~~~~
Functions within external blocks may be called by Rust code,