diff options
| author | bors <bors@rust-lang.org> | 2014-04-06 02:56:39 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-06 02:56:39 -0700 |
| commit | f1f50565a1fda0dfd60d89fea65e2328f42cc5e0 (patch) | |
| tree | c6afc2ec113c761b4a284e1370f00f29155f7025 /src/doc | |
| parent | 667f82a79b2275a696b21086ddf5148a617fe20a (diff) | |
| parent | 38f7a1b41b0ff9c1bcaec9a892c8ffb64ad6139f (diff) | |
| download | rust-f1f50565a1fda0dfd60d89fea65e2328f42cc5e0.tar.gz rust-f1f50565a1fda0dfd60d89fea65e2328f42cc5e0.zip | |
auto merge of #13315 : alexcrichton/rust/libc, r=alexcrichton,me
Rebasing of #12526 with a very obscure bug fixed on windows.
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/guide-ffi.md | 16 | ||||
| -rw-r--r-- | src/doc/guide-unsafe.md | 3 | ||||
| -rw-r--r-- | src/doc/index.md | 1 | ||||
| -rw-r--r-- | src/doc/rust.md | 4 |
4 files changed, 17 insertions, 7 deletions
diff --git a/src/doc/guide-ffi.md b/src/doc/guide-ffi.md index ee7c4064dd4..449c3ca6941 100644 --- a/src/doc/guide-ffi.md +++ b/src/doc/guide-ffi.md @@ -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 diff --git a/src/doc/guide-unsafe.md b/src/doc/guide-unsafe.md index 47b629ac4d0..c19977d0bab 100644 --- a/src/doc/guide-unsafe.md +++ b/src/doc/guide-unsafe.md @@ -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; diff --git a/src/doc/index.md b/src/doc/index.md index 5bcfd8e8305..efc1847e2c5 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -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) diff --git a/src/doc/rust.md b/src/doc/rust.md index 1e1278f08bb..afb21a19965 100644 --- a/src/doc/rust.md +++ b/src/doc/rust.md @@ -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, |
