blob: ff53835fd1e3639d8935b106406242bda157b432 [file] [log] [blame]
Alex Crichtondafaca92015-09-09 21:50:47 -07001// 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
Alex Crichton95b18b72015-09-17 10:06:58 -070011//! Crate docs
12
Alex Crichton07d3a0d2015-10-30 10:21:32 -070013#![allow(bad_style, raw_pointer_derive, overflowing_literals, improper_ctypes)]
Alex Crichton24abc4f2015-09-16 23:54:56 -070014#![cfg_attr(dox, feature(no_core, lang_items))]
15#![cfg_attr(dox, no_core)]
16#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
17 html_favicon_url = "https://doc.rust-lang.org/favicon.ico")]
18
Alex Crichton730a17f2015-09-17 10:05:36 -070019#![cfg_attr(all(target_os = "linux", target_arch = "x86_64"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070020 html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu"
Alex Crichton730a17f2015-09-17 10:05:36 -070021))]
22#![cfg_attr(all(target_os = "linux", target_arch = "x86"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070023 html_root_url = "https://doc.rust-lang.org/libc/i686-unknown-linux-gnu"
Alex Crichton730a17f2015-09-17 10:05:36 -070024))]
25#![cfg_attr(all(target_os = "linux", target_arch = "arm"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070026 html_root_url = "https://doc.rust-lang.org/libc/arm-unknown-linux-gnueabihf"
Alex Crichton730a17f2015-09-17 10:05:36 -070027))]
28#![cfg_attr(all(target_os = "linux", target_arch = "mips"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070029 html_root_url = "https://doc.rust-lang.org/libc/mips-unknown-linux-gnu"
Alex Crichton730a17f2015-09-17 10:05:36 -070030))]
Alex Crichtond13e1e42015-09-17 17:29:18 -070031#![cfg_attr(all(target_os = "linux", target_arch = "aarch64"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070032 html_root_url = "https://doc.rust-lang.org/libc/aarch64-unknown-linux-gnu"
Alex Crichtond13e1e42015-09-17 17:29:18 -070033))]
Alex Crichton730a17f2015-09-17 10:05:36 -070034#![cfg_attr(all(target_os = "linux", target_env = "musl"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070035 html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl"
Alex Crichton730a17f2015-09-17 10:05:36 -070036))]
37#![cfg_attr(all(target_os = "macos", target_arch = "x86_64"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070038 html_root_url = "https://doc.rust-lang.org/libc/x86_64-apple-darwin"
Alex Crichton730a17f2015-09-17 10:05:36 -070039))]
40#![cfg_attr(all(target_os = "macos", target_arch = "x86"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070041 html_root_url = "https://doc.rust-lang.org/libc/i686-apple-darwin"
Alex Crichton730a17f2015-09-17 10:05:36 -070042))]
43#![cfg_attr(all(windows, target_arch = "x86_64", target_env = "gnu"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070044 html_root_url = "https://doc.rust-lang.org/libc/x86_64-pc-windows-gnu"
Alex Crichton730a17f2015-09-17 10:05:36 -070045))]
Alex Crichton611e9a32015-09-17 10:06:19 -070046#![cfg_attr(all(windows, target_arch = "x86", target_env = "gnu"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070047 html_root_url = "https://doc.rust-lang.org/libc/i686-pc-windows-gnu"
Alex Crichton730a17f2015-09-17 10:05:36 -070048))]
49#![cfg_attr(all(windows, target_arch = "x86_64", target_env = "msvc"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070050 html_root_url = "https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc"
Alex Crichton730a17f2015-09-17 10:05:36 -070051))]
Alex Crichton611e9a32015-09-17 10:06:19 -070052#![cfg_attr(all(windows, target_arch = "x86", target_env = "msvc"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070053 html_root_url = "https://doc.rust-lang.org/libc/i686-pc-windows-msvc"
Alex Crichton730a17f2015-09-17 10:05:36 -070054))]
55#![cfg_attr(all(target_os = "android"), doc(
Alex Crichton13418a52015-10-29 11:54:12 -070056 html_root_url = "https://doc.rust-lang.org/libc/arm-linux-androideabi"
Alex Crichton730a17f2015-09-17 10:05:36 -070057))]
Alex Crichtondafaca92015-09-09 21:50:47 -070058
Alex Crichton5d6cf052015-09-11 14:52:34 -070059#[macro_use] mod macros;
Alex Crichton24abc4f2015-09-16 23:54:56 -070060mod dox;
Alex Crichton31504842015-09-10 23:43:41 -070061
Alex Crichtond5c4e552015-10-29 15:46:16 -070062// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
63// more optimization opportunities around it recognizing things like
64// malloc/free.
Alex Crichton5d6cf052015-09-11 14:52:34 -070065#[repr(u8)]
66pub enum c_void {
Alex Crichtond5c4e552015-10-29 15:46:16 -070067 // Two dummy variants so the #[repr] attribute can be used.
Alex Crichton9f2b1012015-09-16 23:32:21 -070068 #[doc(hidden)]
Alex Crichton5d6cf052015-09-11 14:52:34 -070069 __variant1,
Alex Crichton9f2b1012015-09-16 23:32:21 -070070 #[doc(hidden)]
Alex Crichton5d6cf052015-09-11 14:52:34 -070071 __variant2,
72}
Alex Crichtondafaca92015-09-09 21:50:47 -070073
Alex Crichton5d6cf052015-09-11 14:52:34 -070074pub type int8_t = i8;
75pub type int16_t = i16;
76pub type int32_t = i32;
77pub type int64_t = i64;
78pub type uint8_t = u8;
79pub type uint16_t = u16;
80pub type uint32_t = u32;
81pub type uint64_t = u64;
Alex Crichtondafaca92015-09-09 21:50:47 -070082
Alex Crichton17910462015-09-22 19:11:04 -070083pub type c_schar = i8;
84pub type c_uchar = u8;
85pub type c_short = i16;
86pub type c_ushort = u16;
87pub type c_int = i32;
88pub type c_uint = u32;
89pub type c_float = f32;
90pub type c_double = f64;
91pub type c_longlong = i64;
92pub type c_ulonglong = u64;
93pub type intmax_t = i64;
94pub type uintmax_t = u64;
95
96pub type size_t = usize;
97pub type ptrdiff_t = isize;
98pub type intptr_t = isize;
99pub type uintptr_t = usize;
100pub type ssize_t = isize;
101
Alex Crichton5d6cf052015-09-11 14:52:34 -0700102pub enum FILE {}
Alex Crichton74825222015-10-29 17:36:55 -0700103pub enum fpos_t {} // TODO: fill this out with a struct
Alex Crichtondafaca92015-09-09 21:50:47 -0700104
Alex Crichton5d6cf052015-09-11 14:52:34 -0700105extern {
106 pub fn isalnum(c: c_int) -> c_int;
107 pub fn isalpha(c: c_int) -> c_int;
108 pub fn iscntrl(c: c_int) -> c_int;
109 pub fn isdigit(c: c_int) -> c_int;
110 pub fn isgraph(c: c_int) -> c_int;
111 pub fn islower(c: c_int) -> c_int;
112 pub fn isprint(c: c_int) -> c_int;
113 pub fn ispunct(c: c_int) -> c_int;
114 pub fn isspace(c: c_int) -> c_int;
115 pub fn isupper(c: c_int) -> c_int;
116 pub fn isxdigit(c: c_int) -> c_int;
117 pub fn tolower(c: c_int) -> c_int;
118 pub fn toupper(c: c_int) -> c_int;
Alex Crichtondafaca92015-09-09 21:50:47 -0700119
Alex Crichton5d6cf052015-09-11 14:52:34 -0700120 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
121 link_name = "fopen$UNIX2003")]
122 pub fn fopen(filename: *const c_char,
123 mode: *const c_char) -> *mut FILE;
124 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
125 link_name = "freopen$UNIX2003")]
126 pub fn freopen(filename: *const c_char, mode: *const c_char,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700127 file: *mut FILE) -> *mut FILE;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700128 pub fn fflush(file: *mut FILE) -> c_int;
129 pub fn fclose(file: *mut FILE) -> c_int;
130 pub fn remove(filename: *const c_char) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700131 pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700132 pub fn tmpfile() -> *mut FILE;
133 pub fn setvbuf(stream: *mut FILE,
134 buffer: *mut c_char,
135 mode: c_int,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700136 size: size_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700137 pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
Alex Crichton5d6cf052015-09-11 14:52:34 -0700138 pub fn fgetc(stream: *mut FILE) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700139 pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700140 pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
141 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
142 link_name = "fputs$UNIX2003")]
143 pub fn fputs(s: *const c_char, stream: *mut FILE)-> c_int;
144 pub fn puts(s: *const c_char) -> c_int;
145 pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
146 pub fn fread(ptr: *mut c_void,
147 size: size_t,
148 nobj: size_t,
149 stream: *mut FILE)
150 -> size_t;
151 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
152 link_name = "fwrite$UNIX2003")]
153 pub fn fwrite(ptr: *const c_void,
154 size: size_t,
155 nobj: size_t,
156 stream: *mut FILE)
157 -> size_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700158 pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700159 pub fn ftell(stream: *mut FILE) -> c_long;
160 pub fn rewind(stream: *mut FILE);
161 pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
162 pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
163 pub fn feof(stream: *mut FILE) -> c_int;
164 pub fn ferror(stream: *mut FILE) -> c_int;
165 pub fn perror(s: *const c_char);
Alex Crichton5d6cf052015-09-11 14:52:34 -0700166 pub fn atoi(s: *const c_char) -> c_int;
167 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
168 link_name = "strtod$UNIX2003")]
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700169 pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700170 pub fn strtol(s: *const c_char,
171 endp: *mut *mut c_char, base: c_int) -> c_long;
172 pub fn strtoul(s: *const c_char, endp: *mut *mut c_char,
173 base: c_int) -> c_ulong;
174 pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
175 pub fn malloc(size: size_t) -> *mut c_void;
176 pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
177 pub fn free(p: *mut c_void);
178 pub fn exit(status: c_int) -> !;
179 pub fn _exit(status: c_int) -> !;
180 pub fn atexit(cb: extern fn()) -> c_int;
181 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
182 link_name = "system$UNIX2003")]
183 pub fn system(s: *const c_char) -> c_int;
184 pub fn getenv(s: *const c_char) -> *mut c_char;
Alex Crichtondafaca92015-09-09 21:50:47 -0700185
Alex Crichton5d6cf052015-09-11 14:52:34 -0700186 pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
187 pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t)
188 -> *mut c_char;
189 pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
190 pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
191 pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
192 pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
193 pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
194 pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
195 pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
196 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
197 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
198 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
199 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
200 pub fn strlen(cs: *const c_char) -> size_t;
201 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
202 link_name = "strerror$UNIX2003")]
203 pub fn strerror(n: c_int) -> *mut c_char;
204 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
205 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
206 pub fn wcslen(buf: *const wchar_t) -> size_t;
Alex Crichtondafaca92015-09-09 21:50:47 -0700207
Alex Crichton5d6cf052015-09-11 14:52:34 -0700208 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
209 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
Alex Crichtondafaca92015-09-09 21:50:47 -0700210}
Alex Crichtond3d77922015-09-11 17:03:39 -0700211
Alex Crichtond5c4e552015-10-29 15:46:16 -0700212// These are all inline functions on android, so they end up just being entirely
213// missing on that platform.
Alex Crichtond3d77922015-09-11 17:03:39 -0700214#[cfg(not(target_os = "android"))]
215extern {
216 pub fn abs(i: c_int) -> c_int;
217 pub fn atof(s: *const c_char) -> c_double;
218 pub fn labs(i: c_long) -> c_long;
219 pub fn rand() -> c_int;
220 pub fn srand(seed: c_uint);
221}
Alex Crichton50a42e22015-09-15 14:27:15 -0700222
223cfg_if! {
224 if #[cfg(windows)] {
225 mod windows;
226 pub use windows::*;
227 } else {
228 mod unix;
229 pub use unix::*;
230 }
231}