Skip to content

Commit 3ec076c

Browse files
committed
Initial commit
0 parents  commit 3ec076c

File tree

5 files changed

+117
-0
lines changed

5 files changed

+117
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
Cargo.lock

Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "c-types"
3+
license = "MIT"
4+
version = "0.1.0"
5+
authors = ["David Hotham"]
6+
description = """
7+
Re-exports of cross-platform types, gathered from libc and winapi
8+
"""
9+
homepage = "https://github.com/dimbleby/rust-c-types"
10+
repository = "https://github.com/dimbleby/rust-c-types"
11+
documentation = "http://dimbleby.github.io/rust-c-types"
12+
readme = "README.md"
13+
keywords = ["libc", "winapi"]
14+
15+
[dependencies]
16+
libc = "*"
17+
winapi = "*"

LICENSE.txt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 David Hotham
4+
5+
Permission is hereby granted, free of charge, to any
6+
person obtaining a copy of this software and associated
7+
documentation files (the "Software"), to deal in the
8+
Software without restriction, including without
9+
limitation the rights to use, copy, modify, merge,
10+
publish, distribute, sublicense, and/or sell copies of
11+
the Software, and to permit persons to whom the Software
12+
is furnished to do so, subject to the following
13+
conditions:
14+
15+
The above copyright notice and this permission notice
16+
shall be included in all copies or substantial portions
17+
of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
20+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
21+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
22+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
23+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
26+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27+
DEALINGS IN THE SOFTWARE.

src/ctypes.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#![allow(non_camel_case_types)]
2+
3+
#[cfg(unix)]
4+
mod unix {
5+
extern crate libc;
6+
7+
pub type fd_set = libc::fd_set;
8+
9+
#[repr(C)]
10+
#[derive(Debug)]
11+
#[allow(raw_pointer_derive)]
12+
pub struct hostent {
13+
pub h_name: *mut libc::c_char,
14+
pub h_aliases: *mut *mut libc::c_char,
15+
pub h_addrtype: libc::c_int,
16+
pub h_length: libc::c_int,
17+
pub h_addr_list: *mut *mut libc::c_char,
18+
}
19+
20+
pub type in_addr = libc::in_addr;
21+
pub type in6_addr = libc::in6_addr;
22+
pub type sa_family_t = libc::sa_family_t;
23+
pub type sockaddr = libc::sockaddr;
24+
pub type sockaddr_in = libc::sockaddr_in;
25+
pub type sockaddr_in6 = libc::sockaddr_in6;
26+
27+
pub const AF_INET: i32 = libc::AF_INET;
28+
pub const AF_INET6: i32 = libc::AF_INET6;
29+
}
30+
31+
#[cfg(windows)]
32+
mod windows {
33+
extern crate winapi;
34+
35+
pub type fd_set = winapi::fd_set;
36+
pub type hostent = winapi::winsock2::hostent;
37+
pub type in_addr = winapi::in_addr;
38+
pub type in6_addr = winapi::in6_addr;
39+
pub type sa_family_t = winapi::ws2def::ADDRESS_FAMILY;
40+
pub type sockaddr = winapi::SOCKADDR;
41+
pub type sockaddr_in = winapi::ws2def::SOCKADDR_IN;
42+
pub type sockaddr_in6 = winapi::ws2ipdef::sockaddr_in6;
43+
44+
pub const AF_INET: i32 = winapi::ws2def::AF_INET;
45+
pub const AF_INET6: i32 = winapi::ws2def::AF_INET6;
46+
}
47+
48+
#[cfg(unix)]
49+
pub use self::unix::*;
50+
51+
#[cfg(windows)]
52+
pub use self::windows::*;

src/lib.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! A crate that re-exports various types defined in both `libc` and `winapi`.
2+
//!
3+
//! Stop having to write code like this:
4+
//!
5+
//! ```
6+
//! #[cfg(unix)]
7+
//! use libc::some_type;
8+
//!
9+
//! #[cfg(windows)]
10+
//! use winapi::some_type;
11+
//! ```
12+
//!
13+
//! Instead, write code like this:
14+
//!
15+
//! ```
16+
//! use c_types::some_type;
17+
//! ```
18+
mod ctypes;
19+
pub use ctypes::*;

0 commit comments

Comments
 (0)