| Alex Crichton | 68fe98b | 2015-01-13 07:53:42 -0800 | [diff] [blame] | 1 | libc |
| 2 | ==== |
| 3 | |
| 4 | A Rust library with native bindings to the types and functions commonly found on |
| 5 | various systems, including libc. |
| 6 | |
| Alex Crichton | be5ad7d | 2015-10-29 17:50:50 -0700 | [diff] [blame] | 7 | [](https://travis-ci.org/rust-lang-nursery/libc) |
| Alex Crichton | 1f7e2e8 | 2015-10-29 12:02:05 -0700 | [diff] [blame] | 8 | [](https://ci.appveyor.com/project/alexcrichton/libc) |
| Alex Crichton | 68fe98b | 2015-01-13 07:53:42 -0800 | [diff] [blame] | 9 | |
| Alex Crichton | 5289b31 | 2015-10-29 11:57:58 -0700 | [diff] [blame] | 10 | [Documentation](#platforms-and-documentation) |
| Alex Crichton | 78f5aca | 2015-09-18 15:01:16 -0700 | [diff] [blame] | 11 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 12 | ## Usage |
| 13 | |
| 14 | First, add the following to your `Cargo.toml`: |
| 15 | |
| 16 | ```toml |
| 17 | [dependencies] |
| Alex Crichton | cf18a60 | 2015-10-29 22:12:21 -0700 | [diff] [blame^] | 18 | libc = "0.1" |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 19 | ``` |
| 20 | |
| 21 | Next, add this to your crate root: |
| 22 | |
| 23 | ```rust |
| 24 | extern crate libc; |
| 25 | ``` |
| 26 | |
| 27 | ## What is libc? |
| 28 | |
| 29 | The primary purpose of this crate is to provide all of the definitions necessary |
| 30 | to easily interoperate with C code (or "C-like" code) on each of the platforms |
| 31 | that Rust supports. This includes type definitions (e.g. `c_int`), constants |
| 32 | (e.g. `EINVAL`) as well as function headers (e.g. `malloc`). |
| 33 | |
| 34 | This crate does not strive to have any form of compatibility across platforms, |
| 35 | but rather it is simply a straight binding to the system libraries on the |
| 36 | platform in question. |
| 37 | |
| 38 | ## Public API |
| 39 | |
| 40 | This crate exports all underlying platform types, functions, and constants under |
| 41 | the crate root, so all items are accessible as `libc::foo`. The types and values |
| 42 | of all the exported APIs match the platform that libc is compiled for. |
| 43 | |
| Alex Crichton | bbf73de | 2015-10-29 12:28:25 -0700 | [diff] [blame] | 44 | More detailed information about the design of this library can be found in its |
| 45 | [associated RFC][rfc]. |
| 46 | |
| 47 | [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1291-promote-libc.md |
| 48 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 49 | ## Adding an API |
| 50 | |
| 51 | Want to use an API which currently isn't bound in `libc`? It's quite easy to add |
| 52 | one! |
| 53 | |
| 54 | The internal structure of this crate is designed to minimize the number of |
| 55 | `#[cfg]` attributes in order to easily be able to add new items which apply |
| 56 | to all platforms in the future. As a result, the crate is organized |
| 57 | hierarchically based on platform. Each module has a number of `#[cfg]`'d |
| 58 | children, but only one is ever actually compiled. Each module then reexports all |
| 59 | the contents of its children. |
| 60 | |
| 61 | This means that for each platform that libc supports, the path from a |
| 62 | leaf module to the root will contain all bindings for the platform in question. |
| 63 | Consequently, this indicates where an API should be added! Adding an API at a |
| 64 | particular level in the hierarchy means that it is supported on all the child |
| 65 | platforms of that level. For example, when adding a Unix API it should be added |
| 66 | to `src/unix/mod.rs`, but when adding a Linux-only API it should be added to |
| 67 | `src/unix/notbsd/linux/mod.rs`. |
| 68 | |
| 69 | If you're not 100% sure at what level of the hierarchy an API should be added |
| 70 | at, fear not! This crate has CI support which tests any binding against all |
| 71 | platforms supported, so you'll see failures if an API is added at the wrong |
| 72 | level or has different signatures across platforms. |
| 73 | |
| Alex Crichton | 524e137 | 2015-10-29 11:57:29 -0700 | [diff] [blame] | 74 | With that in mind, the steps for adding a new API are: |
| 75 | |
| 76 | 1. Determine where in the module hierarchy your API should be added. |
| 77 | 2. Add the API. |
| 78 | 3. Send a PR to this repo. |
| 79 | 4. Wait for CI to pass, fixing errors. |
| 80 | 5. Wait for a merge! |
| 81 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 82 | ## Platforms and Documentation |
| 83 | |
| 84 | The following platforms are currently tested and have documentation available: |
| Alex Crichton | 78f5aca | 2015-09-18 15:01:16 -0700 | [diff] [blame] | 85 | |
| 86 | Tested: |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 87 | * [`i686-pc-windows-msvc`](https://doc.rust-lang.org/libc/i686-pc-windows-msvc/libc) |
| 88 | * [`x86_64-pc-windows-msvc`](https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc/libc) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 89 | (Windows) |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 90 | * [`i686-pc-windows-gnu`](https://doc.rust-lang.org/libc/i686-pc-windows-gnu/libc) |
| 91 | * [`x86_64-pc-windows-gnu`](https://doc.rust-lang.org/libc/x86_64-pc-windows-gnu/libc) |
| 92 | * [`i686-apple-darwin`](https://doc.rust-lang.org/libc/i686-apple-darwin/libc) |
| 93 | * [`x86_64-apple-darwin`](https://doc.rust-lang.org/libc/x86_64-apple-darwin/libc) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 94 | (OSX) |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 95 | * [`i686-apple-ios`](https://doc.rust-lang.org/libc/i686-apple-ios/libc) |
| 96 | * [`x86_64-apple-ios`](https://doc.rust-lang.org/libc/x86_64-apple-ios/libc) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 97 | (iOS) |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 98 | * [`i686-unknown-linux-gnu`](https://doc.rust-lang.org/libc/i686-unknown-linux-gnu/libc) |
| 99 | * [`x86_64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 100 | (Linux) |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 101 | * [`x86_64-unknown-linux-musl`](https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl/libc) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 102 | (Linux MUSL) |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 103 | * [`aarch64-unknown-linux-gnu`](https://doc.rust-lang.org/libc/aarch64-unknown-linux-gnu/libc) |
| 104 | * [`mips-unknown-linux-gnu`](https://doc.rust-lang.org/libc/mips-unknown-linux-gnu/libc) |
| 105 | * [`arm-unknown-linux-gnueabihf`](https://doc.rust-lang.org/libc/arm-unknown-linux-gnueabihf/libc) |
| 106 | * [`arm-linux-androideabi`](https://doc.rust-lang.org/libc/arm-linux-androideabi/libc) |
| Alex Crichton | b1fbefa | 2015-10-29 11:56:13 -0700 | [diff] [blame] | 107 | (Android) |
| Alex Crichton | 78f5aca | 2015-09-18 15:01:16 -0700 | [diff] [blame] | 108 | |
| Alex Crichton | 13418a5 | 2015-10-29 11:54:12 -0700 | [diff] [blame] | 109 | The following may be supported, but are not guaranteed to always work: |
| 110 | |
| 111 | * `x86_64-unknown-freebsd` |
| 112 | * `i686-unknown-freebsd` |
| 113 | * `x86_64-unknown-bitrig` |
| 114 | * `x86_64-unknown-dragonfly` |
| 115 | * `x86_64-unknown-openbsd` |
| 116 | * `x86_64-unknown-netbsd` |