]>
Commit | Line | Data |
---|---|---|
92a42be0 SL |
1 | //! Windows CRT definitions |
2 | ||
3 | pub type c_char = i8; | |
4 | pub type c_long = i32; | |
5 | pub type c_ulong = u32; | |
6 | pub type wchar_t = u16; | |
7 | ||
8 | pub type clock_t = i32; | |
9 | ||
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 | } | |
17 | ||
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; | |
23 | ||
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, | |
30 | pub st_nlink: ::c_short, | |
31 | pub st_uid: ::c_short, | |
32 | pub st_gid: ::c_short, | |
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, | |
38 | } | |
39 | ||
40 | // note that this is called utimbuf64 in Windows | |
41 | pub struct utimbuf { | |
42 | pub actime: time64_t, | |
43 | pub modtime: time64_t, | |
44 | } | |
45 | ||
46 | pub struct timeval { | |
47 | pub tv_sec: c_long, | |
48 | pub tv_usec: c_long, | |
49 | } | |
50 | ||
51 | pub struct timespec { | |
52 | pub tv_sec: time_t, | |
53 | pub tv_nsec: c_long, | |
54 | } | |
55 | } | |
56 | ||
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; | |
70 | ||
71 | cfg_if! { | |
72 | if #[cfg(all(target_env = "gnu"))] { | |
73 | pub const L_tmpnam: ::c_uint = 14; | |
74 | pub const TMP_MAX: ::c_uint = 0x7fff; | |
54a0048b | 75 | } else if #[cfg(all(target_env = "msvc"))] { |
92a42be0 SL |
76 | pub const L_tmpnam: ::c_uint = 260; |
77 | pub const TMP_MAX: ::c_uint = 0x7fff_ffff; | |
54a0048b SL |
78 | } else { |
79 | // Unknown target_env | |
92a42be0 SL |
80 | } |
81 | } | |
82 | ||
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; | |
100 | ||
54a0048b | 101 | #[cfg(target_env = "msvc")] // " if " -- appease style checker |
92a42be0 SL |
102 | #[link(name = "msvcrt")] |
103 | extern {} | |
104 | ||
105 | extern { | |
106 | #[link_name = "_chmod"] | |
107 | pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int; | |
108 | #[link_name = "_wchmod"] | |
109 | pub fn wchmod(path: *const wchar_t, mode: ::c_int) -> ::c_int; | |
110 | #[link_name = "_mkdir"] | |
111 | pub fn mkdir(path: *const c_char) -> ::c_int; | |
112 | #[link_name = "_wrmdir"] | |
113 | pub fn wrmdir(path: *const wchar_t) -> ::c_int; | |
114 | #[link_name = "_fstat64"] | |
115 | pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; | |
116 | #[link_name = "_stat64"] | |
117 | pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; | |
118 | #[link_name = "_wstat64"] | |
119 | pub fn wstat(path: *const wchar_t, buf: *mut stat) -> ::c_int; | |
120 | #[link_name = "_wutime64"] | |
121 | pub fn wutime(file: *const wchar_t, buf: *mut utimbuf) -> ::c_int; | |
122 | #[link_name = "_popen"] | |
123 | pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; | |
124 | #[link_name = "_pclose"] | |
125 | pub fn pclose(stream: *mut ::FILE) -> ::c_int; | |
126 | #[link_name = "_fdopen"] | |
127 | pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; | |
128 | #[link_name = "_fileno"] | |
129 | pub fn fileno(stream: *mut ::FILE) -> ::c_int; | |
130 | #[link_name = "_open"] | |
131 | pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; | |
132 | #[link_name = "_wopen"] | |
133 | pub fn wopen(path: *const wchar_t, oflag: ::c_int, ...) -> ::c_int; | |
134 | #[link_name = "_creat"] | |
135 | pub fn creat(path: *const c_char, mode: ::c_int) -> ::c_int; | |
136 | #[link_name = "_access"] | |
137 | pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; | |
138 | #[link_name = "_chdir"] | |
139 | pub fn chdir(dir: *const c_char) -> ::c_int; | |
140 | #[link_name = "_close"] | |
141 | pub fn close(fd: ::c_int) -> ::c_int; | |
142 | #[link_name = "_dup"] | |
143 | pub fn dup(fd: ::c_int) -> ::c_int; | |
144 | #[link_name = "_dup2"] | |
145 | pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int; | |
146 | #[link_name = "_execv"] | |
147 | pub fn execv(prog: *const c_char, argv: *const *const c_char) -> ::intptr_t; | |
148 | #[link_name = "_execve"] | |
149 | pub fn execve(prog: *const c_char, argv: *const *const c_char, | |
150 | envp: *const *const c_char) -> ::c_int; | |
151 | #[link_name = "_execvp"] | |
152 | pub fn execvp(c: *const c_char, argv: *const *const c_char) -> ::c_int; | |
153 | #[link_name = "_execvpe"] | |
154 | pub fn execvpe(c: *const c_char, argv: *const *const c_char, | |
155 | envp: *const *const c_char) -> ::c_int; | |
156 | #[link_name = "_getcwd"] | |
157 | pub fn getcwd(buf: *mut c_char, size: ::c_int) -> *mut c_char; | |
158 | #[link_name = "_getpid"] | |
159 | pub fn getpid() -> ::c_int; | |
160 | #[link_name = "_isatty"] | |
161 | pub fn isatty(fd: ::c_int) -> ::c_int; | |
162 | #[link_name = "_lseek"] | |
163 | pub fn lseek(fd: ::c_int, offset: c_long, origin: ::c_int) -> c_long; | |
164 | #[link_name = "_pipe"] | |
54a0048b SL |
165 | pub fn pipe(fds: *mut ::c_int, |
166 | psize: ::c_uint, | |
167 | textmode: ::c_int) -> ::c_int; | |
92a42be0 SL |
168 | #[link_name = "_read"] |
169 | pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::c_uint) -> ::c_int; | |
170 | #[link_name = "_rmdir"] | |
171 | pub fn rmdir(path: *const c_char) -> ::c_int; | |
172 | #[link_name = "_unlink"] | |
173 | pub fn unlink(c: *const c_char) -> ::c_int; | |
174 | #[link_name = "_write"] | |
175 | pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::c_uint) -> ::c_int; | |
176 | #[link_name = "_commit"] | |
177 | pub fn commit(fd: ::c_int) -> ::c_int; | |
178 | #[link_name = "_get_osfhandle"] | |
179 | pub fn get_osfhandle(fd: ::c_int) -> ::intptr_t; | |
180 | #[link_name = "_open_osfhandle"] | |
181 | pub fn open_osfhandle(osfhandle: ::intptr_t, flags: ::c_int) -> ::c_int; | |
182 | } |