blob: 910b9483b3cfcc21068ab9ebcf3c3853ececf532 [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)]
12
Alex Crichton5d6cf052015-09-11 14:52:34 -070013#[macro_use] mod macros;
Alex Crichton31504842015-09-10 23:43:41 -070014
Alex Crichton5d6cf052015-09-11 14:52:34 -070015#[repr(u8)]
16pub enum c_void {
17 __variant1,
18 __variant2,
19}
Alex Crichtondafaca92015-09-09 21:50:47 -070020
Alex Crichton5d6cf052015-09-11 14:52:34 -070021pub type int8_t = i8;
22pub type int16_t = i16;
23pub type int32_t = i32;
24pub type int64_t = i64;
25pub type uint8_t = u8;
26pub type uint16_t = u16;
27pub type uint32_t = u32;
28pub type uint64_t = u64;
Alex Crichtondafaca92015-09-09 21:50:47 -070029
Alex Crichton5d6cf052015-09-11 14:52:34 -070030pub enum FILE {}
31pub enum fpos_t {}
32pub enum DIR {}
33pub enum dirent {}
Alex Crichtondafaca92015-09-09 21:50:47 -070034
Alex Crichton5d6cf052015-09-11 14:52:34 -070035cfg_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 Crichtondafaca92015-09-09 21:50:47 -070054 }
55}
56
Alex Crichton5d6cf052015-09-11 14:52:34 -070057#[cfg(unix)] mod unix;
58#[cfg(unix)] pub use unix::*;
Alex Crichtondafaca92015-09-09 21:50:47 -070059
Alex Crichton5d6cf052015-09-11 14:52:34 -070060cfg_if! {
61 if #[cfg(any(target_os = "macos",
62 target_os = "ios",
63 target_os = "freebsd",
64 target_os = "dragonfly",
65 target_os = "bitrig",
66 target_os = "netbsd",
67 target_os = "openbsd"))] {
Alex Crichton084f9ea2015-09-11 15:11:59 -070068 extern {
69 pub fn sysctl(name: *mut c_int,
70 namelen: c_uint,
71 oldp: *mut c_void,
72 oldlenp: *mut size_t,
73 newp: *mut c_void,
74 newlen: size_t)
75 -> c_int;
76 pub fn mincore(addr: *const c_void, len: size_t, vec: *mut c_char)
77 -> c_int;
78 pub fn sysctlbyname(name: *const c_char,
79 oldp: *mut c_void,
80 oldlenp: *mut size_t,
81 newp: *mut c_void,
82 newlen: size_t)
83 -> c_int;
84 pub fn sysctlnametomib(name: *const c_char,
85 mibp: *mut c_int,
86 sizep: *mut size_t)
87 -> c_int;
88 }
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070089 } else if #[cfg(unix)] {
Alex Crichton084f9ea2015-09-11 15:11:59 -070090 extern {
91 pub fn sysctl(name: *mut c_int,
92 namelen: c_int,
93 oldp: *mut c_void,
94 oldlenp: *mut size_t,
95 newp: *mut c_void,
96 newlen: size_t)
97 -> c_int;
98 pub fn mincore(addr: *mut c_void, len: size_t, vec: *mut c_uchar)
99 -> c_int;
100 }
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700101 } else {
102 // ...
Alex Crichtondafaca92015-09-09 21:50:47 -0700103 }
104}
105
Alex Crichton5d6cf052015-09-11 14:52:34 -0700106extern {
107 pub fn isalnum(c: c_int) -> c_int;
108 pub fn isalpha(c: c_int) -> c_int;
109 pub fn iscntrl(c: c_int) -> c_int;
110 pub fn isdigit(c: c_int) -> c_int;
111 pub fn isgraph(c: c_int) -> c_int;
112 pub fn islower(c: c_int) -> c_int;
113 pub fn isprint(c: c_int) -> c_int;
114 pub fn ispunct(c: c_int) -> c_int;
115 pub fn isspace(c: c_int) -> c_int;
116 pub fn isupper(c: c_int) -> c_int;
117 pub fn isxdigit(c: c_int) -> c_int;
118 pub fn tolower(c: c_int) -> c_int;
119 pub fn toupper(c: c_int) -> c_int;
Alex Crichtondafaca92015-09-09 21:50:47 -0700120
Alex Crichton5d6cf052015-09-11 14:52:34 -0700121 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
122 link_name = "fopen$UNIX2003")]
123 pub fn fopen(filename: *const c_char,
124 mode: *const c_char) -> *mut FILE;
125 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
126 link_name = "freopen$UNIX2003")]
127 pub fn freopen(filename: *const c_char, mode: *const c_char,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700128 file: *mut FILE) -> *mut FILE;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700129 pub fn fflush(file: *mut FILE) -> c_int;
130 pub fn fclose(file: *mut FILE) -> c_int;
131 pub fn remove(filename: *const c_char) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700132 pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700133 pub fn tmpfile() -> *mut FILE;
134 pub fn setvbuf(stream: *mut FILE,
135 buffer: *mut c_char,
136 mode: c_int,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700137 size: size_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700138 pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
Alex Crichton5d6cf052015-09-11 14:52:34 -0700139 pub fn fgetc(stream: *mut FILE) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700140 pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700141 pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
142 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
143 link_name = "fputs$UNIX2003")]
144 pub fn fputs(s: *const c_char, stream: *mut FILE)-> c_int;
145 pub fn puts(s: *const c_char) -> c_int;
146 pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
147 pub fn fread(ptr: *mut c_void,
148 size: size_t,
149 nobj: size_t,
150 stream: *mut FILE)
151 -> size_t;
152 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
153 link_name = "fwrite$UNIX2003")]
154 pub fn fwrite(ptr: *const c_void,
155 size: size_t,
156 nobj: size_t,
157 stream: *mut FILE)
158 -> size_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700159 pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700160 pub fn ftell(stream: *mut FILE) -> c_long;
161 pub fn rewind(stream: *mut FILE);
162 pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
163 pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
164 pub fn feof(stream: *mut FILE) -> c_int;
165 pub fn ferror(stream: *mut FILE) -> c_int;
166 pub fn perror(s: *const c_char);
167 pub fn abs(i: c_int) -> c_int;
168 pub fn labs(i: c_long) -> c_long;
169 pub fn atof(s: *const c_char) -> c_double;
170 pub fn atoi(s: *const c_char) -> c_int;
171 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
172 link_name = "strtod$UNIX2003")]
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700173 pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700174 pub fn strtol(s: *const c_char,
175 endp: *mut *mut c_char, base: c_int) -> c_long;
176 pub fn strtoul(s: *const c_char, endp: *mut *mut c_char,
177 base: c_int) -> c_ulong;
178 pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
179 pub fn malloc(size: size_t) -> *mut c_void;
180 pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
181 pub fn free(p: *mut c_void);
182 pub fn exit(status: c_int) -> !;
183 pub fn _exit(status: c_int) -> !;
184 pub fn atexit(cb: extern fn()) -> c_int;
185 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
186 link_name = "system$UNIX2003")]
187 pub fn system(s: *const c_char) -> c_int;
188 pub fn getenv(s: *const c_char) -> *mut c_char;
189 pub fn rand() -> c_int;
190 pub fn srand(seed: c_uint);
Alex Crichtondafaca92015-09-09 21:50:47 -0700191
Alex Crichton5d6cf052015-09-11 14:52:34 -0700192 pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
193 pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t)
194 -> *mut c_char;
195 pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
196 pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
197 pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
198 pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
199 pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
200 pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
201 pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
202 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
203 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
204 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
205 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
206 pub fn strlen(cs: *const c_char) -> size_t;
207 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
208 link_name = "strerror$UNIX2003")]
209 pub fn strerror(n: c_int) -> *mut c_char;
210 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
211 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
212 pub fn wcslen(buf: *const wchar_t) -> size_t;
Alex Crichtondafaca92015-09-09 21:50:47 -0700213
Alex Crichton5d6cf052015-09-11 14:52:34 -0700214 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
215 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
Alex Crichtondafaca92015-09-09 21:50:47 -0700216}