blob: 6c8332a62ee9055d1fd5056fad9552d1d994e2b3 [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;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -07004pub type c_long = i32;
5pub type c_ulong = u32;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -07006pub type wchar_t = u16;
Alex Crichton5d6cf052015-09-11 14:52:34 -07007
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -07008pub type clock_t = i32;
Alex Crichton5d6cf052015-09-11 14:52:34 -07009
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070010cfg_if! {
11 if #[cfg(all(target_arch = "x86", target_env = "gnu"))] {
12 pub type time_t = i32;
13 } else {
14 pub type time_t = i64;
15 }
16}
Alex Crichton5d6cf052015-09-11 14:52:34 -070017
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070018pub type off_t = i32;
19pub type dev_t = u32;
20pub type ino_t = u16;
21pub enum timezone {}
22pub type time64_t = i64;
Alex Crichton5d6cf052015-09-11 14:52:34 -070023
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070024s! {
25 // note this is the struct called stat64 in Windows. Not stat, nor stati64.
26 pub struct stat {
27 pub st_dev: dev_t,
28 pub st_ino: ino_t,
29 pub st_mode: u16,
Alex Crichton17910462015-09-22 19:11:04 -070030 pub st_nlink: ::c_short,
31 pub st_uid: ::c_short,
32 pub st_gid: ::c_short,
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070033 pub st_rdev: dev_t,
34 pub st_size: i64,
35 pub st_atime: time64_t,
36 pub st_mtime: time64_t,
37 pub st_ctime: time64_t,
Alex Crichton5d6cf052015-09-11 14:52:34 -070038 }
39
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070040 // note that this is called utimbuf64 in Windows
41 pub struct utimbuf {
42 pub actime: time64_t,
43 pub modtime: time64_t,
Alex Crichton5d6cf052015-09-11 14:52:34 -070044 }
45
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070046 pub struct timeval {
47 pub tv_sec: c_long,
48 pub tv_usec: c_long,
49 }
Alex Crichton5d6cf052015-09-11 14:52:34 -070050
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070051 pub struct timespec {
52 pub tv_sec: time_t,
53 pub tv_nsec: c_long,
54 }
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070055}
56
Alex Crichton17910462015-09-22 19:11:04 -070057pub const EXIT_FAILURE: ::c_int = 1;
58pub const EXIT_SUCCESS: ::c_int = 0;
59pub const RAND_MAX: ::c_int = 32767;
60pub const EOF: ::c_int = -1;
61pub const SEEK_SET: ::c_int = 0;
62pub const SEEK_CUR: ::c_int = 1;
63pub const SEEK_END: ::c_int = 2;
64pub const _IOFBF: ::c_int = 0;
65pub const _IONBF: ::c_int = 4;
66pub const _IOLBF: ::c_int = 64;
67pub const BUFSIZ: ::c_uint = 512;
68pub const FOPEN_MAX: ::c_uint = 20;
69pub const FILENAME_MAX: ::c_uint = 260;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070070
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070071cfg_if! {
72 if #[cfg(all(target_env = "gnu"))] {
Alex Crichton17910462015-09-22 19:11:04 -070073 pub const L_tmpnam: ::c_uint = 14;
74 pub const TMP_MAX: ::c_uint = 0x7fff;
Kamal Marhubi66c33752016-03-10 15:07:32 -050075 } else if #[cfg(all(target_env = "msvc"))] {
Alex Crichton17910462015-09-22 19:11:04 -070076 pub const L_tmpnam: ::c_uint = 260;
77 pub const TMP_MAX: ::c_uint = 0x7fff_ffff;
Kamal Marhubi66c33752016-03-10 15:07:32 -050078 } else {
79 // Unknown target_env
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -070080 }
81}
82
Alex Crichton17910462015-09-22 19:11:04 -070083pub const O_RDONLY: ::c_int = 0;
84pub const O_WRONLY: ::c_int = 1;
85pub const O_RDWR: ::c_int = 2;
86pub const O_APPEND: ::c_int = 8;
87pub const O_CREAT: ::c_int = 256;
88pub const O_EXCL: ::c_int = 1024;
89pub const O_TEXT: ::c_int = 16384;
90pub const O_BINARY: ::c_int = 32768;
91pub const O_NOINHERIT: ::c_int = 128;
92pub const O_TRUNC: ::c_int = 512;
93pub const S_IFCHR: ::c_int = 8192;
94pub const S_IFDIR: ::c_int = 16384;
95pub const S_IFREG: ::c_int = 32768;
96pub const S_IFMT: ::c_int = 61440;
97pub const S_IEXEC: ::c_int = 64;
98pub const S_IWRITE: ::c_int = 128;
99pub const S_IREAD: ::c_int = 256;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700100
ParadoxSpiralaff822e2016-07-22 02:11:11 +0200101pub const LC_ALL: ::c_int = 0;
102pub const LC_COLLATE: ::c_int = 1;
103pub const LC_CTYPE: ::c_int = 2;
104pub const LC_MONETARY: ::c_int = 3;
105pub const LC_NUMERIC: ::c_int = 4;
106pub const LC_TIME: ::c_int = 5;
107
Raphael Cohn37849902016-09-14 14:32:16 +0100108pub const EPERM: ::c_int = 1;
109pub const ENOENT: ::c_int = 2;
110pub const ESRCH: ::c_int = 3;
111pub const EINTR: ::c_int = 4;
112pub const EIO: ::c_int = 5;
113pub const ENXIO: ::c_int = 6;
114pub const E2BIG: ::c_int = 7;
115pub const ENOEXEC: ::c_int = 8;
116pub const EBADF: ::c_int = 9;
117pub const ECHILD: ::c_int = 10;
118pub const EAGAIN: ::c_int = 11;
119pub const ENOMEM: ::c_int = 12;
120pub const EACCES: ::c_int = 13;
121pub const EFAULT: ::c_int = 14;
122pub const EBUSY: ::c_int = 16;
123pub const EEXIST: ::c_int = 17;
124pub const EXDEV: ::c_int = 18;
125pub const ENODEV: ::c_int = 19;
126pub const ENOTDIR: ::c_int = 20;
127pub const EISDIR: ::c_int = 21;
128pub const EINVAL: ::c_int = 22;
129pub const ENFILE: ::c_int = 23;
130pub const EMFILE: ::c_int = 24;
131pub const ENOTTY: ::c_int = 25;
132pub const EFBIG: ::c_int = 27;
133pub const ENOSPC: ::c_int = 28;
134pub const ESPIPE: ::c_int = 29;
135pub const EROFS: ::c_int = 30;
136pub const EMLINK: ::c_int = 31;
137pub const EPIPE: ::c_int = 32;
138pub const EDOM: ::c_int = 33;
139pub const ERANGE: ::c_int = 34;
140pub const EDEADLK: ::c_int = 36;
141pub const EDEADLOCK: ::c_int = 36;
142pub const ENAMETOOLONG: ::c_int = 38;
143pub const ENOLCK: ::c_int = 39;
144pub const ENOSYS: ::c_int = 40;
145pub const ENOTEMPTY: ::c_int = 41;
146pub const EILSEQ: ::c_int = 42;
147pub const STRUNCATE: ::c_int = 80;
148
Alex Crichtonf9323d12016-10-31 16:44:29 -0700149#[cfg(all(target_env = "msvc", stdbuild))] // " if " -- appease style checker
150#[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))]
151#[link(name = "libcmt", cfg(target_feature = "crt-static"))]
Alex Crichton2c57e362015-09-15 17:30:53 -0700152extern {}
153
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700154extern {
155 #[link_name = "_chmod"]
Alex Crichton17910462015-09-22 19:11:04 -0700156 pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700157 #[link_name = "_wchmod"]
Alex Crichton17910462015-09-22 19:11:04 -0700158 pub fn wchmod(path: *const wchar_t, mode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700159 #[link_name = "_mkdir"]
Alex Crichton17910462015-09-22 19:11:04 -0700160 pub fn mkdir(path: *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700161 #[link_name = "_wrmdir"]
Alex Crichton17910462015-09-22 19:11:04 -0700162 pub fn wrmdir(path: *const wchar_t) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700163 #[link_name = "_fstat64"]
Alex Crichton17910462015-09-22 19:11:04 -0700164 pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700165 #[link_name = "_stat64"]
Alex Crichton17910462015-09-22 19:11:04 -0700166 pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700167 #[link_name = "_wstat64"]
Alex Crichton17910462015-09-22 19:11:04 -0700168 pub fn wstat(path: *const wchar_t, buf: *mut stat) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700169 #[link_name = "_wutime64"]
Alex Crichton17910462015-09-22 19:11:04 -0700170 pub fn wutime(file: *const wchar_t, buf: *mut utimbuf) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700171 #[link_name = "_popen"]
172 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE;
173 #[link_name = "_pclose"]
Alex Crichton17910462015-09-22 19:11:04 -0700174 pub fn pclose(stream: *mut ::FILE) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700175 #[link_name = "_fdopen"]
Alex Crichton17910462015-09-22 19:11:04 -0700176 pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700177 #[link_name = "_fileno"]
Alex Crichton17910462015-09-22 19:11:04 -0700178 pub fn fileno(stream: *mut ::FILE) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700179 #[link_name = "_open"]
Alex Crichton17910462015-09-22 19:11:04 -0700180 pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700181 #[link_name = "_wopen"]
Alex Crichton17910462015-09-22 19:11:04 -0700182 pub fn wopen(path: *const wchar_t, oflag: ::c_int, ...) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700183 #[link_name = "_creat"]
Alex Crichton17910462015-09-22 19:11:04 -0700184 pub fn creat(path: *const c_char, mode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700185 #[link_name = "_access"]
Alex Crichton17910462015-09-22 19:11:04 -0700186 pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700187 #[link_name = "_chdir"]
Alex Crichton17910462015-09-22 19:11:04 -0700188 pub fn chdir(dir: *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700189 #[link_name = "_close"]
Alex Crichton17910462015-09-22 19:11:04 -0700190 pub fn close(fd: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700191 #[link_name = "_dup"]
Alex Crichton17910462015-09-22 19:11:04 -0700192 pub fn dup(fd: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700193 #[link_name = "_dup2"]
Alex Crichton17910462015-09-22 19:11:04 -0700194 pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700195 #[link_name = "_execv"]
Alex Crichton17910462015-09-22 19:11:04 -0700196 pub fn execv(prog: *const c_char, argv: *const *const c_char) -> ::intptr_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700197 #[link_name = "_execve"]
198 pub fn execve(prog: *const c_char, argv: *const *const c_char,
Alex Crichton17910462015-09-22 19:11:04 -0700199 envp: *const *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700200 #[link_name = "_execvp"]
Alex Crichton17910462015-09-22 19:11:04 -0700201 pub fn execvp(c: *const c_char, argv: *const *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700202 #[link_name = "_execvpe"]
203 pub fn execvpe(c: *const c_char, argv: *const *const c_char,
Alex Crichton17910462015-09-22 19:11:04 -0700204 envp: *const *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700205 #[link_name = "_getcwd"]
Alex Crichton17910462015-09-22 19:11:04 -0700206 pub fn getcwd(buf: *mut c_char, size: ::c_int) -> *mut c_char;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700207 #[link_name = "_getpid"]
Alex Crichton17910462015-09-22 19:11:04 -0700208 pub fn getpid() -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700209 #[link_name = "_isatty"]
Alex Crichton17910462015-09-22 19:11:04 -0700210 pub fn isatty(fd: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700211 #[link_name = "_lseek"]
Alex Crichton17910462015-09-22 19:11:04 -0700212 pub fn lseek(fd: ::c_int, offset: c_long, origin: ::c_int) -> c_long;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700213 #[link_name = "_pipe"]
Alex Crichton8a8bc662016-02-29 23:02:36 -0800214 pub fn pipe(fds: *mut ::c_int,
215 psize: ::c_uint,
216 textmode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700217 #[link_name = "_read"]
Alex Crichton17910462015-09-22 19:11:04 -0700218 pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::c_uint) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700219 #[link_name = "_rmdir"]
Alex Crichton17910462015-09-22 19:11:04 -0700220 pub fn rmdir(path: *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700221 #[link_name = "_unlink"]
Alex Crichton17910462015-09-22 19:11:04 -0700222 pub fn unlink(c: *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700223 #[link_name = "_write"]
Alex Crichton17910462015-09-22 19:11:04 -0700224 pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::c_uint) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700225 #[link_name = "_commit"]
Alex Crichton17910462015-09-22 19:11:04 -0700226 pub fn commit(fd: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700227 #[link_name = "_get_osfhandle"]
Alex Crichton17910462015-09-22 19:11:04 -0700228 pub fn get_osfhandle(fd: ::c_int) -> ::intptr_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700229 #[link_name = "_open_osfhandle"]
Alex Crichton17910462015-09-22 19:11:04 -0700230 pub fn open_osfhandle(osfhandle: ::intptr_t, flags: ::c_int) -> ::c_int;
ParadoxSpiralaff822e2016-07-22 02:11:11 +0200231 pub fn setlocale(category: ::c_int, locale: *const c_char) -> *mut c_char;
232 #[link_name = "_wsetlocale"]
233 pub fn wsetlocale(category: ::c_int,
234 locale: *const wchar_t) -> *mut wchar_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700235}