blob: 5ba8b33451cdf50e66fba6cb714030a9b3bb6115 [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
Alex Crichton8a8bc662016-02-29 23:02:36 -0800108#[cfg(target_env = "msvc")] // " if " -- appease style checker
Alex Crichton2c57e362015-09-15 17:30:53 -0700109#[link(name = "msvcrt")]
110extern {}
111
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700112extern {
113 #[link_name = "_chmod"]
Alex Crichton17910462015-09-22 19:11:04 -0700114 pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700115 #[link_name = "_wchmod"]
Alex Crichton17910462015-09-22 19:11:04 -0700116 pub fn wchmod(path: *const wchar_t, mode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700117 #[link_name = "_mkdir"]
Alex Crichton17910462015-09-22 19:11:04 -0700118 pub fn mkdir(path: *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700119 #[link_name = "_wrmdir"]
Alex Crichton17910462015-09-22 19:11:04 -0700120 pub fn wrmdir(path: *const wchar_t) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700121 #[link_name = "_fstat64"]
Alex Crichton17910462015-09-22 19:11:04 -0700122 pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700123 #[link_name = "_stat64"]
Alex Crichton17910462015-09-22 19:11:04 -0700124 pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700125 #[link_name = "_wstat64"]
Alex Crichton17910462015-09-22 19:11:04 -0700126 pub fn wstat(path: *const wchar_t, buf: *mut stat) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700127 #[link_name = "_wutime64"]
Alex Crichton17910462015-09-22 19:11:04 -0700128 pub fn wutime(file: *const wchar_t, buf: *mut utimbuf) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700129 #[link_name = "_popen"]
130 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE;
131 #[link_name = "_pclose"]
Alex Crichton17910462015-09-22 19:11:04 -0700132 pub fn pclose(stream: *mut ::FILE) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700133 #[link_name = "_fdopen"]
Alex Crichton17910462015-09-22 19:11:04 -0700134 pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700135 #[link_name = "_fileno"]
Alex Crichton17910462015-09-22 19:11:04 -0700136 pub fn fileno(stream: *mut ::FILE) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700137 #[link_name = "_open"]
Alex Crichton17910462015-09-22 19:11:04 -0700138 pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700139 #[link_name = "_wopen"]
Alex Crichton17910462015-09-22 19:11:04 -0700140 pub fn wopen(path: *const wchar_t, oflag: ::c_int, ...) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700141 #[link_name = "_creat"]
Alex Crichton17910462015-09-22 19:11:04 -0700142 pub fn creat(path: *const c_char, mode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700143 #[link_name = "_access"]
Alex Crichton17910462015-09-22 19:11:04 -0700144 pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700145 #[link_name = "_chdir"]
Alex Crichton17910462015-09-22 19:11:04 -0700146 pub fn chdir(dir: *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700147 #[link_name = "_close"]
Alex Crichton17910462015-09-22 19:11:04 -0700148 pub fn close(fd: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700149 #[link_name = "_dup"]
Alex Crichton17910462015-09-22 19:11:04 -0700150 pub fn dup(fd: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700151 #[link_name = "_dup2"]
Alex Crichton17910462015-09-22 19:11:04 -0700152 pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700153 #[link_name = "_execv"]
Alex Crichton17910462015-09-22 19:11:04 -0700154 pub fn execv(prog: *const c_char, argv: *const *const c_char) -> ::intptr_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700155 #[link_name = "_execve"]
156 pub fn execve(prog: *const c_char, argv: *const *const c_char,
Alex Crichton17910462015-09-22 19:11:04 -0700157 envp: *const *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700158 #[link_name = "_execvp"]
Alex Crichton17910462015-09-22 19:11:04 -0700159 pub fn execvp(c: *const c_char, argv: *const *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700160 #[link_name = "_execvpe"]
161 pub fn execvpe(c: *const c_char, argv: *const *const c_char,
Alex Crichton17910462015-09-22 19:11:04 -0700162 envp: *const *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700163 #[link_name = "_getcwd"]
Alex Crichton17910462015-09-22 19:11:04 -0700164 pub fn getcwd(buf: *mut c_char, size: ::c_int) -> *mut c_char;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700165 #[link_name = "_getpid"]
Alex Crichton17910462015-09-22 19:11:04 -0700166 pub fn getpid() -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700167 #[link_name = "_isatty"]
Alex Crichton17910462015-09-22 19:11:04 -0700168 pub fn isatty(fd: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700169 #[link_name = "_lseek"]
Alex Crichton17910462015-09-22 19:11:04 -0700170 pub fn lseek(fd: ::c_int, offset: c_long, origin: ::c_int) -> c_long;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700171 #[link_name = "_pipe"]
Alex Crichton8a8bc662016-02-29 23:02:36 -0800172 pub fn pipe(fds: *mut ::c_int,
173 psize: ::c_uint,
174 textmode: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700175 #[link_name = "_read"]
Alex Crichton17910462015-09-22 19:11:04 -0700176 pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::c_uint) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700177 #[link_name = "_rmdir"]
Alex Crichton17910462015-09-22 19:11:04 -0700178 pub fn rmdir(path: *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700179 #[link_name = "_unlink"]
Alex Crichton17910462015-09-22 19:11:04 -0700180 pub fn unlink(c: *const c_char) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700181 #[link_name = "_write"]
Alex Crichton17910462015-09-22 19:11:04 -0700182 pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::c_uint) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700183 #[link_name = "_commit"]
Alex Crichton17910462015-09-22 19:11:04 -0700184 pub fn commit(fd: ::c_int) -> ::c_int;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700185 #[link_name = "_get_osfhandle"]
Alex Crichton17910462015-09-22 19:11:04 -0700186 pub fn get_osfhandle(fd: ::c_int) -> ::intptr_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700187 #[link_name = "_open_osfhandle"]
Alex Crichton17910462015-09-22 19:11:04 -0700188 pub fn open_osfhandle(osfhandle: ::intptr_t, flags: ::c_int) -> ::c_int;
ParadoxSpiralaff822e2016-07-22 02:11:11 +0200189 pub fn setlocale(category: ::c_int, locale: *const c_char) -> *mut c_char;
190 #[link_name = "_wsetlocale"]
191 pub fn wsetlocale(category: ::c_int,
192 locale: *const wchar_t) -> *mut wchar_t;
Alex Crichtonbfc6ebc2015-09-11 15:29:40 -0700193}