blob: 4d82511277e4aced1af898108893f3b9afe9a5b0 [file] [log] [blame] [view]
Alex Crichton68fe98b2015-01-13 07:53:42 -08001libc
2====
3
4A Rust library with native bindings to the types and functions commonly found on
5various systems, including libc.
6
Alex Crichton13418a52015-10-29 11:54:12 -07007[![Build Status](https://travis-ci.org/rust-lang/libc.svg?branch=master)](https://travis-ci.org/rust-lang/libc)
8[![Build status](https://ci.appveyor.com/api/projects/status/v0414slj8y8nga0p?svg=true)](https://ci.appveyor.com/project/rust-lang/libc)
Alex Crichton68fe98b2015-01-13 07:53:42 -08009
Alex Crichton13418a52015-10-29 11:54:12 -070010[Documentation][#Platforms-and-Documentation]
Alex Crichton78f5aca2015-09-18 15:01:16 -070011
Alex Crichton13418a52015-10-29 11:54:12 -070012## Usage
13
14First, add the following to your `Cargo.toml`:
15
16```toml
17[dependencies]
18libc = "1.0"
19```
20
21Next, add this to your crate root:
22
23```rust
24extern crate libc;
25```
26
27## What is libc?
28
29The primary purpose of this crate is to provide all of the definitions necessary
30to easily interoperate with C code (or "C-like" code) on each of the platforms
31that Rust supports. This includes type definitions (e.g. `c_int`), constants
32(e.g. `EINVAL`) as well as function headers (e.g. `malloc`).
33
34This crate does not strive to have any form of compatibility across platforms,
35but rather it is simply a straight binding to the system libraries on the
36platform in question.
37
38## Public API
39
40This crate exports all underlying platform types, functions, and constants under
41the crate root, so all items are accessible as `libc::foo`. The types and values
42of all the exported APIs match the platform that libc is compiled for.
43
44## Adding an API
45
46Want to use an API which currently isn't bound in `libc`? It's quite easy to add
47one!
48
49The internal structure of this crate is designed to minimize the number of
50`#[cfg]` attributes in order to easily be able to add new items which apply
51to all platforms in the future. As a result, the crate is organized
52hierarchically based on platform. Each module has a number of `#[cfg]`'d
53children, but only one is ever actually compiled. Each module then reexports all
54the contents of its children.
55
56This means that for each platform that libc supports, the path from a
57leaf module to the root will contain all bindings for the platform in question.
58Consequently, this indicates where an API should be added! Adding an API at a
59particular level in the hierarchy means that it is supported on all the child
60platforms of that level. For example, when adding a Unix API it should be added
61to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to
62`src/unix/notbsd/linux/mod.rs`.
63
64If you're not 100% sure at what level of the hierarchy an API should be added
65at, fear not! This crate has CI support which tests any binding against all
66platforms supported, so you'll see failures if an API is added at the wrong
67level or has different signatures across platforms.
68
69## Platforms and Documentation
70
71The following platforms are currently tested and have documentation available:
Alex Crichton78f5aca2015-09-18 15:01:16 -070072
73Tested:
Alex Crichton13418a52015-10-29 11:54:12 -070074 * [`i686-pc-windows-msvc`](https://doc.rust-lang.org/libc/i686-pc-windows-msvc/libc)
75 * [`x86_64-pc-windows-msvc`](https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc/libc)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -070076 (Windows)
Alex Crichton13418a52015-10-29 11:54:12 -070077 * [`i686-pc-windows-gnu`](https://doc.rust-lang.org/libc/i686-pc-windows-gnu/libc)
78 * [`x86_64-pc-windows-gnu`](https://doc.rust-lang.org/libc/x86_64-pc-windows-gnu/libc)
79 * [`i686-apple-darwin`](https://doc.rust-lang.org/libc/i686-apple-darwin/libc)
80 * [`x86_64-apple-darwin`](https://doc.rust-lang.org/libc/x86_64-apple-darwin/libc)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -070081 (OSX)
Alex Crichton13418a52015-10-29 11:54:12 -070082 * [`i686-apple-ios`](https://doc.rust-lang.org/libc/i686-apple-ios/libc)
83 * [`x86_64-apple-ios`](https://doc.rust-lang.org/libc/x86_64-apple-ios/libc)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -070084 (iOS)
Alex Crichton13418a52015-10-29 11:54:12 -070085 * [`i686-unknown-linux-gnu`](https://doc.rust-lang.org/libc/i686-unknown-linux-gnu/libc)
86 * [`x86_64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -070087 (Linux)
Alex Crichton13418a52015-10-29 11:54:12 -070088 * [`x86_64-unknown-linux-musl`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl/libc)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -070089 (Linux MUSL)
Alex Crichton13418a52015-10-29 11:54:12 -070090 * [`aarch64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/aarch64-unknown-linux-gnu/libc)
91 * [`mips-unknown-linux-gnu`](https://doc.rust-lang.org/libc/mips-unknown-linux-gnu/libc)
92 * [`arm-unknown-linux-gnueabihf`](https://doc.rust-lang.org/libc/arm-unknown-linux-gnueabihf/libc)
93 * [`arm-linux-androideabi`](https://doc.rust-lang.org/libc/arm-linux-androideabi/libc)
Alex Crichtonb1fbefa2015-10-29 11:56:13 -070094 (Android)
Alex Crichton78f5aca2015-09-18 15:01:16 -070095
Alex Crichton13418a52015-10-29 11:54:12 -070096The following may be supported, but are not guaranteed to always work:
97
98 * `x86_64-unknown-freebsd`
99 * `i686-unknown-freebsd`
100 * `x86_64-unknown-bitrig`
101 * `x86_64-unknown-dragonfly`
102 * `x86_64-unknown-openbsd`
103 * `x86_64-unknown-netbsd`