blob: b3319475e19b9c5456a106b537a97524a14c914d [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 -070035extern {
36 pub fn isalnum(c: c_int) -> c_int;
37 pub fn isalpha(c: c_int) -> c_int;
38 pub fn iscntrl(c: c_int) -> c_int;
39 pub fn isdigit(c: c_int) -> c_int;
40 pub fn isgraph(c: c_int) -> c_int;
41 pub fn islower(c: c_int) -> c_int;
42 pub fn isprint(c: c_int) -> c_int;
43 pub fn ispunct(c: c_int) -> c_int;
44 pub fn isspace(c: c_int) -> c_int;
45 pub fn isupper(c: c_int) -> c_int;
46 pub fn isxdigit(c: c_int) -> c_int;
47 pub fn tolower(c: c_int) -> c_int;
48 pub fn toupper(c: c_int) -> c_int;
Alex Crichtondafaca92015-09-09 21:50:47 -070049
Alex Crichton5d6cf052015-09-11 14:52:34 -070050 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
51 link_name = "fopen$UNIX2003")]
52 pub fn fopen(filename: *const c_char,
53 mode: *const c_char) -> *mut FILE;
54 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
55 link_name = "freopen$UNIX2003")]
56 pub fn freopen(filename: *const c_char, mode: *const c_char,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070057 file: *mut FILE) -> *mut FILE;
Alex Crichton5d6cf052015-09-11 14:52:34 -070058 pub fn fflush(file: *mut FILE) -> c_int;
59 pub fn fclose(file: *mut FILE) -> c_int;
60 pub fn remove(filename: *const c_char) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070061 pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -070062 pub fn tmpfile() -> *mut FILE;
63 pub fn setvbuf(stream: *mut FILE,
64 buffer: *mut c_char,
65 mode: c_int,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070066 size: size_t) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -070067 pub fn setbuf(stream: *mut FILE, buf: *mut c_char);
Alex Crichton5d6cf052015-09-11 14:52:34 -070068 pub fn fgetc(stream: *mut FILE) -> c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070069 pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char;
Alex Crichton5d6cf052015-09-11 14:52:34 -070070 pub fn fputc(c: c_int, stream: *mut FILE) -> c_int;
71 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
72 link_name = "fputs$UNIX2003")]
73 pub fn fputs(s: *const c_char, stream: *mut FILE)-> c_int;
74 pub fn puts(s: *const c_char) -> c_int;
75 pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int;
76 pub fn fread(ptr: *mut c_void,
77 size: size_t,
78 nobj: size_t,
79 stream: *mut FILE)
80 -> size_t;
81 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
82 link_name = "fwrite$UNIX2003")]
83 pub fn fwrite(ptr: *const c_void,
84 size: size_t,
85 nobj: size_t,
86 stream: *mut FILE)
87 -> size_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070088 pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int;
Alex Crichton5d6cf052015-09-11 14:52:34 -070089 pub fn ftell(stream: *mut FILE) -> c_long;
90 pub fn rewind(stream: *mut FILE);
91 pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int;
92 pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int;
93 pub fn feof(stream: *mut FILE) -> c_int;
94 pub fn ferror(stream: *mut FILE) -> c_int;
95 pub fn perror(s: *const c_char);
Alex Crichton5d6cf052015-09-11 14:52:34 -070096 pub fn atoi(s: *const c_char) -> c_int;
97 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
98 link_name = "strtod$UNIX2003")]
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070099 pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double;
Alex Crichton5d6cf052015-09-11 14:52:34 -0700100 pub fn strtol(s: *const c_char,
101 endp: *mut *mut c_char, base: c_int) -> c_long;
102 pub fn strtoul(s: *const c_char, endp: *mut *mut c_char,
103 base: c_int) -> c_ulong;
104 pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void;
105 pub fn malloc(size: size_t) -> *mut c_void;
106 pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
107 pub fn free(p: *mut c_void);
108 pub fn exit(status: c_int) -> !;
109 pub fn _exit(status: c_int) -> !;
110 pub fn atexit(cb: extern fn()) -> c_int;
111 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
112 link_name = "system$UNIX2003")]
113 pub fn system(s: *const c_char) -> c_int;
114 pub fn getenv(s: *const c_char) -> *mut c_char;
Alex Crichtondafaca92015-09-09 21:50:47 -0700115
Alex Crichton5d6cf052015-09-11 14:52:34 -0700116 pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char;
117 pub fn strncpy(dst: *mut c_char, src: *const c_char, n: size_t)
118 -> *mut c_char;
119 pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char;
120 pub fn strncat(s: *mut c_char, ct: *const c_char, n: size_t) -> *mut c_char;
121 pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int;
122 pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int;
123 pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int;
124 pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char;
125 pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char;
126 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t;
127 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t;
128 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char;
129 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char;
130 pub fn strlen(cs: *const c_char) -> size_t;
131 #[cfg_attr(all(target_os = "macos", target_arch = "x86"),
132 link_name = "strerror$UNIX2003")]
133 pub fn strerror(n: c_int) -> *mut c_char;
134 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char;
135 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t;
136 pub fn wcslen(buf: *const wchar_t) -> size_t;
Alex Crichtondafaca92015-09-09 21:50:47 -0700137
Alex Crichton5d6cf052015-09-11 14:52:34 -0700138 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int;
139 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void;
Alex Crichtondafaca92015-09-09 21:50:47 -0700140}
Alex Crichtond3d77922015-09-11 17:03:39 -0700141
142// These are all inline functions on android
143#[cfg(not(target_os = "android"))]
144extern {
145 pub fn abs(i: c_int) -> c_int;
146 pub fn atof(s: *const c_char) -> c_double;
147 pub fn labs(i: c_long) -> c_long;
148 pub fn rand() -> c_int;
149 pub fn srand(seed: c_uint);
150}
Alex Crichton50a42e22015-09-15 14:27:15 -0700151
152cfg_if! {
153 if #[cfg(windows)] {
154 mod windows;
155 pub use windows::*;
156 } else {
157 mod unix;
158 pub use unix::*;
159 }
160}