Go to file
bors ac6e2a79b5 Auto merge of #1201 - thendiscard:master, r=gnzlbg
Remove fexecve from netbsdlike as it's not implemented

Sometimes it causes confusion in downstream users of libc, for example it caused nix-rust/nix to fail to compile on OpenBSD 6.4 (see https://github.com/nix-rust/nix/pull/1000).

OpenBSD doesn't implement fexecve. The only reference of it that I can
find in the OpenBSD source is in the man pages of signal(3) and
sigaction(2) (where it's mentioned that it is not implemented).

OpenBSD official source code link:
https://cvsweb.openbsd.org/src/lib/libc/sys/sigaction.2?rev=1.75&content-type=text/x-cvsweb-markup

OpenBSD Github mirror:
https://github.com/openbsd/src/blob/master/lib/libc/sys/sigaction.2#L619

On NetBSD's unistd.h I see that it is under an ifdef. Calling it returns
78 / ENOSYS / Function not implemented.

NetBSD office source code link:
http://cvsweb.netbsd.org/bsdweb.cgi/src/include/unistd.h?rev=1.151&content-type=text/x-cvsweb-markup&only_with_tag=MAIN

NetBSD Github mirror:
https://github.com/NetBSD/src/blob/trunk/include/unistd.h#L319

Tests on OpenBSD 6.4 after the change:
```bash
user@openbsd64 ~/RUST/libc $ cargo build
   Compiling libc v0.2.46 (/home/user/RUST/libc)
    Finished dev [unoptimized + debuginfo] target(s) in 3.88s

user@openbsd64 ~/RUST/libc $ cargo build --release
   Compiling libc v0.2.46 (/home/user/RUST/libc)
    Finished release [optimized] target(s) in 2.21s

user@openbsd64 ~/RUST/libc/libc-test $ cargo test
   Compiling proc-macro2 v0.4.24
   Compiling unicode-xid v0.1.0
   Compiling semver-parser v0.7.0
   Compiling serde v1.0.84
   Compiling libc v0.2.45
   Compiling num-traits v0.2.6
   Compiling ryu v0.2.7
   Compiling cfg-if v0.1.6
   Compiling itoa v0.4.3
   Compiling term v0.4.6
   Compiling bitflags v0.9.1
   Compiling cc v1.0.28
   Compiling libc v0.2.46 (/home/user/RUST/libc)
   Compiling log v0.4.6
   Compiling semver v0.9.0
   Compiling log v0.3.9
   Compiling rustc_version v0.2.3
   Compiling rand v0.4.3
   Compiling extprim v1.6.0
   Compiling quote v0.6.10
   Compiling syn v0.15.23
   Compiling serde_derive v1.0.84
   Compiling syntex_pos v0.59.1
   Compiling serde_json v1.0.34
   Compiling syntex_errors v0.59.1
   Compiling syntex_syntax v0.59.1
   Compiling ctest v0.2.8
   Compiling libc-test v0.1.0 (/home/user/RUST/libc/libc-test)
    Finished dev [unoptimized + debuginfo] target(s) in 2m 16s
     Running /home/user/RUST/libc/target/debug/deps/linux_fcntl-08861a7cd96d1b94
RUNNING ALL TESTS
PASSED 0 tests
     Running /home/user/RUST/libc/target/debug/deps/main-57e266d38aa58cce
RUNNING ALL TESTS
PASSED 7187 tests
```
I've tried running the tests on a NetBSD 8.0 box unfortunately there `libc-test` fails to compile even before this change.
2019-01-15 11:04:59 +00:00
ci Merge pull request #1172 from piersfinlayson/master 2018-12-11 15:47:36 -06:00
libc-test mincore has been removed from OpenBSD 6.5 2019-01-13 09:06:05 +01:00
src Auto merge of #1201 - thendiscard:master, r=gnzlbg 2019-01-15 11:04:59 +00:00
.cirrus.yml Move FreeBSD testing from Travis/QEMU to Cirrus-CI 2018-12-07 13:11:09 -07:00
.gitignore Add ~ to .gitignore 2016-01-29 21:34:19 +00:00
.travis.yml Auto merge of #1159 - cmbrandenburg:sysv_sem_support, r=alexcrichton 2018-12-09 02:34:28 +00:00
appveyor.yml Use Reqwest backend for Appveyor, not Hyper which is deprecated 2018-11-20 23:30:56 +00:00
build.rs core::ffi::c_void is available since rustc 1.30 2018-11-21 16:43:24 +09:00
Cargo.lock Bump version to 0.2.47 2019-01-14 08:07:57 -07:00
Cargo.toml Bump version to 0.2.47 2019-01-14 08:07:57 -07:00
LICENSE-APACHE Initial commit 2015-01-13 08:22:00 -08:00
LICENSE-MIT Initial commit 2015-01-13 08:22:00 -08:00
README.md Test out new bors integration 2019-01-02 10:27:19 -08:00

libc

Raw FFI bindings to platform libraries like libc.

Build Status Build status Build Status Latest version Documentation License

Usage

First, add the following to your Cargo.toml:

[dependencies]
libc = "0.2"

Next, add this to your crate root:

extern crate libc;

Currently libc by default links to the standard library, but if you would instead like to use libc in a #![no_std] situation or crate you can request this via:

[dependencies]
libc = { version = "0.2", default-features = false }

By default libc uses private fields in structs in order to enforce a certain memory alignment on them. These structs can be hard to instantiate outside of libc. To make libc use #[repr(align(x))], instead of the private fields, activate the align feature. This requires Rust 1.25 or newer:

[dependencies]
libc = { version = "0.2", features = ["align"] }

What is libc?

The primary purpose of this crate is to provide all of the definitions necessary to easily interoperate with C code (or "C-like" code) on each of the platforms that Rust supports. This includes type definitions (e.g. c_int), constants (e.g. EINVAL) as well as function headers (e.g. malloc).

This crate does not strive to have any form of compatibility across platforms, but rather it is simply a straight binding to the system libraries on the platform in question.

Public API

This crate exports all underlying platform types, functions, and constants under the crate root, so all items are accessible as libc::foo. The types and values of all the exported APIs match the platform that libc is compiled for.

More detailed information about the design of this library can be found in its associated RFC.

Adding an API

Want to use an API which currently isn't bound in libc? It's quite easy to add one!

The internal structure of this crate is designed to minimize the number of #[cfg] attributes in order to easily be able to add new items which apply to all platforms in the future. As a result, the crate is organized hierarchically based on platform. Each module has a number of #[cfg]'d children, but only one is ever actually compiled. Each module then reexports all the contents of its children.

This means that for each platform that libc supports, the path from a leaf module to the root will contain all bindings for the platform in question. Consequently, this indicates where an API should be added! Adding an API at a particular level in the hierarchy means that it is supported on all the child platforms of that level. For example, when adding a Unix API it should be added to src/unix/mod.rs, but when adding a Linux-only API it should be added to src/unix/notbsd/linux/mod.rs.

If you're not 100% sure at what level of the hierarchy an API should be added at, fear not! This crate has CI support which tests any binding against all platforms supported, so you'll see failures if an API is added at the wrong level or has different signatures across platforms.

With that in mind, the steps for adding a new API are:

  1. Determine where in the module hierarchy your API should be added.
  2. Add the API.
  3. Send a PR to this repo.
  4. Wait for CI to pass, fixing errors.
  5. Wait for a merge!

Test before you commit

We have two automated tests running on Travis:

  1. libc-test
  • cd libc-test && cargo test
  • Use the skip_*() functions in build.rs if you really need a workaround.
  1. Style checker
  • rustc ci/style.rs && ./style src

Releasing your change to crates.io

Now that you've done the amazing job of landing your new API or your new platform in this crate, the next step is to get that sweet, sweet usage from crates.io! The only next step is to bump the version of libc and then publish it. If you'd like to get a release out ASAP you can follow these steps:

  1. Update the version number in Cargo.toml, you'll just be bumping the patch version number.
  2. Run cargo update to regenerate the lockfile to encode your version bump in the lock file. You may pull in some other updated dependencies, that's ok.
  3. Send a PR to this repository. It should look like this, but it'd also be nice to fill out the description with a small rationale for the release (any rationale is ok though!)
  4. Once merged the release will be tagged and published by one of the libc crate maintainers.

Platforms and Documentation

The following platforms are currently tested and have documentation available:

Tested:

The following may be supported, but are not guaranteed to always work: