Alex Crichton | d3d7792 | 2015-09-11 17:03:39 -0700 | [diff] [blame] | 1 | //! Windows CRT definitions |
| 2 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 3 | pub type c_char = i8; |
| 4 | pub type c_schar = i8; |
| 5 | pub type c_uchar = u8; |
| 6 | pub type c_short = i16; |
| 7 | pub type c_ushort = u16; |
| 8 | pub type c_int = i32; |
| 9 | pub type c_uint = u32; |
| 10 | pub type c_long = i32; |
| 11 | pub type c_ulong = u32; |
| 12 | pub type c_float = f32; |
| 13 | pub type c_double = f64; |
| 14 | pub type wchar_t = u16; |
| 15 | pub type c_longlong = i64; |
| 16 | pub type c_ulonglong = u64; |
| 17 | pub type intmax_t = i64; |
| 18 | pub type uintmax_t = u64; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 19 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 20 | cfg_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 Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 27 | } 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 Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 33 | } else { |
| 34 | // unknown arch |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 35 | } |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 36 | } |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 37 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 38 | pub type clock_t = i32; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 39 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 40 | cfg_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 Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 47 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 48 | pub type off_t = i32; |
| 49 | pub type dev_t = u32; |
| 50 | pub type ino_t = u16; |
| 51 | pub enum timezone {} |
| 52 | pub type time64_t = i64; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 53 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 54 | s! { |
| 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 Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 70 | // note that this is called utimbuf64 in Windows |
| 71 | pub struct utimbuf { |
| 72 | pub actime: time64_t, |
| 73 | pub modtime: time64_t, |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 76 | pub struct timeval { |
| 77 | pub tv_sec: c_long, |
| 78 | pub tv_usec: c_long, |
| 79 | } |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 80 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 81 | pub struct timespec { |
| 82 | pub tv_sec: time_t, |
| 83 | pub tv_nsec: c_long, |
| 84 | } |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | pub const EXIT_FAILURE: c_int = 1; |
| 88 | pub const EXIT_SUCCESS: c_int = 0; |
| 89 | pub const RAND_MAX: c_int = 32767; |
| 90 | pub const EOF: c_int = -1; |
| 91 | pub const SEEK_SET: c_int = 0; |
| 92 | pub const SEEK_CUR: c_int = 1; |
| 93 | pub const SEEK_END: c_int = 2; |
| 94 | pub const _IOFBF: c_int = 0; |
| 95 | pub const _IONBF: c_int = 4; |
| 96 | pub const _IOLBF: c_int = 64; |
| 97 | pub const BUFSIZ: c_uint = 512; |
| 98 | pub const FOPEN_MAX: c_uint = 20; |
| 99 | pub const FILENAME_MAX: c_uint = 260; |
| 100 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 101 | cfg_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 | |
| 111 | pub const O_RDONLY: c_int = 0; |
| 112 | pub const O_WRONLY: c_int = 1; |
| 113 | pub const O_RDWR: c_int = 2; |
| 114 | pub const O_APPEND: c_int = 8; |
| 115 | pub const O_CREAT: c_int = 256; |
| 116 | pub const O_EXCL: c_int = 1024; |
Alex Crichton | c4d4c70 | 2015-09-21 13:36:54 -0700 | [diff] [blame] | 117 | pub const O_TEXT: c_int = 16384; |
| 118 | pub const O_BINARY: c_int = 32768; |
| 119 | pub const O_NOINHERIT: c_int = 128; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 120 | pub const O_TRUNC: c_int = 512; |
| 121 | pub const S_IFCHR: c_int = 8192; |
| 122 | pub const S_IFDIR: c_int = 16384; |
| 123 | pub const S_IFREG: c_int = 32768; |
| 124 | pub const S_IFMT: c_int = 61440; |
| 125 | pub const S_IEXEC: c_int = 64; |
| 126 | pub const S_IWRITE: c_int = 128; |
| 127 | pub const S_IREAD: c_int = 256; |
| 128 | |
Alex Crichton | 2c57e36 | 2015-09-15 17:30:53 -0700 | [diff] [blame] | 129 | #[cfg(target_env = "msvc")] |
Alex Crichton | 2c57e36 | 2015-09-15 17:30:53 -0700 | [diff] [blame] | 130 | #[link(name = "msvcrt")] |
| 131 | extern {} |
| 132 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 133 | extern { |
| 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 | } |