]>
Commit | Line | Data |
---|---|---|
92a42be0 SL |
1 | // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | //! Crate docs | |
12 | ||
13 | #![allow(bad_style, overflowing_literals, improper_ctypes)] | |
14 | #![crate_type = "rlib"] | |
15 | #![crate_name = "libc"] | |
16 | #![cfg_attr(dox, feature(no_core, lang_items))] | |
17 | #![cfg_attr(dox, no_core)] | |
18 | #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", | |
19 | html_favicon_url = "https://doc.rust-lang.org/favicon.ico")] | |
20 | ||
21 | #![cfg_attr(all(target_os = "linux", target_arch = "x86_64"), doc( | |
22 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu" | |
23 | ))] | |
24 | #![cfg_attr(all(target_os = "linux", target_arch = "x86"), doc( | |
25 | html_root_url = "https://doc.rust-lang.org/libc/i686-unknown-linux-gnu" | |
26 | ))] | |
27 | #![cfg_attr(all(target_os = "linux", target_arch = "arm"), doc( | |
28 | html_root_url = "https://doc.rust-lang.org/libc/arm-unknown-linux-gnueabihf" | |
29 | ))] | |
30 | #![cfg_attr(all(target_os = "linux", target_arch = "mips"), doc( | |
31 | html_root_url = "https://doc.rust-lang.org/libc/mips-unknown-linux-gnu" | |
32 | ))] | |
33 | #![cfg_attr(all(target_os = "linux", target_arch = "aarch64"), doc( | |
34 | html_root_url = "https://doc.rust-lang.org/libc/aarch64-unknown-linux-gnu" | |
35 | ))] | |
9e0c209e SL |
36 | #![cfg_attr(all(target_os = "linux", target_arch = "s390x"), doc( |
37 | html_root_url = "https://doc.rust-lang.org/libc/s390x-unknown-linux-gnu" | |
38 | ))] | |
92a42be0 SL |
39 | #![cfg_attr(all(target_os = "linux", target_env = "musl"), doc( |
40 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl" | |
41 | ))] | |
42 | #![cfg_attr(all(target_os = "macos", target_arch = "x86_64"), doc( | |
43 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-apple-darwin" | |
44 | ))] | |
45 | #![cfg_attr(all(target_os = "macos", target_arch = "x86"), doc( | |
46 | html_root_url = "https://doc.rust-lang.org/libc/i686-apple-darwin" | |
47 | ))] | |
48 | #![cfg_attr(all(windows, target_arch = "x86_64", target_env = "gnu"), doc( | |
49 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-pc-windows-gnu" | |
50 | ))] | |
51 | #![cfg_attr(all(windows, target_arch = "x86", target_env = "gnu"), doc( | |
52 | html_root_url = "https://doc.rust-lang.org/libc/i686-pc-windows-gnu" | |
53 | ))] | |
54 | #![cfg_attr(all(windows, target_arch = "x86_64", target_env = "msvc"), doc( | |
55 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc" | |
56 | ))] | |
57 | #![cfg_attr(all(windows, target_arch = "x86", target_env = "msvc"), doc( | |
58 | html_root_url = "https://doc.rust-lang.org/libc/i686-pc-windows-msvc" | |
59 | ))] | |
9cc50fc6 | 60 | #![cfg_attr(target_os = "android", doc( |
92a42be0 SL |
61 | html_root_url = "https://doc.rust-lang.org/libc/arm-linux-androideabi" |
62 | ))] | |
9cc50fc6 SL |
63 | #![cfg_attr(target_os = "freebsd", doc( |
64 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-freebsd" | |
65 | ))] | |
66 | #![cfg_attr(target_os = "openbsd", doc( | |
67 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-openbsd" | |
68 | ))] | |
69 | #![cfg_attr(target_os = "bitrig", doc( | |
70 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-bitrig" | |
71 | ))] | |
72 | #![cfg_attr(target_os = "netbsd", doc( | |
73 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-netbsd" | |
74 | ))] | |
75 | #![cfg_attr(target_os = "dragonfly", doc( | |
76 | html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-dragonfly" | |
77 | ))] | |
92a42be0 SL |
78 | |
79 | // Attributes needed when building as part of the standard library | |
54a0048b | 80 | #![cfg_attr(stdbuild, feature(no_std, core, core_slice_ext, staged_api, custom_attribute, cfg_target_vendor))] |
92a42be0 SL |
81 | #![cfg_attr(stdbuild, no_std)] |
82 | #![cfg_attr(stdbuild, staged_api)] | |
83 | #![cfg_attr(stdbuild, allow(warnings))] | |
84 | #![cfg_attr(stdbuild, unstable(feature = "libc", | |
85 | reason = "use `libc` from crates.io", | |
86 | issue = "27783"))] | |
87 | ||
7453a54e SL |
88 | #![cfg_attr(not(feature = "use_std"), no_std)] |
89 | ||
90 | #[cfg(all(not(stdbuild), not(dox), feature = "use_std"))] | |
92a42be0 SL |
91 | extern crate std as core; |
92 | ||
93 | #[macro_use] mod macros; | |
94 | mod dox; | |
95 | ||
96 | // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable | |
97 | // more optimization opportunities around it recognizing things like | |
98 | // malloc/free. | |
99 | #[repr(u8)] | |
100 | pub enum c_void { | |
101 | // Two dummy variants so the #[repr] attribute can be used. | |
102 | #[doc(hidden)] | |
103 | __variant1, | |
104 | #[doc(hidden)] | |
105 | __variant2, | |
106 | } | |
107 | ||
108 | pub type int8_t = i8; | |
109 | pub type int16_t = i16; | |
110 | pub type int32_t = i32; | |
111 | pub type int64_t = i64; | |
112 | pub type uint8_t = u8; | |
113 | pub type uint16_t = u16; | |
114 | pub type uint32_t = u32; | |
115 | pub type uint64_t = u64; | |
116 | ||
117 | pub type c_schar = i8; | |
118 | pub type c_uchar = u8; | |
119 | pub type c_short = i16; | |
120 | pub type c_ushort = u16; | |
121 | pub type c_int = i32; | |
122 | pub type c_uint = u32; | |
123 | pub type c_float = f32; | |
124 | pub type c_double = f64; | |
125 | pub type c_longlong = i64; | |
126 | pub type c_ulonglong = u64; | |
127 | pub type intmax_t = i64; | |
128 | pub type uintmax_t = u64; | |
129 | ||
130 | pub type size_t = usize; | |
131 | pub type ptrdiff_t = isize; | |
132 | pub type intptr_t = isize; | |
133 | pub type uintptr_t = usize; | |
134 | pub type ssize_t = isize; | |
135 | ||
136 | pub enum FILE {} | |
137 | pub enum fpos_t {} // TODO: fill this out with a struct | |
138 | ||
139 | extern { | |
140 | pub fn isalnum(c: c_int) -> c_int; | |
141 | pub fn isalpha(c: c_int) -> c_int; | |
142 | pub fn iscntrl(c: c_int) -> c_int; | |
143 | pub fn isdigit(c: c_int) -> c_int; | |
144 | pub fn isgraph(c: c_int) -> c_int; | |
145 | pub fn islower(c: c_int) -> c_int; | |
146 | pub fn isprint(c: c_int) -> c_int; | |
147 | pub fn ispunct(c: c_int) -> c_int; | |
148 | pub fn isspace(c: c_int) -> c_int; | |
149 | pub fn isupper(c: c_int) -> c_int; | |
150 | pub fn isxdigit(c: c_int) -> c_int; | |
151 | pub fn tolower(c: c_int) -> c_int; | |
152 | pub fn toupper(c: c_int) -> c_int; | |
153 | ||
154 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), | |
155 | link_name = "fopen$UNIX2003")] | |
156 | pub fn fopen(filename: *const c_char, | |
157 | mode: *const c_char) -> *mut FILE; | |
158 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), | |
159 | link_name = "freopen$UNIX2003")] | |
160 | pub fn freopen(filename: *const c_char, mode: *const c_char, | |
161 | file: *mut FILE) -> *mut FILE; | |
162 | pub fn fflush(file: *mut FILE) -> c_int; | |
163 | pub fn fclose(file: *mut FILE) -> c_int; | |
164 | pub fn remove(filename: *const c_char) -> c_int; | |
165 | pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; | |
166 | pub fn tmpfile() -> *mut FILE; | |
167 | pub fn setvbuf(stream: *mut FILE, | |
168 | buffer: *mut c_char, | |
169 | mode: c_int, | |
170 | size: size_t) -> c_int; | |
171 | pub fn setbuf(stream: *mut FILE, buf: *mut c_char); | |
9e0c209e SL |
172 | pub fn getchar() -> c_int; |
173 | pub fn putchar(c: c_int) -> c_int; | |
92a42be0 SL |
174 | pub fn fgetc(stream: *mut FILE) -> c_int; |
175 | pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; | |
176 | pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; | |
177 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), | |
178 | link_name = "fputs$UNIX2003")] | |
179 | pub fn fputs(s: *const c_char, stream: *mut FILE)-> c_int; | |
180 | pub fn puts(s: *const c_char) -> c_int; | |
181 | pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; | |
182 | pub fn fread(ptr: *mut c_void, | |
183 | size: size_t, | |
184 | nobj: size_t, | |
185 | stream: *mut FILE) | |
186 | -> size_t; | |
187 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), | |
188 | link_name = "fwrite$UNIX2003")] | |
189 | pub fn fwrite(ptr: *const c_void, | |
190 | size: size_t, | |
191 | nobj: size_t, | |
192 | stream: *mut FILE) | |
193 | -> size_t; | |
194 | pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; | |
195 | pub fn ftell(stream: *mut FILE) -> c_long; | |
196 | pub fn rewind(stream: *mut FILE); | |
9cc50fc6 | 197 | #[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")] |
92a42be0 | 198 | pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; |
9cc50fc6 | 199 | #[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")] |
92a42be0 SL |
200 | pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; |
201 | pub fn feof(stream: *mut FILE) -> c_int; | |
202 | pub fn ferror(stream: *mut FILE) -> c_int; | |
203 | pub fn perror(s: *const c_char); | |
204 | pub fn atoi(s: *const c_char) -> c_int; | |
205 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), | |
206 | link_name = "strtod$UNIX2003")] | |
207 | pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; | |
208 | pub fn strtol(s: *const c_char, | |
209 | endp: *mut *mut c_char, base: c_int) -> c_long; | |
210 | pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, | |
211 | base: c_int) -> c_ulong; | |
212 | pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; | |
213 | pub fn malloc(size: size_t) -> *mut c_void; | |
214 | pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; | |
215 | pub fn free(p: *mut c_void); | |
7453a54e | 216 | pub fn abort() -> !; |
92a42be0 SL |
217 | pub fn exit(status: c_int) -> !; |
218 | pub fn _exit(status: c_int) -> !; | |
219 | pub fn atexit(cb: extern fn()) -> c_int; | |
220 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), | |
221 | link_name = "system$UNIX2003")] | |
222 | pub fn system(s: *const c_char) -> c_int; | |
223 | pub fn getenv(s: *const c_char) -> *mut c_char; | |
224 | ||
225 | pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; | |
226 | pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t) | |
227 | -> *mut c_char; | |
228 | pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; | |
229 | pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char; | |
230 | pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; | |
231 | pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; | |
232 | pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; | |
233 | pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; | |
234 | pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; | |
235 | pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; | |
236 | pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; | |
5bcae85e | 237 | pub fn strdup(cs: *const c_char) -> *mut c_char; |
92a42be0 SL |
238 | pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; |
239 | pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; | |
240 | pub fn strlen(cs: *const c_char) -> size_t; | |
a7813a04 | 241 | pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; |
92a42be0 SL |
242 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
243 | link_name = "strerror$UNIX2003")] | |
244 | pub fn strerror(n: c_int) -> *mut c_char; | |
245 | pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; | |
246 | pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; | |
247 | pub fn wcslen(buf: *const wchar_t) -> size_t; | |
248 | ||
92a42be0 | 249 | pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; |
9e0c209e SL |
250 | pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; |
251 | pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; | |
252 | pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; | |
253 | pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; | |
92a42be0 SL |
254 | } |
255 | ||
256 | // These are all inline functions on android, so they end up just being entirely | |
257 | // missing on that platform. | |
258 | #[cfg(not(target_os = "android"))] | |
259 | extern { | |
260 | pub fn abs(i: c_int) -> c_int; | |
261 | pub fn atof(s: *const c_char) -> c_double; | |
262 | pub fn labs(i: c_long) -> c_long; | |
263 | pub fn rand() -> c_int; | |
264 | pub fn srand(seed: c_uint); | |
265 | } | |
266 | ||
267 | cfg_if! { | |
268 | if #[cfg(windows)] { | |
269 | mod windows; | |
270 | pub use windows::*; | |
54a0048b | 271 | } else if #[cfg(unix)] { |
92a42be0 SL |
272 | mod unix; |
273 | pub use unix::*; | |
54a0048b SL |
274 | } else { |
275 | // Unknown target_family | |
92a42be0 SL |
276 | } |
277 | } |