Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 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 | |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 11 | #![allow(bad_style, raw_pointer_derive)] |
| 12 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 13 | #[macro_use] mod macros; |
Alex Crichton | 3150484 | 2015-09-10 23:43:41 -0700 | [diff] [blame] | 14 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 15 | #[repr(u8)] |
| 16 | pub enum c_void { |
| 17 | __variant1, |
| 18 | __variant2, |
| 19 | } |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 20 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 21 | pub type int8_t = i8; |
| 22 | pub type int16_t = i16; |
| 23 | pub type int32_t = i32; |
| 24 | pub type int64_t = i64; |
| 25 | pub type uint8_t = u8; |
| 26 | pub type uint16_t = u16; |
| 27 | pub type uint32_t = u32; |
| 28 | pub type uint64_t = u64; |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 29 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 30 | pub enum FILE {} |
| 31 | pub enum fpos_t {} |
| 32 | pub enum DIR {} |
| 33 | pub enum dirent {} |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 34 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 35 | cfg_if! { |
| 36 | if #[cfg(any(target_os = "macos", target_os = "ios"))] { |
| 37 | mod apple; |
| 38 | pub use apple::*; |
| 39 | } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd", |
| 40 | target_os = "dragonfly"))] { |
| 41 | mod openbsdlike; |
| 42 | pub use openbsdlike::*; |
| 43 | } else if #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] { |
| 44 | mod freebsdlike; |
| 45 | pub use freebsdlike::*; |
| 46 | } else if #[cfg(any(target_os = "android", target_os = "linux"))] { |
| 47 | mod linuxlike; |
| 48 | pub use linuxlike::*; |
| 49 | } else if #[cfg(windows)] { |
| 50 | mod windows; |
| 51 | pub use windows::*; |
| 52 | } else { |
| 53 | // ... |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 57 | #[cfg(unix)] mod unix; |
| 58 | #[cfg(unix)] pub use unix::*; |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 59 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 60 | extern { |
| 61 | pub fn isalnum(c: c_int) -> c_int; |
| 62 | pub fn isalpha(c: c_int) -> c_int; |
| 63 | pub fn iscntrl(c: c_int) -> c_int; |
| 64 | pub fn isdigit(c: c_int) -> c_int; |
| 65 | pub fn isgraph(c: c_int) -> c_int; |
| 66 | pub fn islower(c: c_int) -> c_int; |
| 67 | pub fn isprint(c: c_int) -> c_int; |
| 68 | pub fn ispunct(c: c_int) -> c_int; |
| 69 | pub fn isspace(c: c_int) -> c_int; |
| 70 | pub fn isupper(c: c_int) -> c_int; |
| 71 | pub fn isxdigit(c: c_int) -> c_int; |
| 72 | pub fn tolower(c: c_int) -> c_int; |
| 73 | pub fn toupper(c: c_int) -> c_int; |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 74 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 75 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 76 | link_name = "fopen$UNIX2003")] |
| 77 | pub fn fopen(filename: *const c_char, |
| 78 | mode: *const c_char) -> *mut FILE; |
| 79 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 80 | link_name = "freopen$UNIX2003")] |
| 81 | pub fn freopen(filename: *const c_char, mode: *const c_char, |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 82 | file: *mut FILE) -> *mut FILE; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 83 | pub fn fflush(file: *mut FILE) -> c_int; |
| 84 | pub fn fclose(file: *mut FILE) -> c_int; |
| 85 | pub fn remove(filename: *const c_char) -> c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 86 | pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 87 | pub fn tmpfile() -> *mut FILE; |
| 88 | pub fn setvbuf(stream: *mut FILE, |
| 89 | buffer: *mut c_char, |
| 90 | mode: c_int, |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 91 | size: size_t) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 92 | pub fn setbuf(stream: *mut FILE, buf: *mut c_char); |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 93 | pub fn fgetc(stream: *mut FILE) -> c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 94 | pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 95 | pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; |
| 96 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 97 | link_name = "fputs$UNIX2003")] |
| 98 | pub fn fputs(s: *const c_char, stream: *mut FILE)-> c_int; |
| 99 | pub fn puts(s: *const c_char) -> c_int; |
| 100 | pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; |
| 101 | pub fn fread(ptr: *mut c_void, |
| 102 | size: size_t, |
| 103 | nobj: size_t, |
| 104 | stream: *mut FILE) |
| 105 | -> size_t; |
| 106 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 107 | link_name = "fwrite$UNIX2003")] |
| 108 | pub fn fwrite(ptr: *const c_void, |
| 109 | size: size_t, |
| 110 | nobj: size_t, |
| 111 | stream: *mut FILE) |
| 112 | -> size_t; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 113 | pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 114 | pub fn ftell(stream: *mut FILE) -> c_long; |
| 115 | pub fn rewind(stream: *mut FILE); |
| 116 | pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; |
| 117 | pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; |
| 118 | pub fn feof(stream: *mut FILE) -> c_int; |
| 119 | pub fn ferror(stream: *mut FILE) -> c_int; |
| 120 | pub fn perror(s: *const c_char); |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 121 | pub fn atoi(s: *const c_char) -> c_int; |
| 122 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 123 | link_name = "strtod$UNIX2003")] |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 124 | pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 125 | pub fn strtol(s: *const c_char, |
| 126 | endp: *mut *mut c_char, base: c_int) -> c_long; |
| 127 | pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, |
| 128 | base: c_int) -> c_ulong; |
| 129 | pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; |
| 130 | pub fn malloc(size: size_t) -> *mut c_void; |
| 131 | pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; |
| 132 | pub fn free(p: *mut c_void); |
| 133 | pub fn exit(status: c_int) -> !; |
| 134 | pub fn _exit(status: c_int) -> !; |
| 135 | pub fn atexit(cb: extern fn()) -> c_int; |
| 136 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 137 | link_name = "system$UNIX2003")] |
| 138 | pub fn system(s: *const c_char) -> c_int; |
| 139 | pub fn getenv(s: *const c_char) -> *mut c_char; |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 140 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 141 | pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; |
| 142 | pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t) |
| 143 | -> *mut c_char; |
| 144 | pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; |
| 145 | pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char; |
| 146 | pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; |
| 147 | pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; |
| 148 | pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; |
| 149 | pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; |
| 150 | pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; |
| 151 | pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; |
| 152 | pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; |
| 153 | pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; |
| 154 | pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; |
| 155 | pub fn strlen(cs: *const c_char) -> size_t; |
| 156 | #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 157 | link_name = "strerror$UNIX2003")] |
| 158 | pub fn strerror(n: c_int) -> *mut c_char; |
| 159 | pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; |
| 160 | pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; |
| 161 | pub fn wcslen(buf: *const wchar_t) -> size_t; |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 162 | |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 163 | pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; |
| 164 | pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; |
Alex Crichton | dafaca9 | 2015-09-09 21:50:47 -0700 | [diff] [blame] | 165 | } |
Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame^] | 166 | |
| 167 | // These are all inline functions on android |
| 168 | #[cfg(not(target_os = "android"))] |
| 169 | extern { |
| 170 | pub fn abs(i: c_int) -> c_int; |
| 171 | pub fn atof(s: *const c_char) -> c_double; |
| 172 | pub fn labs(i: c_long) -> c_long; |
| 173 | pub fn rand() -> c_int; |
| 174 | pub fn srand(seed: c_uint); |
| 175 | } |