blob: cf2ba526bd4b8dbca30c8e638032b60f4ede02f4 [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
17#![cfg_attr(all(target_os = "linux", target_arch = "x86_64"),
18 doc(html_root_url = "http://alexcrichton.com/libc/x86_64-unknown-linux-gnu"))]
Alex Crichtondafaca92015-09-09 21:50:47 -070019
Alex Crichton5d6cf052015-09-11 14:52:34 -070020#[macro_use] mod macros;
Alex Crichton24abc4f2015-09-16 23:54:56 -070021mod dox;
Alex Crichton31504842015-09-10 23:43:41 -070022
Alex Crichton5d6cf052015-09-11 14:52:34 -070023#[repr(u8)]
24pub enum c_void {
Alex Crichton9f2b1012015-09-16 23:32:21 -070025 // Two dummy variants so the #[repr] attribute can be used
26 #[doc(hidden)]
Alex Crichton5d6cf052015-09-11 14:52:34 -070027 __variant1,
Alex Crichton9f2b1012015-09-16 23:32:21 -070028 #[doc(hidden)]
Alex Crichton5d6cf052015-09-11 14:52:34 -070029 __variant2,
30}
Alex Crichtondafaca92015-09-09 21:50:47 -070031
Alex Crichton5d6cf052015-09-11 14:52:34 -070032pub type int8_t = i8;
33pub type int16_t = i16;
34pub type int32_t = i32;
35pub type int64_t = i64;
36pub type uint8_t = u8;
37pub type uint16_t = u16;
38pub type uint32_t = u32;
39pub type uint64_t = u64;
Alex Crichtondafaca92015-09-09 21:50:47 -070040
Alex Crichton5d6cf052015-09-11 14:52:34 -070041pub enum FILE {}
42pub enum fpos_t {}
43pub enum DIR {}
44pub enum dirent {}
Alex Crichtondafaca92015-09-09 21:50:47 -070045
Alex Crichton5d6cf052015-09-11 14:52:34 -070046extern {
47 pub fn isalnum(c: c_int) -> c_int;
48 pub fn isalpha(c: c_int) -> c_int;
49 pub fn iscntrl(c: c_int) -> c_int;
50 pub fn isdigit(c: c_int) -> c_int;
51 pub fn isgraph(c: c_int) -> c_int;
52 pub fn islower(c: c_int) -> c_int;
53 pub fn isprint(c: c_int) -> c_int;
54 pub fn ispunct(c: c_int) -> c_int;
55 pub fn isspace(c: c_int) -> c_int;
56 pub fn isupper(c: c_int) -> c_int;
57 pub fn isxdigit(c: c_int) -> c_int;
58 pub fn tolower(c: c_int) -> c_int;
59 pub fn toupper(c: c_int) -> c_int;
Alex Crichtondafaca92015-09-09 21:50:47 -070060
Alex Crichton5d6cf052015-09-11 14:52:34 -070061 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
62 link_name = "fopen$UNIX2003")]
63 pub fn fopen(filename: *const c_char,
64 mode: *const c_char) -> *mut FILE;
65 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
66 link_name = "freopen$UNIX2003")]
67 pub fn freopen(filename: *const c_char, mode: *const c_char,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070068 file: *mut FILE) -> *mut FILE;
Alex Crichton5d6cf052015-09-11 14:52:34 -070069 pub fn fflush(file: *mut FILE) -> c_int;
70 pub fn fclose(file: *mut FILE) -> c_int;
71 pub fn remove(filename: *const c_char) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070072 pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -070073 pub fn tmpfile() -> *mut FILE;
74 pub fn setvbuf(stream: *mut FILE,
75 buffer: *mut c_char,
76 mode: c_int,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070077 size: size_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -070078 pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
Alex Crichton5d6cf052015-09-11 14:52:34 -070079 pub fn fgetc(stream: *mut FILE) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070080 pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
Alex Crichton5d6cf052015-09-11 14:52:34 -070081 pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
82 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
83 link_name = "fputs$UNIX2003")]
84 pub fn fputs(s: *const c_char, stream: *mut FILE)-> c_int;
85 pub fn puts(s: *const c_char) -> c_int;
86 pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
87 pub fn fread(ptr: *mut c_void,
88 size: size_t,
89 nobj: size_t,
90 stream: *mut FILE)
91 -> size_t;
92 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
93 link_name = "fwrite$UNIX2003")]
94 pub fn fwrite(ptr: *const c_void,
95 size: size_t,
96 nobj: size_t,
97 stream: *mut FILE)
98 -> size_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070099 pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700100 pub fn ftell(stream: *mut FILE) -> c_long;
101 pub fn rewind(stream: *mut FILE);
102 pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
103 pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
104 pub fn feof(stream: *mut FILE) -> c_int;
105 pub fn ferror(stream: *mut FILE) -> c_int;
106 pub fn perror(s: *const c_char);
Alex Crichton5d6cf052015-09-11 14:52:34 -0700107 pub fn atoi(s: *const c_char) -> c_int;
108 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
109 link_name = "strtod$UNIX2003")]
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700110 pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700111 pub fn strtol(s: *const c_char,
112 endp: *mut *mut c_char, base: c_int) -> c_long;
113 pub fn strtoul(s: *const c_char, endp: *mut *mut c_char,
114 base: c_int) -> c_ulong;
115 pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
116 pub fn malloc(size: size_t) -> *mut c_void;
117 pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
118 pub fn free(p: *mut c_void);
119 pub fn exit(status: c_int) -> !;
120 pub fn _exit(status: c_int) -> !;
121 pub fn atexit(cb: extern fn()) -> c_int;
122 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
123 link_name = "system$UNIX2003")]
124 pub fn system(s: *const c_char) -> c_int;
125 pub fn getenv(s: *const c_char) -> *mut c_char;
Alex Crichtondafaca92015-09-09 21:50:47 -0700126
Alex Crichton5d6cf052015-09-11 14:52:34 -0700127 pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
128 pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t)
129 -> *mut c_char;
130 pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
131 pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
132 pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
133 pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
134 pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
135 pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
136 pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
137 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
138 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
139 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
140 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
141 pub fn strlen(cs: *const c_char) -> size_t;
142 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
143 link_name = "strerror$UNIX2003")]
144 pub fn strerror(n: c_int) -> *mut c_char;
145 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
146 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
147 pub fn wcslen(buf: *const wchar_t) -> size_t;
Alex Crichtondafaca92015-09-09 21:50:47 -0700148
Alex Crichton5d6cf052015-09-11 14:52:34 -0700149 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
150 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
Alex Crichtondafaca92015-09-09 21:50:47 -0700151}
Alex Crichtond3d77922015-09-11 17:03:39 -0700152
153// These are all inline functions on android
154#[cfg(not(target_os = "android"))]
155extern {
156 pub fn abs(i: c_int) -> c_int;
157 pub fn atof(s: *const c_char) -> c_double;
158 pub fn labs(i: c_long) -> c_long;
159 pub fn rand() -> c_int;
160 pub fn srand(seed: c_uint);
161}
Alex Crichton50a42e22015-09-15 14:27:15 -0700162
163cfg_if! {
164 if #[cfg(windows)] {
165 mod windows;
166 pub use windows::*;
167 } else {
168 mod unix;
169 pub use unix::*;
170 }
171}