|
| 1 | +mod dox; |
| 2 | + |
| 3 | +cfg_if! { |
| 4 | + if #[cfg(core_cvoid)] { |
| 5 | + pub use core::ffi::c_void; |
| 6 | + } else { |
| 7 | + // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable |
| 8 | + // more optimization opportunities around it recognizing things like |
| 9 | + // malloc/free. |
| 10 | + #[repr(u8)] |
| 11 | + pub enum c_void { |
| 12 | + // Two dummy variants so the #[repr] attribute can be used. |
| 13 | + #[doc(hidden)] |
| 14 | + __variant1, |
| 15 | + #[doc(hidden)] |
| 16 | + __variant2, |
| 17 | + } |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 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; |
| 29 | + |
| 30 | +pub type c_schar = i8; |
| 31 | +pub type c_uchar = u8; |
| 32 | +pub type c_short = i16; |
| 33 | +pub type c_ushort = u16; |
| 34 | +pub type c_int = i32; |
| 35 | +pub type c_uint = u32; |
| 36 | +pub type c_float = f32; |
| 37 | +pub type c_double = f64; |
| 38 | +pub type c_longlong = i64; |
| 39 | +pub type c_ulonglong = u64; |
| 40 | +pub type intmax_t = i64; |
| 41 | +pub type uintmax_t = u64; |
| 42 | + |
| 43 | +pub type size_t = usize; |
| 44 | +pub type ptrdiff_t = isize; |
| 45 | +pub type intptr_t = isize; |
| 46 | +pub type uintptr_t = usize; |
| 47 | +pub type ssize_t = isize; |
| 48 | + |
| 49 | +pub enum FILE {} |
| 50 | +pub enum fpos_t {} // TODO: fill this out with a struct |
| 51 | + |
| 52 | +pub const INT_MIN: c_int = -2147483648; |
| 53 | +pub const INT_MAX: c_int = 2147483647; |
| 54 | + |
| 55 | +extern { |
| 56 | + pub fn isalnum(c: c_int) -> c_int; |
| 57 | + pub fn isalpha(c: c_int) -> c_int; |
| 58 | + pub fn iscntrl(c: c_int) -> c_int; |
| 59 | + pub fn isdigit(c: c_int) -> c_int; |
| 60 | + pub fn isgraph(c: c_int) -> c_int; |
| 61 | + pub fn islower(c: c_int) -> c_int; |
| 62 | + pub fn isprint(c: c_int) -> c_int; |
| 63 | + pub fn ispunct(c: c_int) -> c_int; |
| 64 | + pub fn isspace(c: c_int) -> c_int; |
| 65 | + pub fn isupper(c: c_int) -> c_int; |
| 66 | + pub fn isxdigit(c: c_int) -> c_int; |
| 67 | + pub fn tolower(c: c_int) -> c_int; |
| 68 | + pub fn toupper(c: c_int) -> c_int; |
| 69 | + |
| 70 | + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 71 | + link_name = "fopen$UNIX2003")] |
| 72 | + pub fn fopen(filename: *const c_char, |
| 73 | + mode: *const c_char) -> *mut FILE; |
| 74 | + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 75 | + link_name = "freopen$UNIX2003")] |
| 76 | + pub fn freopen(filename: *const c_char, mode: *const c_char, |
| 77 | + file: *mut FILE) -> *mut FILE; |
| 78 | + pub fn fflush(file: *mut FILE) -> c_int; |
| 79 | + pub fn fclose(file: *mut FILE) -> c_int; |
| 80 | + pub fn remove(filename: *const c_char) -> c_int; |
| 81 | + pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; |
| 82 | + pub fn tmpfile() -> *mut FILE; |
| 83 | + pub fn setvbuf(stream: *mut FILE, |
| 84 | + buffer: *mut c_char, |
| 85 | + mode: c_int, |
| 86 | + size: size_t) -> c_int; |
| 87 | + pub fn setbuf(stream: *mut FILE, buf: *mut c_char); |
| 88 | + pub fn getchar() -> c_int; |
| 89 | + pub fn putchar(c: c_int) -> c_int; |
| 90 | + pub fn fgetc(stream: *mut FILE) -> c_int; |
| 91 | + pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; |
| 92 | + pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; |
| 93 | + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 94 | + link_name = "fputs$UNIX2003")] |
| 95 | + pub fn fputs(s: *const c_char, stream: *mut FILE)-> c_int; |
| 96 | + pub fn puts(s: *const c_char) -> c_int; |
| 97 | + pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; |
| 98 | + pub fn fread(ptr: *mut c_void, |
| 99 | + size: size_t, |
| 100 | + nobj: size_t, |
| 101 | + stream: *mut FILE) |
| 102 | + -> size_t; |
| 103 | + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 104 | + link_name = "fwrite$UNIX2003")] |
| 105 | + pub fn fwrite(ptr: *const c_void, |
| 106 | + size: size_t, |
| 107 | + nobj: size_t, |
| 108 | + stream: *mut FILE) |
| 109 | + -> size_t; |
| 110 | + pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; |
| 111 | + pub fn ftell(stream: *mut FILE) -> c_long; |
| 112 | + pub fn rewind(stream: *mut FILE); |
| 113 | + #[cfg_attr(target_os = "netbsd", link_name = "__fgetpos50")] |
| 114 | + pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; |
| 115 | + #[cfg_attr(target_os = "netbsd", link_name = "__fsetpos50")] |
| 116 | + pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; |
| 117 | + pub fn feof(stream: *mut FILE) -> c_int; |
| 118 | + pub fn ferror(stream: *mut FILE) -> c_int; |
| 119 | + pub fn perror(s: *const c_char); |
| 120 | + pub fn atoi(s: *const c_char) -> c_int; |
| 121 | + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 122 | + link_name = "strtod$UNIX2003")] |
| 123 | + pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; |
| 124 | + pub fn strtol(s: *const c_char, |
| 125 | + endp: *mut *mut c_char, base: c_int) -> c_long; |
| 126 | + pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, |
| 127 | + base: c_int) -> c_ulong; |
| 128 | + pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; |
| 129 | + pub fn malloc(size: size_t) -> *mut c_void; |
| 130 | + pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; |
| 131 | + pub fn free(p: *mut c_void); |
| 132 | + pub fn abort() -> !; |
| 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; |
| 140 | + |
| 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 strdup(cs: *const c_char) -> *mut c_char; |
| 154 | + pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; |
| 155 | + pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; |
| 156 | + pub fn strlen(cs: *const c_char) -> size_t; |
| 157 | + pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; |
| 158 | + #[cfg_attr(all(target_os = "macos", target_arch = "x86"), |
| 159 | + link_name = "strerror$UNIX2003")] |
| 160 | + pub fn strerror(n: c_int) -> *mut c_char; |
| 161 | + pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; |
| 162 | + pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; |
| 163 | + pub fn wcslen(buf: *const wchar_t) -> size_t; |
| 164 | + pub fn wcstombs(dest: *mut c_char, src: *const wchar_t, n: size_t) -> ::size_t; |
| 165 | + |
| 166 | + pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; |
| 167 | + pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; |
| 168 | + pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; |
| 169 | + pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; |
| 170 | + pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; |
| 171 | +} |
| 172 | + |
| 173 | +// These are all inline functions on android, so they end up just being entirely |
| 174 | +// missing on that platform. |
| 175 | +cfg_if! { |
| 176 | + if #[cfg(target_os = "android")] { |
| 177 | + // empty... |
| 178 | + } else { |
| 179 | + extern { |
| 180 | + pub fn abs(i: c_int) -> c_int; |
| 181 | + pub fn atof(s: *const c_char) -> c_double; |
| 182 | + pub fn labs(i: c_long) -> c_long; |
| 183 | + pub fn rand() -> c_int; |
| 184 | + pub fn srand(seed: c_uint); |
| 185 | + } |
| 186 | + } |
| 187 | +} |
| 188 | + |
| 189 | + |
| 190 | +cfg_if! { |
| 191 | + if #[cfg(windows)] { |
| 192 | + mod windows; |
| 193 | + pub use windows::*; |
| 194 | + } else if #[cfg(target_os = "redox")] { |
| 195 | + mod redox; |
| 196 | + pub use redox::*; |
| 197 | + } else if #[cfg(target_os = "cloudabi")] { |
| 198 | + mod cloudabi; |
| 199 | + pub use cloudabi::*; |
| 200 | + } else if #[cfg(target_os = "fuchsia")] { |
| 201 | + mod fuchsia; |
| 202 | + pub use fuchsia::*; |
| 203 | + } else if #[cfg(target_os = "switch")] { |
| 204 | + mod switch; |
| 205 | + pub use switch::*; |
| 206 | + } else if #[cfg(unix)] { |
| 207 | + mod unix; |
| 208 | + pub use unix::*; |
| 209 | + } else { |
| 210 | + // Unknown target_family |
| 211 | + } |
| 212 | +} |
0 commit comments