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; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 4 | pub type c_long = i32; |
| 5 | pub type c_ulong = u32; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 6 | pub type wchar_t = u16; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 7 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 8 | pub type clock_t = i32; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 9 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 10 | cfg_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 Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 17 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 18 | pub type off_t = i32; |
| 19 | pub type dev_t = u32; |
| 20 | pub type ino_t = u16; |
| 21 | pub enum timezone {} |
| 22 | pub type time64_t = i64; |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 23 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 24 | s! { |
| 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 Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 30 | pub st_nlink: ::c_short, |
| 31 | pub st_uid: ::c_short, |
| 32 | pub st_gid: ::c_short, |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 33 | 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 Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 40 | // note that this is called utimbuf64 in Windows |
| 41 | pub struct utimbuf { |
| 42 | pub actime: time64_t, |
| 43 | pub modtime: time64_t, |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 46 | pub struct timeval { |
| 47 | pub tv_sec: c_long, |
| 48 | pub tv_usec: c_long, |
| 49 | } |
Alex Crichton | 5d6cf05 | 2015-09-11 14:52:34 -0700 | [diff] [blame] | 50 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 51 | pub struct timespec { |
| 52 | pub tv_sec: time_t, |
| 53 | pub tv_nsec: c_long, |
| 54 | } |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 57 | pub const EXIT_FAILURE: ::c_int = 1; |
| 58 | pub const EXIT_SUCCESS: ::c_int = 0; |
| 59 | pub const RAND_MAX: ::c_int = 32767; |
| 60 | pub const EOF: ::c_int = -1; |
| 61 | pub const SEEK_SET: ::c_int = 0; |
| 62 | pub const SEEK_CUR: ::c_int = 1; |
| 63 | pub const SEEK_END: ::c_int = 2; |
| 64 | pub const _IOFBF: ::c_int = 0; |
| 65 | pub const _IONBF: ::c_int = 4; |
| 66 | pub const _IOLBF: ::c_int = 64; |
| 67 | pub const BUFSIZ: ::c_uint = 512; |
| 68 | pub const FOPEN_MAX: ::c_uint = 20; |
| 69 | pub const FILENAME_MAX: ::c_uint = 260; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 70 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 71 | cfg_if! { |
| 72 | if #[cfg(all(target_env = "gnu"))] { |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 73 | pub const L_tmpnam: ::c_uint = 14; |
| 74 | pub const TMP_MAX: ::c_uint = 0x7fff; |
Kamal Marhubi | 66c3375 | 2016-03-10 15:07:32 -0500 | [diff] [blame^] | 75 | } else if #[cfg(all(target_env = "msvc"))] { |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 76 | pub const L_tmpnam: ::c_uint = 260; |
| 77 | pub const TMP_MAX: ::c_uint = 0x7fff_ffff; |
Kamal Marhubi | 66c3375 | 2016-03-10 15:07:32 -0500 | [diff] [blame^] | 78 | } else { |
| 79 | // Unknown target_env |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 83 | pub const O_RDONLY: ::c_int = 0; |
| 84 | pub const O_WRONLY: ::c_int = 1; |
| 85 | pub const O_RDWR: ::c_int = 2; |
| 86 | pub const O_APPEND: ::c_int = 8; |
| 87 | pub const O_CREAT: ::c_int = 256; |
| 88 | pub const O_EXCL: ::c_int = 1024; |
| 89 | pub const O_TEXT: ::c_int = 16384; |
| 90 | pub const O_BINARY: ::c_int = 32768; |
| 91 | pub const O_NOINHERIT: ::c_int = 128; |
| 92 | pub const O_TRUNC: ::c_int = 512; |
| 93 | pub const S_IFCHR: ::c_int = 8192; |
| 94 | pub const S_IFDIR: ::c_int = 16384; |
| 95 | pub const S_IFREG: ::c_int = 32768; |
| 96 | pub const S_IFMT: ::c_int = 61440; |
| 97 | pub const S_IEXEC: ::c_int = 64; |
| 98 | pub const S_IWRITE: ::c_int = 128; |
| 99 | pub const S_IREAD: ::c_int = 256; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 100 | |
Alex Crichton | 8a8bc66 | 2016-02-29 23:02:36 -0800 | [diff] [blame] | 101 | #[cfg(target_env = "msvc")] // " if " -- appease style checker |
Alex Crichton | 2c57e36 | 2015-09-15 17:30:53 -0700 | [diff] [blame] | 102 | #[link(name = "msvcrt")] |
| 103 | extern {} |
| 104 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 105 | extern { |
| 106 | #[link_name = "_chmod"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 107 | pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 108 | #[link_name = "_wchmod"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 109 | pub fn wchmod(path: *const wchar_t, mode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 110 | #[link_name = "_mkdir"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 111 | pub fn mkdir(path: *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 112 | #[link_name = "_wrmdir"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 113 | pub fn wrmdir(path: *const wchar_t) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 114 | #[link_name = "_fstat64"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 115 | pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 116 | #[link_name = "_stat64"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 117 | pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 118 | #[link_name = "_wstat64"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 119 | pub fn wstat(path: *const wchar_t, buf: *mut stat) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 120 | #[link_name = "_wutime64"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 121 | pub fn wutime(file: *const wchar_t, buf: *mut utimbuf) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 122 | #[link_name = "_popen"] |
| 123 | pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; |
| 124 | #[link_name = "_pclose"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 125 | pub fn pclose(stream: *mut ::FILE) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 126 | #[link_name = "_fdopen"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 127 | pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 128 | #[link_name = "_fileno"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 129 | pub fn fileno(stream: *mut ::FILE) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 130 | #[link_name = "_open"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 131 | pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 132 | #[link_name = "_wopen"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 133 | pub fn wopen(path: *const wchar_t, oflag: ::c_int, ...) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 134 | #[link_name = "_creat"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 135 | pub fn creat(path: *const c_char, mode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 136 | #[link_name = "_access"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 137 | pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 138 | #[link_name = "_chdir"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 139 | pub fn chdir(dir: *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 140 | #[link_name = "_close"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 141 | pub fn close(fd: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 142 | #[link_name = "_dup"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 143 | pub fn dup(fd: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 144 | #[link_name = "_dup2"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 145 | pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 146 | #[link_name = "_execv"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 147 | pub fn execv(prog: *const c_char, argv: *const *const c_char) -> ::intptr_t; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 148 | #[link_name = "_execve"] |
| 149 | pub fn execve(prog: *const c_char, argv: *const *const c_char, |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 150 | envp: *const *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 151 | #[link_name = "_execvp"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 152 | pub fn execvp(c: *const c_char, argv: *const *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 153 | #[link_name = "_execvpe"] |
| 154 | pub fn execvpe(c: *const c_char, argv: *const *const c_char, |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 155 | envp: *const *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 156 | #[link_name = "_getcwd"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 157 | pub fn getcwd(buf: *mut c_char, size: ::c_int) -> *mut c_char; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 158 | #[link_name = "_getpid"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 159 | pub fn getpid() -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 160 | #[link_name = "_isatty"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 161 | pub fn isatty(fd: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 162 | #[link_name = "_lseek"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 163 | pub fn lseek(fd: ::c_int, offset: c_long, origin: ::c_int) -> c_long; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 164 | #[link_name = "_pipe"] |
Alex Crichton | 8a8bc66 | 2016-02-29 23:02:36 -0800 | [diff] [blame] | 165 | pub fn pipe(fds: *mut ::c_int, |
| 166 | psize: ::c_uint, |
| 167 | textmode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 168 | #[link_name = "_read"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 169 | pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::c_uint) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 170 | #[link_name = "_rmdir"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 171 | pub fn rmdir(path: *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 172 | #[link_name = "_unlink"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 173 | pub fn unlink(c: *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 174 | #[link_name = "_write"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 175 | pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::c_uint) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 176 | #[link_name = "_commit"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 177 | pub fn commit(fd: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 178 | #[link_name = "_get_osfhandle"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 179 | pub fn get_osfhandle(fd: ::c_int) -> ::intptr_t; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 180 | #[link_name = "_open_osfhandle"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 181 | pub fn open_osfhandle(osfhandle: ::intptr_t, flags: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 182 | } |