blob: a7ecabda563f48c444a63360263f1bd081b159e8 [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 Crichtondafaca92015-09-09 21:50:47 -070011#![allow(bad_style, raw_pointer_derive)]
Alex Crichton24abc4f2015-09-16 23:54:56 -070012#![cfg_attr(dox, feature(no_core, lang_items))]
13#![cfg_attr(dox, no_core)]
14#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
15 html_favicon_url = "https://doc.rust-lang.org/favicon.ico")]
16
Alex Crichton730a17f2015-09-17 10:05:36 -070017#![cfg_attr(all(target_os = "linux", target_arch = "x86_64"), doc(
18 html_root_url = "http://alexcrichton.com/libc/x86_64-unknown-linux-gnu"
19))]
20#![cfg_attr(all(target_os = "linux", target_arch = "x86"), doc(
21 html_root_url = "http://alexcrichton.com/libc/i686-unknown-linux-gnu"
22))]
23#![cfg_attr(all(target_os = "linux", target_arch = "arm"), doc(
24 html_root_url = "http://alexcrichton.com/libc/arm-unknown-linux-gnueabihf"
25))]
26#![cfg_attr(all(target_os = "linux", target_arch = "mips"), doc(
27 html_root_url = "http://alexcrichton.com/libc/mips-unknown-linux-gnu"
28))]
29#![cfg_attr(all(target_os = "linux", target_env = "musl"), doc(
30 html_root_url = "http://alexcrichton.com/libc/x86_64-unknown-linux-musl"
31))]
32#![cfg_attr(all(target_os = "macos", target_arch = "x86_64"), doc(
33 html_root_url = "http://alexcrichton.com/libc/x86_64-apple-darwin"
34))]
35#![cfg_attr(all(target_os = "macos", target_arch = "x86"), doc(
36 html_root_url = "http://alexcrichton.com/libc/i686-apple-darwin"
37))]
38#![cfg_attr(all(windows, target_arch = "x86_64", target_env = "gnu"), doc(
39 html_root_url = "http://alexcrichton.com/libc/x86_64-pc-windows-gnu"
40))]
Alex Crichton611e9a32015-09-17 10:06:19 -070041#![cfg_attr(all(windows, target_arch = "x86", target_env = "gnu"), doc(
Alex Crichton730a17f2015-09-17 10:05:36 -070042 html_root_url = "http://alexcrichton.com/libc/i686-pc-windows-gnu"
43))]
44#![cfg_attr(all(windows, target_arch = "x86_64", target_env = "msvc"), doc(
45 html_root_url = "http://alexcrichton.com/libc/x86_64-pc-windows-msvc"
46))]
Alex Crichton611e9a32015-09-17 10:06:19 -070047#![cfg_attr(all(windows, target_arch = "x86", target_env = "msvc"), doc(
Alex Crichton730a17f2015-09-17 10:05:36 -070048 html_root_url = "http://alexcrichton.com/libc/i686-pc-windows-msvc"
49))]
50#![cfg_attr(all(target_os = "android"), doc(
51 html_root_url = "http://alexcrichton.com/libc/arm-linux-androideabi"
52))]
Alex Crichtondafaca92015-09-09 21:50:47 -070053
Alex Crichton5d6cf052015-09-11 14:52:34 -070054#[macro_use] mod macros;
Alex Crichton24abc4f2015-09-16 23:54:56 -070055mod dox;
Alex Crichton31504842015-09-10 23:43:41 -070056
Alex Crichton5d6cf052015-09-11 14:52:34 -070057#[repr(u8)]
58pub enum c_void {
Alex Crichton9f2b1012015-09-16 23:32:21 -070059 // Two dummy variants so the #[repr] attribute can be used
60 #[doc(hidden)]
Alex Crichton5d6cf052015-09-11 14:52:34 -070061 __variant1,
Alex Crichton9f2b1012015-09-16 23:32:21 -070062 #[doc(hidden)]
Alex Crichton5d6cf052015-09-11 14:52:34 -070063 __variant2,
64}
Alex Crichtondafaca92015-09-09 21:50:47 -070065
Alex Crichton5d6cf052015-09-11 14:52:34 -070066pub type int8_t = i8;
67pub type int16_t = i16;
68pub type int32_t = i32;
69pub type int64_t = i64;
70pub type uint8_t = u8;
71pub type uint16_t = u16;
72pub type uint32_t = u32;
73pub type uint64_t = u64;
Alex Crichtondafaca92015-09-09 21:50:47 -070074
Alex Crichton5d6cf052015-09-11 14:52:34 -070075pub enum FILE {}
76pub enum fpos_t {}
77pub enum DIR {}
78pub enum dirent {}
Alex Crichtondafaca92015-09-09 21:50:47 -070079
Alex Crichton5d6cf052015-09-11 14:52:34 -070080extern {
81 pub fn isalnum(c: c_int) -> c_int;
82 pub fn isalpha(c: c_int) -> c_int;
83 pub fn iscntrl(c: c_int) -> c_int;
84 pub fn isdigit(c: c_int) -> c_int;
85 pub fn isgraph(c: c_int) -> c_int;
86 pub fn islower(c: c_int) -> c_int;
87 pub fn isprint(c: c_int) -> c_int;
88 pub fn ispunct(c: c_int) -> c_int;
89 pub fn isspace(c: c_int) -> c_int;
90 pub fn isupper(c: c_int) -> c_int;
91 pub fn isxdigit(c: c_int) -> c_int;
92 pub fn tolower(c: c_int) -> c_int;
93 pub fn toupper(c: c_int) -> c_int;
Alex Crichtondafaca92015-09-09 21:50:47 -070094
Alex Crichton5d6cf052015-09-11 14:52:34 -070095 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
96 link_name = "fopen$UNIX2003")]
97 pub fn fopen(filename: *const c_char,
98 mode: *const c_char) -> *mut FILE;
99 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
100 link_name = "freopen$UNIX2003")]
101 pub fn freopen(filename: *const c_char, mode: *const c_char,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700102 file: *mut FILE) -> *mut FILE;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700103 pub fn fflush(file: *mut FILE) -> c_int;
104 pub fn fclose(file: *mut FILE) -> c_int;
105 pub fn remove(filename: *const c_char) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700106 pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700107 pub fn tmpfile() -> *mut FILE;
108 pub fn setvbuf(stream: *mut FILE,
109 buffer: *mut c_char,
110 mode: c_int,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700111 size: size_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700112 pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
Alex Crichton5d6cf052015-09-11 14:52:34 -0700113 pub fn fgetc(stream: *mut FILE) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700114 pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700115 pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
116 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
117 link_name = "fputs$UNIX2003")]
118 pub fn fputs(s: *const c_char, stream: *mut FILE)-> c_int;
119 pub fn puts(s: *const c_char) -> c_int;
120 pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
121 pub fn fread(ptr: *mut c_void,
122 size: size_t,
123 nobj: size_t,
124 stream: *mut FILE)
125 -> size_t;
126 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
127 link_name = "fwrite$UNIX2003")]
128 pub fn fwrite(ptr: *const c_void,
129 size: size_t,
130 nobj: size_t,
131 stream: *mut FILE)
132 -> size_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700133 pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700134 pub fn ftell(stream: *mut FILE) -> c_long;
135 pub fn rewind(stream: *mut FILE);
136 pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
137 pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
138 pub fn feof(stream: *mut FILE) -> c_int;
139 pub fn ferror(stream: *mut FILE) -> c_int;
140 pub fn perror(s: *const c_char);
Alex Crichton5d6cf052015-09-11 14:52:34 -0700141 pub fn atoi(s: *const c_char) -> c_int;
142 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
143 link_name = "strtod$UNIX2003")]
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700144 pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700145 pub fn strtol(s: *const c_char,
146 endp: *mut *mut c_char, base: c_int) -> c_long;
147 pub fn strtoul(s: *const c_char, endp: *mut *mut c_char,
148 base: c_int) -> c_ulong;
149 pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
150 pub fn malloc(size: size_t) -> *mut c_void;
151 pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
152 pub fn free(p: *mut c_void);
153 pub fn exit(status: c_int) -> !;
154 pub fn _exit(status: c_int) -> !;
155 pub fn atexit(cb: extern fn()) -> c_int;
156 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
157 link_name = "system$UNIX2003")]
158 pub fn system(s: *const c_char) -> c_int;
159 pub fn getenv(s: *const c_char) -> *mut c_char;
Alex Crichtondafaca92015-09-09 21:50:47 -0700160
Alex Crichton5d6cf052015-09-11 14:52:34 -0700161 pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
162 pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t)
163 -> *mut c_char;
164 pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
165 pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
166 pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
167 pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
168 pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
169 pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
170 pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
171 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
172 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
173 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
174 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
175 pub fn strlen(cs: *const c_char) -> size_t;
176 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
177 link_name = "strerror$UNIX2003")]
178 pub fn strerror(n: c_int) -> *mut c_char;
179 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
180 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
181 pub fn wcslen(buf: *const wchar_t) -> size_t;
Alex Crichtondafaca92015-09-09 21:50:47 -0700182
Alex Crichton5d6cf052015-09-11 14:52:34 -0700183 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
184 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
Alex Crichtondafaca92015-09-09 21:50:47 -0700185}
Alex Crichtond3d77922015-09-11 17:03:39 -0700186
187// These are all inline functions on android
188#[cfg(not(target_os = "android"))]
189extern {
190 pub fn abs(i: c_int) -> c_int;
191 pub fn atof(s: *const c_char) -> c_double;
192 pub fn labs(i: c_long) -> c_long;
193 pub fn rand() -> c_int;
194 pub fn srand(seed: c_uint);
195}
Alex Crichton50a42e22015-09-15 14:27:15 -0700196
197cfg_if! {
198 if #[cfg(windows)] {
199 mod windows;
200 pub use windows::*;
201 } else {
202 mod unix;
203 pub use unix::*;
204 }
205}