blob: e69d682d407a09b9e71a02e1dacebf9774933de1 [file] [log] [blame]
Alex Crichtond3d77922015-09-11 17:03:39 -07001//! Windows CRT definitions
2
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -07003pub type c_char = i8;
4pub type c_schar = i8;
5pub type c_uchar = u8;
6pub type c_short = i16;
7pub type c_ushort = u16;
8pub type c_int = i32;
9pub type c_uint = u32;
10pub type c_long = i32;
11pub type c_ulong = u32;
12pub type c_float = f32;
13pub type c_double = f64;
14pub type wchar_t = u16;
15pub type c_longlong = i64;
16pub type c_ulonglong = u64;
17pub type intmax_t = i64;
18pub type uintmax_t = u64;
Alex Crichton5d6cf052015-09-11 14:52:34 -070019
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070020cfg_if! {
21 if #[cfg(target_arch = "x86")] {
22 pub type intptr_t = i32;
23 pub type ptrdiff_t = i32;
24 pub type size_t = u32;
25 pub type ssize_t = i32;
26 pub type uintptr_t = u32;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070027 } else if #[cfg(target_arch = "x86_64")] {
28 pub type intptr_t = i64;
29 pub type ptrdiff_t = i64;
30 pub type size_t = u64;
31 pub type ssize_t = i64;
32 pub type uintptr_t = u64;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070033 } else {
34 // unknown arch
Alex Crichton5d6cf052015-09-11 14:52:34 -070035 }
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070036}
Alex Crichton5d6cf052015-09-11 14:52:34 -070037
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070038pub type clock_t = i32;
Alex Crichton5d6cf052015-09-11 14:52:34 -070039
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070040cfg_if! {
41 if #[cfg(all(target_arch = "x86", target_env = "gnu"))] {
42 pub type time_t = i32;
43 } else {
44 pub type time_t = i64;
45 }
46}
Alex Crichton5d6cf052015-09-11 14:52:34 -070047
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070048pub type off_t = i32;
49pub type dev_t = u32;
50pub type ino_t = u16;
51pub enum timezone {}
52pub type time64_t = i64;
Alex Crichton5d6cf052015-09-11 14:52:34 -070053
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070054s! {
55 // note this is the struct called stat64 in Windows. Not stat, nor stati64.
56 pub struct stat {
57 pub st_dev: dev_t,
58 pub st_ino: ino_t,
59 pub st_mode: u16,
60 pub st_nlink: c_short,
61 pub st_uid: c_short,
62 pub st_gid: c_short,
63 pub st_rdev: dev_t,
64 pub st_size: i64,
65 pub st_atime: time64_t,
66 pub st_mtime: time64_t,
67 pub st_ctime: time64_t,
Alex Crichton5d6cf052015-09-11 14:52:34 -070068 }
69
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070070 // note that this is called utimbuf64 in Windows
71 pub struct utimbuf {
72 pub actime: time64_t,
73 pub modtime: time64_t,
Alex Crichton5d6cf052015-09-11 14:52:34 -070074 }
75
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070076 pub struct timeval {
77 pub tv_sec: c_long,
78 pub tv_usec: c_long,
79 }
Alex Crichton5d6cf052015-09-11 14:52:34 -070080
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070081 pub struct timespec {
82 pub tv_sec: time_t,
83 pub tv_nsec: c_long,
84 }
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070085}
86
87pub const EXIT_FAILURE: c_int = 1;
88pub const EXIT_SUCCESS: c_int = 0;
89pub const RAND_MAX: c_int = 32767;
90pub const EOF: c_int = -1;
91pub const SEEK_SET: c_int = 0;
92pub const SEEK_CUR: c_int = 1;
93pub const SEEK_END: c_int = 2;
94pub const _IOFBF: c_int = 0;
95pub const _IONBF: c_int = 4;
96pub const _IOLBF: c_int = 64;
97pub const BUFSIZ: c_uint = 512;
98pub const FOPEN_MAX: c_uint = 20;
99pub const FILENAME_MAX: c_uint = 260;
100
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700101cfg_if! {
102 if #[cfg(all(target_env = "gnu"))] {
103 pub const L_tmpnam: c_uint = 14;
104 pub const TMP_MAX: c_uint = 0x7fff;
105 } else {
106 pub const L_tmpnam: c_uint = 260;
107 pub const TMP_MAX: c_uint = 0x7fff_ffff;
108 }
109}
110
111pub const O_RDONLY: c_int = 0;
112pub const O_WRONLY: c_int = 1;
113pub const O_RDWR: c_int = 2;
114pub const O_APPEND: c_int = 8;
115pub const O_CREAT: c_int = 256;
116pub const O_EXCL: c_int = 1024;
Alex Crichtonc4d4c702015-09-21 13:36:54 -0700117pub const O_TEXT: c_int = 16384;
118pub const O_BINARY: c_int = 32768;
119pub const O_NOINHERIT: c_int = 128;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700120pub const O_TRUNC: c_int = 512;
121pub const S_IFCHR: c_int = 8192;
122pub const S_IFDIR: c_int = 16384;
123pub const S_IFREG: c_int = 32768;
124pub const S_IFMT: c_int = 61440;
125pub const S_IEXEC: c_int = 64;
126pub const S_IWRITE: c_int = 128;
127pub const S_IREAD: c_int = 256;
128
Alex Crichton2c57e362015-09-15 17:30:53 -0700129#[cfg(target_env = "msvc")]
Alex Crichton2c57e362015-09-15 17:30:53 -0700130#[link(name = "msvcrt")]
131extern {}
132
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700133extern {
134 #[link_name = "_chmod"]
135 pub fn chmod(path: *const c_char, mode: c_int) -> c_int;
136 #[link_name = "_wchmod"]
137 pub fn wchmod(path: *const wchar_t, mode: c_int) -> c_int;
138 #[link_name = "_mkdir"]
139 pub fn mkdir(path: *const c_char) -> c_int;
140 #[link_name = "_wrmdir"]
141 pub fn wrmdir(path: *const wchar_t) -> c_int;
142 #[link_name = "_fstat64"]
143 pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
144 #[link_name = "_stat64"]
145 pub fn stat(path: *const c_char, buf: *mut stat) -> c_int;
146 #[link_name = "_wstat64"]
147 pub fn wstat(path: *const wchar_t, buf: *mut stat) -> c_int;
148 #[link_name = "_wutime64"]
149 pub fn wutime(file: *const wchar_t, buf: *mut utimbuf) -> c_int;
150 #[link_name = "_popen"]
151 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE;
152 #[link_name = "_pclose"]
153 pub fn pclose(stream: *mut ::FILE) -> c_int;
154 #[link_name = "_fdopen"]
155 pub fn fdopen(fd: c_int, mode: *const c_char) -> *mut ::FILE;
156 #[link_name = "_fileno"]
157 pub fn fileno(stream: *mut ::FILE) -> c_int;
158 #[link_name = "_open"]
159 pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int;
160 #[link_name = "_wopen"]
161 pub fn wopen(path: *const wchar_t, oflag: c_int, ...) -> c_int;
162 #[link_name = "_creat"]
163 pub fn creat(path: *const c_char, mode: c_int) -> c_int;
164 #[link_name = "_access"]
165 pub fn access(path: *const c_char, amode: c_int) -> c_int;
166 #[link_name = "_chdir"]
167 pub fn chdir(dir: *const c_char) -> c_int;
168 #[link_name = "_close"]
169 pub fn close(fd: c_int) -> c_int;
170 #[link_name = "_dup"]
171 pub fn dup(fd: c_int) -> c_int;
172 #[link_name = "_dup2"]
173 pub fn dup2(src: c_int, dst: c_int) -> c_int;
174 #[link_name = "_execv"]
175 pub fn execv(prog: *const c_char, argv: *const *const c_char) -> intptr_t;
176 #[link_name = "_execve"]
177 pub fn execve(prog: *const c_char, argv: *const *const c_char,
178 envp: *const *const c_char) -> c_int;
179 #[link_name = "_execvp"]
180 pub fn execvp(c: *const c_char, argv: *const *const c_char) -> c_int;
181 #[link_name = "_execvpe"]
182 pub fn execvpe(c: *const c_char, argv: *const *const c_char,
183 envp: *const *const c_char) -> c_int;
184 #[link_name = "_getcwd"]
185 pub fn getcwd(buf: *mut c_char, size: c_int) -> *mut c_char;
186 #[link_name = "_getpid"]
187 pub fn getpid() -> c_int;
188 #[link_name = "_isatty"]
189 pub fn isatty(fd: c_int) -> c_int;
190 #[link_name = "_lseek"]
191 pub fn lseek(fd: c_int, offset: c_long, origin: c_int) -> c_long;
192 #[link_name = "_pipe"]
193 pub fn pipe(fds: *mut c_int, psize: c_uint, textmode: c_int) -> c_int;
194 #[link_name = "_read"]
195 pub fn read(fd: c_int, buf: *mut ::c_void, count: c_uint) -> c_int;
196 #[link_name = "_rmdir"]
197 pub fn rmdir(path: *const c_char) -> c_int;
198 #[link_name = "_unlink"]
199 pub fn unlink(c: *const c_char) -> c_int;
200 #[link_name = "_write"]
201 pub fn write(fd: c_int, buf: *const ::c_void, count: c_uint) -> c_int;
202 #[link_name = "_commit"]
203 pub fn commit(fd: c_int) -> c_int;
204 #[link_name = "_get_osfhandle"]
205 pub fn get_osfhandle(fd: c_int) -> intptr_t;
206 #[link_name = "_open_osfhandle"]
207 pub fn open_osfhandle(osfhandle: intptr_t, flags: c_int) -> c_int;
208}