]> git.proxmox.com Git - rustc.git/blob - src/liblibc/src/lib.rs
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / liblibc / src / lib.rs
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 ))]
36 #![cfg_attr(all(target_os = "linux", target_env = "musl"), doc(
37 html_root_url = "https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl"
38 ))]
39 #![cfg_attr(all(target_os = "macos", target_arch = "x86_64"), doc(
40 html_root_url = "https://doc.rust-lang.org/libc/x86_64-apple-darwin"
41 ))]
42 #![cfg_attr(all(target_os = "macos", target_arch = "x86"), doc(
43 html_root_url = "https://doc.rust-lang.org/libc/i686-apple-darwin"
44 ))]
45 #![cfg_attr(all(windows, target_arch = "x86_64", target_env = "gnu"), doc(
46 html_root_url = "https://doc.rust-lang.org/libc/x86_64-pc-windows-gnu"
47 ))]
48 #![cfg_attr(all(windows, target_arch = "x86", target_env = "gnu"), doc(
49 html_root_url = "https://doc.rust-lang.org/libc/i686-pc-windows-gnu"
50 ))]
51 #![cfg_attr(all(windows, target_arch = "x86_64", target_env = "msvc"), doc(
52 html_root_url = "https://doc.rust-lang.org/libc/x86_64-pc-windows-msvc"
53 ))]
54 #![cfg_attr(all(windows, target_arch = "x86", target_env = "msvc"), doc(
55 html_root_url = "https://doc.rust-lang.org/libc/i686-pc-windows-msvc"
56 ))]
57 #![cfg_attr(all(target_os = "android"), doc(
58 html_root_url = "https://doc.rust-lang.org/libc/arm-linux-androideabi"
59 ))]
60
61 // Attributes needed when building as part of the standard library
62 #![cfg_attr(stdbuild, feature(no_std, core, core_slice_ext, staged_api, custom_attribute))]
63 #![cfg_attr(stdbuild, no_std)]
64 #![cfg_attr(stdbuild, staged_api)]
65 #![cfg_attr(stdbuild, allow(warnings))]
66 #![cfg_attr(stdbuild, unstable(feature = "libc",
67 reason = "use `libc` from crates.io",
68 issue = "27783"))]
69
70 #[cfg(all(not(stdbuild), not(dox)))]
71 extern crate std as core;
72
73 #[macro_use] mod macros;
74 mod dox;
75
76 // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
77 // more optimization opportunities around it recognizing things like
78 // malloc/free.
79 #[repr(u8)]
80 pub enum c_void {
81 // Two dummy variants so the #[repr] attribute can be used.
82 #[doc(hidden)]
83 __variant1,
84 #[doc(hidden)]
85 __variant2,
86 }
87
88 pub type int8_t = i8;
89 pub type int16_t = i16;
90 pub type int32_t = i32;
91 pub type int64_t = i64;
92 pub type uint8_t = u8;
93 pub type uint16_t = u16;
94 pub type uint32_t = u32;
95 pub type uint64_t = u64;
96
97 pub type c_schar = i8;
98 pub type c_uchar = u8;
99 pub type c_short = i16;
100 pub type c_ushort = u16;
101 pub type c_int = i32;
102 pub type c_uint = u32;
103 pub type c_float = f32;
104 pub type c_double = f64;
105 pub type c_longlong = i64;
106 pub type c_ulonglong = u64;
107 pub type intmax_t = i64;
108 pub type uintmax_t = u64;
109
110 pub type size_t = usize;
111 pub type ptrdiff_t = isize;
112 pub type intptr_t = isize;
113 pub type uintptr_t = usize;
114 pub type ssize_t = isize;
115
116 pub enum FILE {}
117 pub enum fpos_t {} // TODO: fill this out with a struct
118
119 extern {
120 pub fn isalnum(c: c_int) -> c_int;
121 pub fn isalpha(c: c_int) -> c_int;
122 pub fn iscntrl(c: c_int) -> c_int;
123 pub fn isdigit(c: c_int) -> c_int;
124 pub fn isgraph(c: c_int) -> c_int;
125 pub fn islower(c: c_int) -> c_int;
126 pub fn isprint(c: c_int) -> c_int;
127 pub fn ispunct(c: c_int) -> c_int;
128 pub fn isspace(c: c_int) -> c_int;
129 pub fn isupper(c: c_int) -> c_int;
130 pub fn isxdigit(c: c_int) -> c_int;
131 pub fn tolower(c: c_int) -> c_int;
132 pub fn toupper(c: c_int) -> c_int;
133
134 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
135 link_name = "fopen$UNIX2003")]
136 pub fn fopen(filename: *const c_char,
137 mode: *const c_char) -> *mut FILE;
138 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
139 link_name = "freopen$UNIX2003")]
140 pub fn freopen(filename: *const c_char, mode: *const c_char,
141 file: *mut FILE) -> *mut FILE;
142 pub fn fflush(file: *mut FILE) -> c_int;
143 pub fn fclose(file: *mut FILE) -> c_int;
144 pub fn remove(filename: *const c_char) -> c_int;
145 pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
146 pub fn tmpfile() -> *mut FILE;
147 pub fn setvbuf(stream: *mut FILE,
148 buffer: *mut c_char,
149 mode: c_int,
150 size: size_t) -> c_int;
151 pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
152 pub fn fgetc(stream: *mut FILE) -> c_int;
153 pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
154 pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
155 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
156 link_name = "fputs$UNIX2003")]
157 pub fn fputs(s: *const c_char, stream: *mut FILE)-> c_int;
158 pub fn puts(s: *const c_char) -> c_int;
159 pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
160 pub fn fread(ptr: *mut c_void,
161 size: size_t,
162 nobj: size_t,
163 stream: *mut FILE)
164 -> size_t;
165 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
166 link_name = "fwrite$UNIX2003")]
167 pub fn fwrite(ptr: *const c_void,
168 size: size_t,
169 nobj: size_t,
170 stream: *mut FILE)
171 -> size_t;
172 pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
173 pub fn ftell(stream: *mut FILE) -> c_long;
174 pub fn rewind(stream: *mut FILE);
175 pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
176 pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
177 pub fn feof(stream: *mut FILE) -> c_int;
178 pub fn ferror(stream: *mut FILE) -> c_int;
179 pub fn perror(s: *const c_char);
180 pub fn atoi(s: *const c_char) -> c_int;
181 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
182 link_name = "strtod$UNIX2003")]
183 pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
184 pub fn strtol(s: *const c_char,
185 endp: *mut *mut c_char, base: c_int) -> c_long;
186 pub fn strtoul(s: *const c_char, endp: *mut *mut c_char,
187 base: c_int) -> c_ulong;
188 pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
189 pub fn malloc(size: size_t) -> *mut c_void;
190 pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
191 pub fn free(p: *mut c_void);
192 pub fn exit(status: c_int) -> !;
193 pub fn _exit(status: c_int) -> !;
194 pub fn atexit(cb: extern fn()) -> c_int;
195 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
196 link_name = "system$UNIX2003")]
197 pub fn system(s: *const c_char) -> c_int;
198 pub fn getenv(s: *const c_char) -> *mut c_char;
199
200 pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
201 pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t)
202 -> *mut c_char;
203 pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
204 pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
205 pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
206 pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
207 pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
208 pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
209 pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
210 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
211 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
212 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
213 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
214 pub fn strlen(cs: *const c_char) -> size_t;
215 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
216 link_name = "strerror$UNIX2003")]
217 pub fn strerror(n: c_int) -> *mut c_char;
218 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
219 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
220 pub fn wcslen(buf: *const wchar_t) -> size_t;
221
222 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
223 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
224 }
225
226 // These are all inline functions on android, so they end up just being entirely
227 // missing on that platform.
228 #[cfg(not(target_os = "android"))]
229 extern {
230 pub fn abs(i: c_int) -> c_int;
231 pub fn atof(s: *const c_char) -> c_double;
232 pub fn labs(i: c_long) -> c_long;
233 pub fn rand() -> c_int;
234 pub fn srand(seed: c_uint);
235 }
236
237 cfg_if! {
238 if #[cfg(windows)] {
239 mod windows;
240 pub use windows::*;
241 } else {
242 mod unix;
243 pub use unix::*;
244 }
245 }