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 | |
ParadoxSpiral | aff822e | 2016-07-22 02:11:11 +0200 | [diff] [blame] | 101 | pub const LC_ALL: ::c_int = 0; |
| 102 | pub const LC_COLLATE: ::c_int = 1; |
| 103 | pub const LC_CTYPE: ::c_int = 2; |
| 104 | pub const LC_MONETARY: ::c_int = 3; |
| 105 | pub const LC_NUMERIC: ::c_int = 4; |
| 106 | pub const LC_TIME: ::c_int = 5; |
| 107 | |
Raphael Cohn | 3784990 | 2016-09-14 14:32:16 +0100 | [diff] [blame] | 108 | pub const EPERM: ::c_int = 1; |
| 109 | pub const ENOENT: ::c_int = 2; |
| 110 | pub const ESRCH: ::c_int = 3; |
| 111 | pub const EINTR: ::c_int = 4; |
| 112 | pub const EIO: ::c_int = 5; |
| 113 | pub const ENXIO: ::c_int = 6; |
| 114 | pub const E2BIG: ::c_int = 7; |
| 115 | pub const ENOEXEC: ::c_int = 8; |
| 116 | pub const EBADF: ::c_int = 9; |
| 117 | pub const ECHILD: ::c_int = 10; |
| 118 | pub const EAGAIN: ::c_int = 11; |
| 119 | pub const ENOMEM: ::c_int = 12; |
| 120 | pub const EACCES: ::c_int = 13; |
| 121 | pub const EFAULT: ::c_int = 14; |
| 122 | pub const EBUSY: ::c_int = 16; |
| 123 | pub const EEXIST: ::c_int = 17; |
| 124 | pub const EXDEV: ::c_int = 18; |
| 125 | pub const ENODEV: ::c_int = 19; |
| 126 | pub const ENOTDIR: ::c_int = 20; |
| 127 | pub const EISDIR: ::c_int = 21; |
| 128 | pub const EINVAL: ::c_int = 22; |
| 129 | pub const ENFILE: ::c_int = 23; |
| 130 | pub const EMFILE: ::c_int = 24; |
| 131 | pub const ENOTTY: ::c_int = 25; |
| 132 | pub const EFBIG: ::c_int = 27; |
| 133 | pub const ENOSPC: ::c_int = 28; |
| 134 | pub const ESPIPE: ::c_int = 29; |
| 135 | pub const EROFS: ::c_int = 30; |
| 136 | pub const EMLINK: ::c_int = 31; |
| 137 | pub const EPIPE: ::c_int = 32; |
| 138 | pub const EDOM: ::c_int = 33; |
| 139 | pub const ERANGE: ::c_int = 34; |
| 140 | pub const EDEADLK: ::c_int = 36; |
| 141 | pub const EDEADLOCK: ::c_int = 36; |
| 142 | pub const ENAMETOOLONG: ::c_int = 38; |
| 143 | pub const ENOLCK: ::c_int = 39; |
| 144 | pub const ENOSYS: ::c_int = 40; |
| 145 | pub const ENOTEMPTY: ::c_int = 41; |
| 146 | pub const EILSEQ: ::c_int = 42; |
| 147 | pub const STRUNCATE: ::c_int = 80; |
| 148 | |
Alex Crichton | f9323d1 | 2016-10-31 16:44:29 -0700 | [diff] [blame] | 149 | #[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 Crichton | 2c57e36 | 2015-09-15 17:30:53 -0700 | [diff] [blame] | 152 | extern {} |
| 153 | |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 154 | extern { |
| 155 | #[link_name = "_chmod"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 156 | pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 157 | #[link_name = "_wchmod"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 158 | pub fn wchmod(path: *const wchar_t, mode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 159 | #[link_name = "_mkdir"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 160 | pub fn mkdir(path: *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 161 | #[link_name = "_wrmdir"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 162 | pub fn wrmdir(path: *const wchar_t) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 163 | #[link_name = "_fstat64"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 164 | pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 165 | #[link_name = "_stat64"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 166 | pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 167 | #[link_name = "_wstat64"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 168 | pub fn wstat(path: *const wchar_t, buf: *mut stat) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 169 | #[link_name = "_wutime64"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 170 | pub fn wutime(file: *const wchar_t, buf: *mut utimbuf) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 171 | #[link_name = "_popen"] |
| 172 | pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; |
| 173 | #[link_name = "_pclose"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 174 | pub fn pclose(stream: *mut ::FILE) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 175 | #[link_name = "_fdopen"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 176 | pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 177 | #[link_name = "_fileno"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 178 | pub fn fileno(stream: *mut ::FILE) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 179 | #[link_name = "_open"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 180 | pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 181 | #[link_name = "_wopen"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 182 | pub fn wopen(path: *const wchar_t, oflag: ::c_int, ...) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 183 | #[link_name = "_creat"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 184 | pub fn creat(path: *const c_char, mode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 185 | #[link_name = "_access"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 186 | pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 187 | #[link_name = "_chdir"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 188 | pub fn chdir(dir: *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 189 | #[link_name = "_close"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 190 | pub fn close(fd: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 191 | #[link_name = "_dup"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 192 | pub fn dup(fd: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 193 | #[link_name = "_dup2"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 194 | pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 195 | #[link_name = "_execv"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 196 | 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] | 197 | #[link_name = "_execve"] |
| 198 | pub fn execve(prog: *const c_char, argv: *const *const c_char, |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 199 | envp: *const *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 200 | #[link_name = "_execvp"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 201 | 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] | 202 | #[link_name = "_execvpe"] |
| 203 | pub fn execvpe(c: *const c_char, argv: *const *const c_char, |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 204 | envp: *const *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 205 | #[link_name = "_getcwd"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 206 | 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] | 207 | #[link_name = "_getpid"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 208 | pub fn getpid() -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 209 | #[link_name = "_isatty"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 210 | pub fn isatty(fd: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 211 | #[link_name = "_lseek"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 212 | 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] | 213 | #[link_name = "_pipe"] |
Alex Crichton | 8a8bc66 | 2016-02-29 23:02:36 -0800 | [diff] [blame] | 214 | pub fn pipe(fds: *mut ::c_int, |
| 215 | psize: ::c_uint, |
| 216 | textmode: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 217 | #[link_name = "_read"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 218 | 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] | 219 | #[link_name = "_rmdir"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 220 | pub fn rmdir(path: *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 221 | #[link_name = "_unlink"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 222 | pub fn unlink(c: *const c_char) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 223 | #[link_name = "_write"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 224 | 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] | 225 | #[link_name = "_commit"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 226 | pub fn commit(fd: ::c_int) -> ::c_int; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 227 | #[link_name = "_get_osfhandle"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 228 | pub fn get_osfhandle(fd: ::c_int) -> ::intptr_t; |
Alex Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 229 | #[link_name = "_open_osfhandle"] |
Alex Crichton | 1791046 | 2015-09-22 19:11:04 -0700 | [diff] [blame] | 230 | pub fn open_osfhandle(osfhandle: ::intptr_t, flags: ::c_int) -> ::c_int; |
ParadoxSpiral | aff822e | 2016-07-22 02:11:11 +0200 | [diff] [blame] | 231 | 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 Crichton | bfc6ebc | 2015-09-11 15:29:40 -0700 | [diff] [blame] | 235 | } |