1 //! Windows CRT definitions 2 3 pub type c_schar = i8; 4 pub type c_uchar = u8; 5 pub type c_short = i16; 6 pub type c_ushort = u16; 7 pub type c_int = i32; 8 pub type c_uint = u32; 9 pub type c_float = f32; 10 pub type c_double = f64; 11 pub type c_longlong = i64; 12 pub type c_ulonglong = u64; 13 pub type intmax_t = i64; 14 pub type uintmax_t = u64; 15 16 pub type size_t = usize; 17 pub type ptrdiff_t = isize; 18 pub type intptr_t = isize; 19 pub type uintptr_t = usize; 20 pub type ssize_t = isize; 21 pub type sighandler_t = usize; 22 23 pub type c_char = i8; 24 pub type c_long = i32; 25 pub type c_ulong = u32; 26 pub type wchar_t = u16; 27 28 pub type clock_t = i32; 29 30 cfg_if! { 31 if #[cfg(all(target_arch = "x86", target_env = "gnu"))] { 32 pub type time_t = i32; 33 } else { 34 pub type time_t = i64; 35 } 36 } 37 38 pub type off_t = i32; 39 pub type dev_t = u32; 40 pub type ino_t = u16; 41 #[cfg_attr(feature = "extra_traits", derive(Debug))] 42 pub enum timezone {} 43 impl ::Copy for timezone {} 44 impl ::Clone for timezone { 45 fn clone(&self) -> timezone { *self } 46 } 47 pub type time64_t = i64; 48 49 pub type SOCKET = ::uintptr_t; 50 51 s! { 52 // note this is the struct called stat64 in Windows. Not stat, nor stati64. 53 pub struct stat { 54 pub st_dev: dev_t, 55 pub st_ino: ino_t, 56 pub st_mode: u16, 57 pub st_nlink: ::c_short, 58 pub st_uid: ::c_short, 59 pub st_gid: ::c_short, 60 pub st_rdev: dev_t, 61 pub st_size: i64, 62 pub st_atime: time64_t, 63 pub st_mtime: time64_t, 64 pub st_ctime: time64_t, 65 } 66 67 // note that this is called utimbuf64 in Windows 68 pub struct utimbuf { 69 pub actime: time64_t, 70 pub modtime: time64_t, 71 } 72 73 pub struct tm { 74 pub tm_sec: ::c_int, 75 pub tm_min: ::c_int, 76 pub tm_hour: ::c_int, 77 pub tm_mday: ::c_int, 78 pub tm_mon: ::c_int, 79 pub tm_year: ::c_int, 80 pub tm_wday: ::c_int, 81 pub tm_yday: ::c_int, 82 pub tm_isdst: ::c_int, 83 } 84 85 pub struct timeval { 86 pub tv_sec: c_long, 87 pub tv_usec: c_long, 88 } 89 90 pub struct timespec { 91 pub tv_sec: time_t, 92 pub tv_nsec: c_long, 93 } 94 95 pub struct sockaddr { 96 pub sa_family: c_ushort, 97 pub sa_data: [c_char; 14], 98 } 99 } 100 101 pub const INT_MIN: c_int = -2147483648; 102 pub const INT_MAX: c_int = 2147483647; 103 104 pub const EXIT_FAILURE: ::c_int = 1; 105 pub const EXIT_SUCCESS: ::c_int = 0; 106 pub const RAND_MAX: ::c_int = 32767; 107 pub const EOF: ::c_int = -1; 108 pub const SEEK_SET: ::c_int = 0; 109 pub const SEEK_CUR: ::c_int = 1; 110 pub const SEEK_END: ::c_int = 2; 111 pub const _IOFBF: ::c_int = 0; 112 pub const _IONBF: ::c_int = 4; 113 pub const _IOLBF: ::c_int = 64; 114 pub const BUFSIZ: ::c_uint = 512; 115 pub const FOPEN_MAX: ::c_uint = 20; 116 pub const FILENAME_MAX: ::c_uint = 260; 117 118 pub const O_RDONLY: ::c_int = 0; 119 pub const O_WRONLY: ::c_int = 1; 120 pub const O_RDWR: ::c_int = 2; 121 pub const O_APPEND: ::c_int = 8; 122 pub const O_CREAT: ::c_int = 256; 123 pub const O_EXCL: ::c_int = 1024; 124 pub const O_TEXT: ::c_int = 16384; 125 pub const O_BINARY: ::c_int = 32768; 126 pub const O_NOINHERIT: ::c_int = 128; 127 pub const O_TRUNC: ::c_int = 512; 128 pub const S_IFCHR: ::c_int = 8192; 129 pub const S_IFDIR: ::c_int = 16384; 130 pub const S_IFREG: ::c_int = 32768; 131 pub const S_IFMT: ::c_int = 61440; 132 pub const S_IEXEC: ::c_int = 64; 133 pub const S_IWRITE: ::c_int = 128; 134 pub const S_IREAD: ::c_int = 256; 135 136 pub const LC_ALL: ::c_int = 0; 137 pub const LC_COLLATE: ::c_int = 1; 138 pub const LC_CTYPE: ::c_int = 2; 139 pub const LC_MONETARY: ::c_int = 3; 140 pub const LC_NUMERIC: ::c_int = 4; 141 pub const LC_TIME: ::c_int = 5; 142 143 pub const EPERM: ::c_int = 1; 144 pub const ENOENT: ::c_int = 2; 145 pub const ESRCH: ::c_int = 3; 146 pub const EINTR: ::c_int = 4; 147 pub const EIO: ::c_int = 5; 148 pub const ENXIO: ::c_int = 6; 149 pub const E2BIG: ::c_int = 7; 150 pub const ENOEXEC: ::c_int = 8; 151 pub const EBADF: ::c_int = 9; 152 pub const ECHILD: ::c_int = 10; 153 pub const EAGAIN: ::c_int = 11; 154 pub const ENOMEM: ::c_int = 12; 155 pub const EACCES: ::c_int = 13; 156 pub const EFAULT: ::c_int = 14; 157 pub const EBUSY: ::c_int = 16; 158 pub const EEXIST: ::c_int = 17; 159 pub const EXDEV: ::c_int = 18; 160 pub const ENODEV: ::c_int = 19; 161 pub const ENOTDIR: ::c_int = 20; 162 pub const EISDIR: ::c_int = 21; 163 pub const EINVAL: ::c_int = 22; 164 pub const ENFILE: ::c_int = 23; 165 pub const EMFILE: ::c_int = 24; 166 pub const ENOTTY: ::c_int = 25; 167 pub const EFBIG: ::c_int = 27; 168 pub const ENOSPC: ::c_int = 28; 169 pub const ESPIPE: ::c_int = 29; 170 pub const EROFS: ::c_int = 30; 171 pub const EMLINK: ::c_int = 31; 172 pub const EPIPE: ::c_int = 32; 173 pub const EDOM: ::c_int = 33; 174 pub const ERANGE: ::c_int = 34; 175 pub const EDEADLK: ::c_int = 36; 176 pub const EDEADLOCK: ::c_int = 36; 177 pub const ENAMETOOLONG: ::c_int = 38; 178 pub const ENOLCK: ::c_int = 39; 179 pub const ENOSYS: ::c_int = 40; 180 pub const ENOTEMPTY: ::c_int = 41; 181 pub const EILSEQ: ::c_int = 42; 182 pub const STRUNCATE: ::c_int = 80; 183 184 // signal codes 185 pub const SIGINT: ::c_int = 2; 186 pub const SIGILL: ::c_int = 4; 187 pub const SIGFPE: ::c_int = 8; 188 pub const SIGSEGV: ::c_int = 11; 189 pub const SIGTERM: ::c_int = 15; 190 pub const SIGABRT: ::c_int = 22; 191 pub const NSIG: ::c_int = 23; 192 pub const SIG_ERR: ::c_int = -1; 193 194 // inline comment below appeases style checker 195 #[cfg(all(target_env = "msvc", feature = "rustc-dep-of-std"))] // " if " 196 #[link(name = "msvcrt", cfg(not(target_feature = "crt-static")))] 197 #[link(name = "libcmt", cfg(target_feature = "crt-static"))] 198 extern {} 199 200 #[cfg_attr(feature = "extra_traits", derive(Debug))] 201 pub enum FILE {} 202 impl ::Copy for FILE {} 203 impl ::Clone for FILE { 204 fn clone(&self) -> FILE { *self } 205 } 206 #[cfg_attr(feature = "extra_traits", derive(Debug))] 207 pub enum fpos_t {} // TODO: fill this out with a struct 208 impl ::Copy for fpos_t {} 209 impl ::Clone for fpos_t { 210 fn clone(&self) -> fpos_t { *self } 211 } 212 213 extern { 214 pub fn isalnum(c: c_int) -> c_int; 215 pub fn isalpha(c: c_int) -> c_int; 216 pub fn iscntrl(c: c_int) -> c_int; 217 pub fn isdigit(c: c_int) -> c_int; 218 pub fn isgraph(c: c_int) -> c_int; 219 pub fn islower(c: c_int) -> c_int; 220 pub fn isprint(c: c_int) -> c_int; 221 pub fn ispunct(c: c_int) -> c_int; 222 pub fn isspace(c: c_int) -> c_int; 223 pub fn isupper(c: c_int) -> c_int; 224 pub fn isxdigit(c: c_int) -> c_int; 225 pub fn tolower(c: c_int) -> c_int; 226 pub fn toupper(c: c_int) -> c_int; 227 pub fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE; 228 pub fn freopen(filename: *const c_char, mode: *const c_char, 229 file: *mut FILE) -> *mut FILE; 230 pub fn fflush(file: *mut FILE) -> c_int; 231 pub fn fclose(file: *mut FILE) -> c_int; 232 pub fn remove(filename: *const c_char) -> c_int; 233 pub fn rename(oldname: *const c_char, newname: *const c_char) -> c_int; 234 pub fn tmpfile() -> *mut FILE; 235 pub fn setvbuf(stream: *mut FILE, buffer: *mut c_char, mode: c_int, 236 size: size_t) -> c_int; 237 pub fn setbuf(stream: *mut FILE, buf: *mut c_char); 238 pub fn getchar() -> c_int; 239 pub fn putchar(c: c_int) -> c_int; 240 pub fn fgetc(stream: *mut FILE) -> c_int; 241 pub fn fgets(buf: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char; 242 pub fn fputc(c: c_int, stream: *mut FILE) -> c_int; 243 pub fn fputs(s: *const c_char, stream: *mut FILE) -> c_int; 244 pub fn puts(s: *const c_char) -> c_int; 245 pub fn ungetc(c: c_int, stream: *mut FILE) -> c_int; 246 pub fn fread(ptr: *mut c_void, size: size_t, nobj: size_t, 247 stream: *mut FILE) -> size_t; 248 pub fn fwrite(ptr: *const c_void, size: size_t, nobj: size_t, 249 stream: *mut FILE) -> size_t; 250 pub fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int; 251 pub fn ftell(stream: *mut FILE) -> c_long; 252 pub fn rewind(stream: *mut FILE); 253 pub fn fgetpos(stream: *mut FILE, ptr: *mut fpos_t) -> c_int; 254 pub fn fsetpos(stream: *mut FILE, ptr: *const fpos_t) -> c_int; 255 pub fn feof(stream: *mut FILE) -> c_int; 256 pub fn ferror(stream: *mut FILE) -> c_int; 257 pub fn perror(s: *const c_char); 258 pub fn atoi(s: *const c_char) -> c_int; 259 pub fn strtod(s: *const c_char, endp: *mut *mut c_char) -> c_double; 260 pub fn strtol(s: *const c_char, endp: *mut *mut c_char, 261 base: c_int) -> c_long; 262 pub fn strtoul(s: *const c_char, endp: *mut *mut c_char, 263 base: c_int) -> c_ulong; 264 pub fn calloc(nobj: size_t, size: size_t) -> *mut c_void; 265 pub fn malloc(size: size_t) -> *mut c_void; 266 pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; 267 pub fn free(p: *mut c_void); 268 pub fn abort() -> !; 269 pub fn exit(status: c_int) -> !; 270 pub fn _exit(status: c_int) -> !; 271 pub fn atexit(cb: extern fn()) -> c_int; 272 pub fn system(s: *const c_char) -> c_int; 273 pub fn getenv(s: *const c_char) -> *mut c_char; 274 275 pub fn strcpy(dst: *mut c_char, src: *const c_char) -> *mut c_char; 276 pub fn strncpy(dst: *mut c_char, src: *const c_char, 277 n: size_t) -> *mut c_char; 278 pub fn strcat(s: *mut c_char, ct: *const c_char) -> *mut c_char; 279 pub fn strncat(s: *mut c_char, ct: *const c_char, 280 n: size_t) -> *mut c_char; 281 pub fn strcmp(cs: *const c_char, ct: *const c_char) -> c_int; 282 pub fn strncmp(cs: *const c_char, ct: *const c_char, n: size_t) -> c_int; 283 pub fn strcoll(cs: *const c_char, ct: *const c_char) -> c_int; 284 pub fn strchr(cs: *const c_char, c: c_int) -> *mut c_char; 285 pub fn strrchr(cs: *const c_char, c: c_int) -> *mut c_char; 286 pub fn strspn(cs: *const c_char, ct: *const c_char) -> size_t; 287 pub fn strcspn(cs: *const c_char, ct: *const c_char) -> size_t; 288 pub fn strdup(cs: *const c_char) -> *mut c_char; 289 pub fn strpbrk(cs: *const c_char, ct: *const c_char) -> *mut c_char; 290 pub fn strstr(cs: *const c_char, ct: *const c_char) -> *mut c_char; 291 pub fn strlen(cs: *const c_char) -> size_t; 292 pub fn strnlen(cs: *const c_char, maxlen: size_t) -> size_t; 293 pub fn strerror(n: c_int) -> *mut c_char; 294 pub fn strtok(s: *mut c_char, t: *const c_char) -> *mut c_char; 295 pub fn strxfrm(s: *mut c_char, ct: *const c_char, n: size_t) -> size_t; 296 pub fn wcslen(buf: *const wchar_t) -> size_t; 297 pub fn wcstombs(dest: *mut c_char, src: *const wchar_t, 298 n: size_t) -> ::size_t; 299 300 pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; 301 pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; 302 pub fn memcpy(dest: *mut c_void, src: *const c_void, 303 n: size_t) -> *mut c_void; 304 pub fn memmove(dest: *mut c_void, src: *const c_void, 305 n: size_t) -> *mut c_void; 306 pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; 307 308 pub fn abs(i: c_int) -> c_int; 309 pub fn atof(s: *const c_char) -> c_double; 310 pub fn labs(i: c_long) -> c_long; 311 pub fn rand() -> c_int; 312 pub fn srand(seed: c_uint); 313 314 pub fn signal(signum: c_int, handler: sighandler_t) -> sighandler_t; 315 pub fn raise(signum: c_int) -> c_int; 316 317 #[link_name = "_chmod"] 318 pub fn chmod(path: *const c_char, mode: ::c_int) -> ::c_int; 319 #[link_name = "_wchmod"] 320 pub fn wchmod(path: *const wchar_t, mode: ::c_int) -> ::c_int; 321 #[link_name = "_mkdir"] 322 pub fn mkdir(path: *const c_char) -> ::c_int; 323 #[link_name = "_wrmdir"] 324 pub fn wrmdir(path: *const wchar_t) -> ::c_int; 325 #[link_name = "_fstat64"] 326 pub fn fstat(fildes: ::c_int, buf: *mut stat) -> ::c_int; 327 #[link_name = "_stat64"] 328 pub fn stat(path: *const c_char, buf: *mut stat) -> ::c_int; 329 #[link_name = "_wstat64"] 330 pub fn wstat(path: *const wchar_t, buf: *mut stat) -> ::c_int; 331 #[link_name = "_wutime64"] 332 pub fn wutime(file: *const wchar_t, buf: *mut utimbuf) -> ::c_int; 333 #[link_name = "_popen"] 334 pub fn popen(command: *const c_char, mode: *const c_char) -> *mut ::FILE; 335 #[link_name = "_pclose"] 336 pub fn pclose(stream: *mut ::FILE) -> ::c_int; 337 #[link_name = "_fdopen"] 338 pub fn fdopen(fd: ::c_int, mode: *const c_char) -> *mut ::FILE; 339 #[link_name = "_fileno"] 340 pub fn fileno(stream: *mut ::FILE) -> ::c_int; 341 #[link_name = "_open"] 342 pub fn open(path: *const c_char, oflag: ::c_int, ...) -> ::c_int; 343 #[link_name = "_wopen"] 344 pub fn wopen(path: *const wchar_t, oflag: ::c_int, ...) -> ::c_int; 345 #[link_name = "_creat"] 346 pub fn creat(path: *const c_char, mode: ::c_int) -> ::c_int; 347 #[link_name = "_access"] 348 pub fn access(path: *const c_char, amode: ::c_int) -> ::c_int; 349 #[link_name = "_chdir"] 350 pub fn chdir(dir: *const c_char) -> ::c_int; 351 #[link_name = "_close"] 352 pub fn close(fd: ::c_int) -> ::c_int; 353 #[link_name = "_dup"] 354 pub fn dup(fd: ::c_int) -> ::c_int; 355 #[link_name = "_dup2"] 356 pub fn dup2(src: ::c_int, dst: ::c_int) -> ::c_int; 357 #[link_name = "_execv"] 358 pub fn execv(prog: *const c_char, argv: *const *const c_char) -> ::intptr_t; 359 #[link_name = "_execve"] 360 pub fn execve(prog: *const c_char, argv: *const *const c_char, 361 envp: *const *const c_char) -> ::c_int; 362 #[link_name = "_execvp"] 363 pub fn execvp(c: *const c_char, argv: *const *const c_char) -> ::c_int; 364 #[link_name = "_execvpe"] 365 pub fn execvpe(c: *const c_char, argv: *const *const c_char, 366 envp: *const *const c_char) -> ::c_int; 367 #[link_name = "_getcwd"] 368 pub fn getcwd(buf: *mut c_char, size: ::c_int) -> *mut c_char; 369 #[link_name = "_getpid"] 370 pub fn getpid() -> ::c_int; 371 #[link_name = "_isatty"] 372 pub fn isatty(fd: ::c_int) -> ::c_int; 373 #[link_name = "_lseek"] 374 pub fn lseek(fd: ::c_int, offset: c_long, origin: ::c_int) -> c_long; 375 #[link_name = "_pipe"] 376 pub fn pipe(fds: *mut ::c_int, 377 psize: ::c_uint, 378 textmode: ::c_int) -> ::c_int; 379 #[link_name = "_read"] 380 pub fn read(fd: ::c_int, buf: *mut ::c_void, count: ::c_uint) -> ::c_int; 381 #[link_name = "_rmdir"] 382 pub fn rmdir(path: *const c_char) -> ::c_int; 383 #[link_name = "_unlink"] 384 pub fn unlink(c: *const c_char) -> ::c_int; 385 #[link_name = "_write"] 386 pub fn write(fd: ::c_int, buf: *const ::c_void, count: ::c_uint) -> ::c_int; 387 #[link_name = "_commit"] 388 pub fn commit(fd: ::c_int) -> ::c_int; 389 #[link_name = "_get_osfhandle"] 390 pub fn get_osfhandle(fd: ::c_int) -> ::intptr_t; 391 #[link_name = "_open_osfhandle"] 392 pub fn open_osfhandle(osfhandle: ::intptr_t, flags: ::c_int) -> ::c_int; 393 pub fn setlocale(category: ::c_int, locale: *const c_char) -> *mut c_char; 394 #[link_name = "_wsetlocale"] 395 pub fn wsetlocale(category: ::c_int, 396 locale: *const wchar_t) -> *mut wchar_t; 397 } 398 399 extern "system" { 400 pub fn listen(s: SOCKET, backlog: ::c_int) -> ::c_int; 401 pub fn accept(s: SOCKET, addr: *mut ::sockaddr, 402 addrlen: *mut ::c_int) -> SOCKET; 403 pub fn bind(s: SOCKET, name: *const ::sockaddr, 404 namelen: ::c_int) -> ::c_int; 405 pub fn connect(s: SOCKET, name: *const ::sockaddr, 406 namelen: ::c_int) -> ::c_int; 407 pub fn getpeername(s: SOCKET, name: *mut ::sockaddr, 408 nameln: *mut ::c_int) -> ::c_int; 409 pub fn getsockname(s: SOCKET, name: *mut ::sockaddr, 410 nameln: *mut ::c_int) -> ::c_int; 411 pub fn getsockopt(s: SOCKET, level: ::c_int, optname: ::c_int, 412 optval: *mut ::c_char, 413 optlen: *mut ::c_int) -> ::c_int; 414 pub fn recvfrom(s: SOCKET, buf: *mut ::c_char, len: ::c_int, 415 flags: ::c_int, from: *mut ::sockaddr, 416 fromlen: *mut ::c_int) -> ::c_int; 417 pub fn sendto(s: SOCKET, buf: *const ::c_char, len: ::c_int, 418 flags: ::c_int, to: *const ::sockaddr, 419 tolen: ::c_int) -> ::c_int; 420 pub fn setsockopt(s: SOCKET, level: ::c_int, optname: ::c_int, 421 optval: *const ::c_char, 422 optlen: ::c_int) -> ::c_int; 423 pub fn socket(af: ::c_int, socket_type: ::c_int, 424 protocol: ::c_int) -> SOCKET; 425 } 426 427 cfg_if! { 428 if #[cfg(libc_core_cvoid)] { 429 pub use ::ffi::c_void; 430 } else { 431 // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help 432 // enable more optimization opportunities around it recognizing things 433 // like malloc/free. 434 #[repr(u8)] 435 #[allow(missing_copy_implementations)] 436 #[allow(missing_debug_implementations)] 437 pub enum c_void { 438 // Two dummy variants so the #[repr] attribute can be used. 439 #[doc(hidden)] 440 __variant1, 441 #[doc(hidden)] 442 __variant2, 443 } 444 } 445 } 446 447 cfg_if! { 448 if #[cfg(all(target_env = "gnu"))] { 449 mod gnu; 450 pub use self::gnu::*; 451 } else if #[cfg(all(target_env = "msvc"))] { 452 mod msvc; 453 pub use self::msvc::*; 454 } else { 455 // Unknown target_env 456 } 457 } 458