]> git.lizzy.rs Git - rust.git/blob - src/libcore/libc.rs
53aaf5726dd0bf92aef2b6aa4c3067c67dcad0ac
[rust.git] / src / libcore / libc.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 /*!
12 * Bindings for the C standard library and other platform libraries
13 *
14 * This module contains bindings to the C standard library,
15 * organized into modules by their defining standard.
16 * Additionally, it contains some assorted platform-specific definitions.
17 * For convenience, most functions and types are reexported from `core::libc`,
18 * so `pub use core::libc::*` will import the available
19 * C bindings as appropriate for the target platform. The exact
20 * set of functions available are platform specific.
21 *
22 * *Note* Rustdoc does not indicate reexports currently. Also, because these
23 * definitions are platform-specific, some may not
24 * appear in the generated documentation.
25 *
26 * We consider the following specs reasonably normative with respect
27 * to interoperating with the C standard library (libc/msvcrt):
28 *
29 * * ISO 9899:1990 ('C95', 'ANSI C', 'Standard C'), NA1, 1995.
30 * * ISO 9899:1999 ('C99' or 'C9x').
31 * * ISO 9945:1988 / IEEE 1003.1-1988 ('POSIX.1').
32 * * ISO 9945:2001 / IEEE 1003.1-2001 ('POSIX:2001', 'SUSv3').
33 * * ISO 9945:2008 / IEEE 1003.1-2008 ('POSIX:2008', 'SUSv4').
34 *
35 * Note that any reference to the 1996 revision of POSIX, or any revs
36 * between 1990 (when '88 was approved at ISO) and 2001 (when the next
37 * actual revision-revision happened), are merely additions of other
38 * chapters (1b and 1c) outside the core interfaces.
39 *
40 * Despite having several names each, these are *reasonably* coherent
41 * point-in-time, list-of-definition sorts of specs. You can get each under a
42 * variety of names but will wind up with the same definition in each case.
43 *
44 * See standards(7) in linux-manpages for more details.
45 *
46 * Our interface to these libraries is complicated by the non-universality of
47 * conformance to any of them. About the only thing universally supported is
48 * the first (C95), beyond that definitions quickly become absent on various
49 * platforms.
50 *
51 * We therefore wind up dividing our module-space up (mostly for the sake of
52 * sanity while editing, filling-in-details and eliminating duplication) into
53 * definitions common-to-all (held in modules named c95, c99, posix88, posix01
54 * and posix08) and definitions that appear only on *some* platforms (named
55 * 'extra'). This would be things like significant OSX foundation kit, or
56 * win32 library kernel32.dll, or various fancy glibc, linux or BSD
57 * extensions.
58 *
59 * In addition to the per-platform 'extra' modules, we define a module of
60 * 'common BSD' libc routines that never quite made it into POSIX but show up
61 * in multiple derived systems. This is the 4.4BSD r2 / 1995 release, the
62 * final one from Berkeley after the lawsuits died down and the CSRG
63 * dissolved.
64 */
65
66 #[allow(non_camel_case_types)];
67
68 // Initial glob-exports mean that all the contents of all the modules
69 // wind up exported, if you're interested in writing platform-specific code.
70
71 pub use libc::types::common::c95::*;
72 pub use libc::types::common::c99::*;
73 pub use libc::types::common::posix88::*;
74 pub use libc::types::common::posix01::*;
75 pub use libc::types::common::posix08::*;
76 pub use libc::types::common::bsd44::*;
77 pub use libc::types::os::common::posix01::*;
78 pub use libc::types::os::arch::c95::*;
79 pub use libc::types::os::arch::c99::*;
80 pub use libc::types::os::arch::posix88::*;
81 pub use libc::types::os::arch::posix01::*;
82 pub use libc::types::os::arch::posix08::*;
83 pub use libc::types::os::arch::bsd44::*;
84 pub use libc::types::os::arch::extra::*;
85
86 pub use libc::consts::os::c95::*;
87 pub use libc::consts::os::c99::*;
88 pub use libc::consts::os::posix88::*;
89 pub use libc::consts::os::posix01::*;
90 pub use libc::consts::os::posix08::*;
91 pub use libc::consts::os::bsd44::*;
92 pub use libc::consts::os::extra::*;
93
94 pub use libc::funcs::c95::ctype::*;
95 pub use libc::funcs::c95::stdio::*;
96 pub use libc::funcs::c95::stdlib::*;
97 pub use libc::funcs::c95::string::*;
98
99 pub use libc::funcs::posix88::stat_::*;
100 pub use libc::funcs::posix88::stdio::*;
101 pub use libc::funcs::posix88::fcntl::*;
102 pub use libc::funcs::posix88::dirent::*;
103 pub use libc::funcs::posix88::unistd::*;
104
105 pub use libc::funcs::posix01::stat_::*;
106 pub use libc::funcs::posix01::unistd::*;
107 pub use libc::funcs::posix01::glob::*;
108 pub use libc::funcs::posix08::unistd::*;
109
110 pub use libc::funcs::bsd44::*;
111 pub use libc::funcs::extra::*;
112
113 #[cfg(target_os = "win32")]
114 pub use libc::funcs::extra::kernel32::*;
115 #[cfg(target_os = "win32")]
116 pub use libc::funcs::extra::msvcrt::*;
117
118 // Explicit export lists for the intersection (provided here) mean that
119 // you can write more-platform-agnostic code if you stick to just these
120 // symbols.
121
122 pub use libc::types::common::c95::{FILE, c_void, fpos_t};
123 pub use libc::types::common::posix88::{DIR, dirent_t};
124 pub use libc::types::os::arch::c95::{c_char, c_double, c_float, c_int};
125 pub use libc::types::os::arch::c95::{c_long, c_short, c_uchar, c_ulong};
126 pub use libc::types::os::arch::c95::{c_ushort, clock_t, ptrdiff_t};
127 pub use libc::types::os::arch::c95::{size_t, time_t};
128 pub use libc::types::os::arch::c99::{c_longlong, c_ulonglong, intptr_t};
129 pub use libc::types::os::arch::c99::{uintptr_t};
130 pub use libc::types::os::arch::posix88::{dev_t, dirent_t, ino_t, mode_t};
131 pub use libc::types::os::arch::posix88::{off_t, pid_t, ssize_t};
132
133 pub use libc::consts::os::c95::{_IOFBF, _IOLBF, _IONBF, BUFSIZ, EOF};
134 pub use libc::consts::os::c95::{EXIT_FAILURE, EXIT_SUCCESS};
135 pub use libc::consts::os::c95::{FILENAME_MAX, FOPEN_MAX, L_tmpnam};
136 pub use libc::consts::os::c95::{RAND_MAX, SEEK_CUR, SEEK_END};
137 pub use libc::consts::os::c95::{SEEK_SET, TMP_MAX};
138 pub use libc::consts::os::posix88::{F_OK, O_APPEND, O_CREAT, O_EXCL};
139 pub use libc::consts::os::posix88::{O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY};
140 pub use libc::consts::os::posix88::{R_OK, S_IEXEC, S_IFBLK, S_IFCHR};
141 pub use libc::consts::os::posix88::{S_IFDIR, S_IFIFO, S_IFMT, S_IFREG};
142 pub use libc::consts::os::posix88::{S_IREAD, S_IRUSR, S_IRWXU, S_IWUSR};
143 pub use libc::consts::os::posix88::{STDERR_FILENO, STDIN_FILENO};
144 pub use libc::consts::os::posix88::{STDOUT_FILENO, W_OK, X_OK};
145
146 pub use libc::funcs::c95::ctype::{isalnum, isalpha, iscntrl, isdigit};
147 pub use libc::funcs::c95::ctype::{islower, isprint, ispunct, isspace};
148 pub use libc::funcs::c95::ctype::{isupper, isxdigit, tolower, toupper};
149
150 pub use libc::funcs::c95::stdio::{fclose, feof, ferror, fflush, fgetc};
151 pub use libc::funcs::c95::stdio::{fgetpos, fgets, fopen, fputc, fputs};
152 pub use libc::funcs::c95::stdio::{fread, freopen, fseek, fsetpos, ftell};
153 pub use libc::funcs::c95::stdio::{fwrite, perror, puts, remove, rewind};
154 pub use libc::funcs::c95::stdio::{setbuf, setvbuf, tmpfile, ungetc};
155
156 pub use libc::funcs::c95::stdlib::{abort, abs, atof, atoi, calloc, exit};
157 pub use libc::funcs::c95::stdlib::{free, getenv, labs, malloc, rand};
158 pub use libc::funcs::c95::stdlib::{realloc, srand, strtod, strtol};
159 pub use libc::funcs::c95::stdlib::{strtoul, system};
160
161 pub use libc::funcs::c95::string::{memchr, memcmp, memcpy, memmove};
162 pub use libc::funcs::c95::string::{memset, strcat, strchr, strcmp};
163 pub use libc::funcs::c95::string::{strcoll, strcpy, strcspn, strerror};
164 pub use libc::funcs::c95::string::{strlen, strncat, strncmp, strncpy};
165 pub use libc::funcs::c95::string::{strpbrk, strrchr, strspn, strstr};
166 pub use libc::funcs::c95::string::{strtok, strxfrm};
167
168 pub use libc::funcs::posix88::fcntl::{open, creat};
169 pub use libc::funcs::posix88::stat_::{chmod, fstat, mkdir, stat};
170 pub use libc::funcs::posix88::stdio::{fdopen, fileno, pclose, popen};
171 pub use libc::funcs::posix88::unistd::{access, chdir, close, dup, dup2};
172 pub use libc::funcs::posix88::unistd::{execv, execve, execvp, getcwd};
173 pub use libc::funcs::posix88::unistd::{getpid, isatty, lseek, pipe, read};
174 pub use libc::funcs::posix88::unistd::{rmdir, unlink, write};
175
176
177 pub mod types {
178
179     // Types tend to vary *per architecture* so we pull their definitions out
180     // into this module.
181
182     // Standard types that are opaque or common, so are not per-target.
183     pub mod common {
184         pub mod c95 {
185             pub enum c_void {}
186             pub enum FILE {}
187             pub enum fpos_t {}
188         }
189         pub mod c99 {
190             pub type int8_t = i8;
191             pub type int16_t = i16;
192             pub type int32_t = i32;
193             pub type int64_t = i64;
194             pub type uint8_t = u8;
195             pub type uint16_t = u16;
196             pub type uint32_t = u32;
197             pub type uint64_t = u64;
198         }
199         pub mod posix88 {
200             pub enum DIR {}
201             pub enum dirent_t {}
202         }
203         pub mod posix01 {}
204         pub mod posix08 {}
205         pub mod bsd44 {}
206     }
207
208     // Standard types that are scalar but vary by OS and arch.
209
210     #[cfg(target_os = "linux")]
211     #[cfg(target_os = "android")]
212     pub mod os {
213         pub mod common {
214             pub mod posix01 {
215                 use libc::types::common::c95::{c_void};
216                 use libc::types::os::arch::c95::{c_char, size_t};
217                 pub struct glob_t {
218                     gl_pathc: size_t,
219                     gl_pathv: **c_char,
220                     gl_offs:  size_t,
221
222                     __unused1: *c_void,
223                     __unused2: *c_void,
224                     __unused3: *c_void,
225                     __unused4: *c_void,
226                     __unused5: *c_void,
227                 }
228             }
229         }
230
231         #[cfg(target_arch = "x86")]
232         #[cfg(target_arch = "arm")]
233         #[cfg(target_arch = "mips")]
234         pub mod arch {
235             pub mod c95 {
236                 pub type c_char = i8;
237                 pub type c_schar = i8;
238                 pub type c_uchar = u8;
239                 pub type c_short = i16;
240                 pub type c_ushort = u16;
241                 pub type c_int = i32;
242                 pub type c_uint = u32;
243                 pub type c_long = i32;
244                 pub type c_ulong = u32;
245                 pub type c_float = f32;
246                 pub type c_double = f64;
247                 pub type size_t = u32;
248                 pub type ptrdiff_t = i32;
249                 pub type clock_t = i32;
250                 pub type time_t = i32;
251                 pub type wchar_t = i32;
252             }
253             pub mod c99 {
254                 pub type c_longlong = i64;
255                 pub type c_ulonglong = u64;
256                 pub type intptr_t = int;
257                 pub type uintptr_t = uint;
258             }
259             pub mod posix88 {
260                 pub type off_t = i32;
261                 pub type dev_t = u64;
262                 pub type ino_t = u32;
263                 pub type pid_t = i32;
264                 pub type uid_t = u32;
265                 pub type gid_t = u32;
266                 pub type useconds_t = u32;
267                 pub type mode_t = u32;
268                 pub type ssize_t = i32;
269             }
270             pub mod posix01 {
271                 use libc::types::os::arch::c95::{c_int, c_short, c_long,
272                                                  time_t};
273                 use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
274                 use libc::types::os::arch::posix88::{mode_t, off_t};
275                 use libc::types::os::arch::posix88::{uid_t};
276
277                 pub type nlink_t = u32;
278                 pub type blksize_t = i32;
279                 pub type blkcnt_t = i32;
280                 pub struct stat {
281                     st_dev: dev_t,
282                     __pad1: c_short,
283                     st_ino: ino_t,
284                     st_mode: mode_t,
285                     st_nlink: nlink_t,
286                     st_uid: uid_t,
287                     st_gid: gid_t,
288                     st_rdev: dev_t,
289                     __pad2: c_short,
290                     st_size: off_t,
291                     st_blksize: blksize_t,
292                     st_blocks: blkcnt_t,
293                     st_atime: time_t,
294                     st_atime_nsec: c_long,
295                     st_mtime: time_t,
296                     st_mtime_nsec: c_long,
297                     st_ctime: time_t,
298                     st_ctime_nsec: c_long,
299                     __unused4: c_long,
300                     __unused5: c_long,
301                 }
302             }
303             pub mod posix08 {}
304             pub mod bsd44 {}
305             pub mod extra {}
306         }
307
308         #[cfg(target_arch = "x86_64")]
309         pub mod arch {
310             pub mod c95 {
311                 pub type c_char = i8;
312                 pub type c_schar = i8;
313                 pub type c_uchar = u8;
314                 pub type c_short = i16;
315                 pub type c_ushort = u16;
316                 pub type c_int = i32;
317                 pub type c_uint = u32;
318                 pub type c_long = i64;
319                 pub type c_ulong = u64;
320                 pub type c_float = f32;
321                 pub type c_double = f64;
322                 pub type size_t = u64;
323                 pub type ptrdiff_t = i64;
324                 pub type clock_t = i64;
325                 pub type time_t = i64;
326                 pub type wchar_t = i32;
327             }
328             pub mod c99 {
329                 pub type c_longlong = i64;
330                 pub type c_ulonglong = u64;
331                 pub type intptr_t = int;
332                 pub type uintptr_t = uint;
333             }
334             pub mod posix88 {
335                 pub type off_t = i64;
336                 pub type dev_t = u64;
337                 pub type ino_t = u64;
338                 pub type pid_t = i32;
339                 pub type uid_t = u32;
340                 pub type gid_t = u32;
341                 pub type useconds_t = u32;
342                 pub type mode_t = u32;
343                 pub type ssize_t = i64;
344             }
345             pub mod posix01 {
346                 use libc::types::os::arch::c95::{c_int, c_long, time_t};
347                 use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
348                 use libc::types::os::arch::posix88::{mode_t, off_t};
349                 use libc::types::os::arch::posix88::{uid_t};
350
351                 pub type nlink_t = u64;
352                 pub type blksize_t = i64;
353                 pub type blkcnt_t = i64;
354                 pub struct stat {
355                     st_dev: dev_t,
356                     st_ino: ino_t,
357                     st_nlink: nlink_t,
358                     st_mode: mode_t,
359                     st_uid: uid_t,
360                     st_gid: gid_t,
361                     __pad0: c_int,
362                     st_rdev: dev_t,
363                     st_size: off_t,
364                     st_blksize: blksize_t,
365                     st_blocks: blkcnt_t,
366                     st_atime: time_t,
367                     st_atime_nsec: c_long,
368                     st_mtime: time_t,
369                     st_mtime_nsec: c_long,
370                     st_ctime: time_t,
371                     st_ctime_nsec: c_long,
372                     __unused: [c_long, ..3],
373                 }
374             }
375             pub mod posix08 {
376             }
377             pub mod bsd44 {
378             }
379             pub mod extra {
380             }
381         }
382     }
383
384     #[cfg(target_os = "freebsd")]
385     pub mod os {
386         pub mod common {
387             pub mod posix01 {
388                 use libc::types::common::c95::{c_void};
389                 use libc::types::os::arch::c95::{c_char, c_int, size_t};
390                 pub struct glob_t {
391                     gl_pathc:  size_t,
392                     __unused1: size_t,
393                     gl_offs:   size_t,
394                     __unused2: c_int,
395                     gl_pathv:  **c_char,
396
397                     __unused3: *c_void,
398
399                     __unused4: *c_void,
400                     __unused5: *c_void,
401                     __unused6: *c_void,
402                     __unused7: *c_void,
403                     __unused8: *c_void,
404                 }
405             }
406         }
407
408         #[cfg(target_arch = "x86_64")]
409         pub mod arch {
410             pub mod c95 {
411                 pub type c_char = i8;
412                 pub type c_schar = i8;
413                 pub type c_uchar = u8;
414                 pub type c_short = i16;
415                 pub type c_ushort = u16;
416                 pub type c_int = i32;
417                 pub type c_uint = u32;
418                 pub type c_long = i64;
419                 pub type c_ulong = u64;
420                 pub type c_float = f32;
421                 pub type c_double = f64;
422                 pub type size_t = u64;
423                 pub type ptrdiff_t = i64;
424                 pub type clock_t = i32;
425                 pub type time_t = i64;
426                 pub type wchar_t = i32;
427             }
428             pub mod c99 {
429                 pub type c_longlong = i64;
430                 pub type c_ulonglong = u64;
431                 pub type intptr_t = int;
432                 pub type uintptr_t = uint;
433             }
434             pub mod posix88 {
435                 pub type off_t = i64;
436                 pub type dev_t = u32;
437                 pub type ino_t = u32;
438                 pub type pid_t = i32;
439                 pub type uid_t = u32;
440                 pub type gid_t = u32;
441                 pub type useconds_t = u32;
442                 pub type mode_t = u16;
443                 pub type ssize_t = i64;
444             }
445             pub mod posix01 {
446                 use libc::types::common::c99::{uint8_t, uint32_t, int32_t};
447                 use libc::types::os::arch::c95::{c_long, time_t};
448                 use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
449                 use libc::types::os::arch::posix88::{mode_t, off_t};
450                 use libc::types::os::arch::posix88::{uid_t};
451
452                 pub type nlink_t = u16;
453                 pub type blksize_t = i64;
454                 pub type blkcnt_t = i64;
455                 pub type fflags_t = u32;
456                 pub struct stat {
457                     st_dev: dev_t,
458                     st_ino: ino_t,
459                     st_mode: mode_t,
460                     st_nlink: nlink_t,
461                     st_uid: uid_t,
462                     st_gid: gid_t,
463                     st_rdev: dev_t,
464                     st_atime: time_t,
465                     st_atime_nsec: c_long,
466                     st_mtime: time_t,
467                     st_mtime_nsec: c_long,
468                     st_ctime: time_t,
469                     st_ctime_nsec: c_long,
470                     st_size: off_t,
471                     st_blocks: blkcnt_t,
472                     st_blksize: blksize_t,
473                     st_flags: fflags_t,
474                     st_gen: uint32_t,
475                     st_lspare: int32_t,
476                     st_birthtime: time_t,
477                     st_birthtime_nsec: c_long,
478                     __unused: [uint8_t, ..2],
479                 }
480             }
481             pub mod posix08 {
482             }
483             pub mod bsd44 {
484             }
485             pub mod extra {
486             }
487         }
488     }
489
490     #[cfg(target_os = "win32")]
491     pub mod os {
492         pub mod common {
493             pub mod posix01 {
494                 use libc::types::os::arch::c95::{c_int, c_short};
495                 use libc::types::os::arch::extra::{int64, time64_t};
496                 use libc::types::os::arch::posix88::{dev_t, ino_t};
497                 use libc::types::os::arch::posix88::mode_t;
498
499                 // Note: this is the struct called stat64 in win32. Not stat,
500                 // nor stati64.
501                 pub struct stat {
502                     st_dev: dev_t,
503                     st_ino: ino_t,
504                     st_mode: mode_t,
505                     st_nlink: c_short,
506                     st_uid: c_short,
507                     st_gid: c_short,
508                     st_rdev: dev_t,
509                     st_size: int64,
510                     st_atime: time64_t,
511                     st_mtime: time64_t,
512                     st_ctime: time64_t,
513                 }
514             }
515         }
516
517         #[cfg(target_arch = "x86")]
518         pub mod arch {
519             pub mod c95 {
520                 pub type c_char = i8;
521                 pub type c_schar = i8;
522                 pub type c_uchar = u8;
523                 pub type c_short = i16;
524                 pub type c_ushort = u16;
525                 pub type c_int = i32;
526                 pub type c_uint = u32;
527                 pub type c_long = i32;
528                 pub type c_ulong = u32;
529                 pub type c_float = f32;
530                 pub type c_double = f64;
531                 pub type size_t = u32;
532                 pub type ptrdiff_t = i32;
533                 pub type clock_t = i32;
534                 pub type time_t = i32;
535                 pub type wchar_t = u16;
536             }
537             pub mod c99 {
538                 pub type c_longlong = i64;
539                 pub type c_ulonglong = u64;
540                 pub type intptr_t = int;
541                 pub type uintptr_t = uint;
542             }
543             pub mod posix88 {
544                 pub type off_t = i32;
545                 pub type dev_t = u32;
546                 pub type ino_t = i16;
547                 pub type pid_t = i32;
548                 pub type useconds_t = u32;
549                 pub type mode_t = u16;
550                 pub type ssize_t = i32;
551             }
552             pub mod posix01 {
553             }
554             pub mod posix08 {
555             }
556             pub mod bsd44 {
557             }
558             pub mod extra {
559                 use libc::types::common::c95::c_void;
560                 use libc::types::os::arch::c95::{c_char, c_int, c_uint};
561                 use libc::types::os::arch::c95::{c_long, c_ulong};
562                 use libc::types::os::arch::c95::{wchar_t};
563                 use libc::types::os::arch::c99::{c_ulonglong};
564
565                 pub type BOOL = c_int;
566                 pub type BYTE = u8;
567                 pub type CCHAR = c_char;
568                 pub type CHAR = c_char;
569
570                 pub type DWORD = c_ulong;
571                 pub type DWORDLONG = c_ulonglong;
572
573                 pub type HANDLE = LPVOID;
574                 pub type HMODULE = c_uint;
575
576                 pub type LONG_PTR = c_long;
577
578                 pub type LPCWSTR = *WCHAR;
579                 pub type LPCSTR = *CHAR;
580                 pub type LPCTSTR = *CHAR;
581                 pub type LPTCH = *CHAR;
582
583                 pub type LPWSTR = *mut WCHAR;
584                 pub type LPSTR = *mut CHAR;
585
586                 // Not really, but opaque to us.
587                 pub type LPSECURITY_ATTRIBUTES = LPVOID;
588
589                 pub type LPVOID = *mut c_void;
590                 pub type LPWORD = *mut WORD;
591
592                 pub type LRESULT = LONG_PTR;
593                 pub type PBOOL = *mut BOOL;
594                 pub type WCHAR = wchar_t;
595                 pub type WORD = u16;
596
597                 pub type time64_t = i64;
598                 pub type int64 = i64;
599             }
600         }
601     }
602
603     #[cfg(target_os = "macos")]
604     pub mod os {
605         pub mod common {
606             pub mod posix01 {
607                 use libc::types::common::c95::{c_void};
608                 use libc::types::os::arch::c95::{c_char, c_int, size_t};
609                 pub struct glob_t {
610                     gl_pathc:  size_t,
611                     __unused1: c_int,
612                     gl_offs:   size_t,
613                     __unused2: c_int,
614                     gl_pathv:  **c_char,
615
616                     __unused3: *c_void,
617
618                     __unused4: *c_void,
619                     __unused5: *c_void,
620                     __unused6: *c_void,
621                     __unused7: *c_void,
622                     __unused8: *c_void,
623                 }
624             }
625         }
626
627         #[cfg(target_arch = "x86")]
628         pub mod arch {
629             pub mod c95 {
630                 pub type c_char = i8;
631                 pub type c_schar = i8;
632                 pub type c_uchar = u8;
633                 pub type c_short = i16;
634                 pub type c_ushort = u16;
635                 pub type c_int = i32;
636                 pub type c_uint = u32;
637                 pub type c_long = i32;
638                 pub type c_ulong = u32;
639                 pub type c_float = f32;
640                 pub type c_double = f64;
641                 pub type size_t = u32;
642                 pub type ptrdiff_t = i32;
643                 pub type clock_t = u32;
644                 pub type time_t = i32;
645                 pub type wchar_t = i32;
646             }
647             pub mod c99 {
648                 pub type c_longlong = i64;
649                 pub type c_ulonglong = u64;
650                 pub type intptr_t = int;
651                 pub type uintptr_t = uint;
652             }
653             pub mod posix88 {
654                 pub type off_t = i64;
655                 pub type dev_t = i32;
656                 pub type ino_t = u64;
657                 pub type pid_t = i32;
658                 pub type uid_t = u32;
659                 pub type gid_t = u32;
660                 pub type useconds_t = u32;
661                 pub type mode_t = u16;
662                 pub type ssize_t = i32;
663             }
664             pub mod posix01 {
665                 use libc::types::common::c99::{int32_t, int64_t, uint32_t};
666                 use libc::types::os::arch::c95::{c_long, time_t};
667                 use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t,
668                                                      mode_t, off_t, uid_t};
669
670                 pub type nlink_t = u16;
671                 pub type blksize_t = i64;
672                 pub type blkcnt_t = i32;
673
674                 pub struct stat {
675                     st_dev: dev_t,
676                     st_mode: mode_t,
677                     st_nlink: nlink_t,
678                     st_ino: ino_t,
679                     st_uid: uid_t,
680                     st_gid: gid_t,
681                     st_rdev: dev_t,
682                     st_atime: time_t,
683                     st_atime_nsec: c_long,
684                     st_mtime: time_t,
685                     st_mtime_nsec: c_long,
686                     st_ctime: time_t,
687                     st_ctime_nsec: c_long,
688                     st_birthtime: time_t,
689                     st_birthtime_nsec: c_long,
690                     st_size: off_t,
691                     st_blocks: blkcnt_t,
692                     st_blksize: blksize_t,
693                     st_flags: uint32_t,
694                     st_gen: uint32_t,
695                     st_lspare: int32_t,
696                     st_qspare: [int64_t, ..2],
697                 }
698             }
699             pub mod posix08 {
700             }
701             pub mod bsd44 {
702             }
703             pub mod extra {
704             }
705         }
706
707         #[cfg(target_arch = "x86_64")]
708         pub mod arch {
709             pub mod c95 {
710                 pub type c_char = i8;
711                 pub type c_schar = i8;
712                 pub type c_uchar = u8;
713                 pub type c_short = i16;
714                 pub type c_ushort = u16;
715                 pub type c_int = i32;
716                 pub type c_uint = u32;
717                 pub type c_long = i64;
718                 pub type c_ulong = u64;
719                 pub type c_float = f32;
720                 pub type c_double = f64;
721                 pub type size_t = u64;
722                 pub type ptrdiff_t = i64;
723                 pub type clock_t = u64;
724                 pub type time_t = i64;
725                 pub type wchar_t = i32;
726             }
727             pub mod c99 {
728                 pub type c_longlong = i64;
729                 pub type c_ulonglong = u64;
730                 pub type intptr_t = int;
731                 pub type uintptr_t = uint;
732             }
733             pub mod posix88 {
734                 pub type off_t = i64;
735                 pub type dev_t = i32;
736                 pub type ino_t = u64;
737                 pub type pid_t = i32;
738                 pub type uid_t = u32;
739                 pub type gid_t = u32;
740                 pub type useconds_t = u32;
741                 pub type mode_t = u16;
742                 pub type ssize_t = i64;
743             }
744             pub mod posix01 {
745                 use libc::types::common::c99::{int32_t, int64_t};
746                 use libc::types::common::c99::{uint32_t};
747                 use libc::types::os::arch::c95::{c_long, time_t};
748                 use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
749                 use libc::types::os::arch::posix88::{mode_t, off_t, uid_t};
750
751                 pub type nlink_t = u16;
752                 pub type blksize_t = i64;
753                 pub type blkcnt_t = i32;
754
755                 pub struct stat {
756                     st_dev: dev_t,
757                     st_mode: mode_t,
758                     st_nlink: nlink_t,
759                     st_ino: ino_t,
760                     st_uid: uid_t,
761                     st_gid: gid_t,
762                     st_rdev: dev_t,
763                     st_atime: time_t,
764                     st_atime_nsec: c_long,
765                     st_mtime: time_t,
766                     st_mtime_nsec: c_long,
767                     st_ctime: time_t,
768                     st_ctime_nsec: c_long,
769                     st_birthtime: time_t,
770                     st_birthtime_nsec: c_long,
771                     st_size: off_t,
772                     st_blocks: blkcnt_t,
773                     st_blksize: blksize_t,
774                     st_flags: uint32_t,
775                     st_gen: uint32_t,
776                     st_lspare: int32_t,
777                     st_qspare: [int64_t, ..2],
778                 }
779             }
780             pub mod posix08 {
781             }
782             pub mod bsd44 {
783             }
784             pub mod extra {
785             }
786         }
787     }
788 }
789
790 pub mod consts {
791     // Consts tend to vary per OS so we pull their definitions out
792     // into this module.
793
794     #[cfg(target_os = "win32")]
795     pub mod os {
796         pub mod c95 {
797             pub static EXIT_FAILURE : int = 1;
798             pub static EXIT_SUCCESS : int = 0;
799             pub static RAND_MAX : int = 32767;
800             pub static EOF : int = -1;
801             pub static SEEK_SET : int = 0;
802             pub static SEEK_CUR : int = 1;
803             pub static SEEK_END : int = 2;
804             pub static _IOFBF : int = 0;
805             pub static _IONBF : int = 4;
806             pub static _IOLBF : int = 64;
807             pub static BUFSIZ : uint = 512_u;
808             pub static FOPEN_MAX : uint = 20_u;
809             pub static FILENAME_MAX : uint = 260_u;
810             pub static L_tmpnam : uint = 16_u;
811             pub static TMP_MAX : uint = 32767_u;
812         }
813         pub mod c99 {
814         }
815         pub mod posix88 {
816             pub static O_RDONLY : int = 0;
817             pub static O_WRONLY : int = 1;
818             pub static O_RDWR : int = 2;
819             pub static O_APPEND : int = 8;
820             pub static O_CREAT : int = 256;
821             pub static O_EXCL : int = 1024;
822             pub static O_TRUNC : int = 512;
823             pub static S_IFIFO : int = 4096;
824             pub static S_IFCHR : int = 8192;
825             pub static S_IFBLK : int = 12288;
826             pub static S_IFDIR : int = 16384;
827             pub static S_IFREG : int = 32768;
828             pub static S_IFMT : int = 61440;
829             pub static S_IEXEC : int = 64;
830             pub static S_IWRITE : int = 128;
831             pub static S_IREAD : int = 256;
832             pub static S_IRWXU : int = 448;
833             pub static S_IXUSR : int = 64;
834             pub static S_IWUSR : int = 128;
835             pub static S_IRUSR : int = 256;
836             pub static F_OK : int = 0;
837             pub static R_OK : int = 4;
838             pub static W_OK : int = 2;
839             pub static X_OK : int = 1;
840             pub static STDIN_FILENO : int = 0;
841             pub static STDOUT_FILENO : int = 1;
842             pub static STDERR_FILENO : int = 2;
843         }
844         pub mod posix01 {
845         }
846         pub mod posix08 {
847         }
848         pub mod bsd44 {
849         }
850         pub mod extra {
851             pub static O_TEXT : int = 16384;
852             pub static O_BINARY : int = 32768;
853             pub static O_NOINHERIT: int = 128;
854
855             pub static ERROR_SUCCESS : int = 0;
856             pub static ERROR_INSUFFICIENT_BUFFER : int = 122;
857             pub static INVALID_HANDLE_VALUE: int = -1;
858         }
859     }
860
861
862     #[cfg(target_os = "linux")]
863     #[cfg(target_os = "android")]
864     pub mod os {
865         pub mod c95 {
866             pub static EXIT_FAILURE : int = 1;
867             pub static EXIT_SUCCESS : int = 0;
868             pub static RAND_MAX : int = 2147483647;
869             pub static EOF : int = -1;
870             pub static SEEK_SET : int = 0;
871             pub static SEEK_CUR : int = 1;
872             pub static SEEK_END : int = 2;
873             pub static _IOFBF : int = 0;
874             pub static _IONBF : int = 2;
875             pub static _IOLBF : int = 1;
876             pub static BUFSIZ : uint = 8192_u;
877             pub static FOPEN_MAX : uint = 16_u;
878             pub static FILENAME_MAX : uint = 4096_u;
879             pub static L_tmpnam : uint = 20_u;
880             pub static TMP_MAX : uint = 238328_u;
881         }
882         pub mod c99 {
883         }
884         pub mod posix88 {
885             pub static O_RDONLY : int = 0;
886             pub static O_WRONLY : int = 1;
887             pub static O_RDWR : int = 2;
888             pub static O_APPEND : int = 1024;
889             pub static O_CREAT : int = 64;
890             pub static O_EXCL : int = 128;
891             pub static O_TRUNC : int = 512;
892             pub static S_IFIFO : int = 4096;
893             pub static S_IFCHR : int = 8192;
894             pub static S_IFBLK : int = 24576;
895             pub static S_IFDIR : int = 16384;
896             pub static S_IFREG : int = 32768;
897             pub static S_IFMT : int = 61440;
898             pub static S_IEXEC : int = 64;
899             pub static S_IWRITE : int = 128;
900             pub static S_IREAD : int = 256;
901             pub static S_IRWXU : int = 448;
902             pub static S_IXUSR : int = 64;
903             pub static S_IWUSR : int = 128;
904             pub static S_IRUSR : int = 256;
905             pub static F_OK : int = 0;
906             pub static R_OK : int = 4;
907             pub static W_OK : int = 2;
908             pub static X_OK : int = 1;
909             pub static STDIN_FILENO : int = 0;
910             pub static STDOUT_FILENO : int = 1;
911             pub static STDERR_FILENO : int = 2;
912             pub static F_LOCK : int = 1;
913             pub static F_TEST : int = 3;
914             pub static F_TLOCK : int = 2;
915             pub static F_ULOCK : int = 0;
916             pub static SIGHUP : int = 1;
917             pub static SIGINT : int = 2;
918             pub static SIGQUIT : int = 3;
919             pub static SIGILL : int = 4;
920             pub static SIGABRT : int = 6;
921             pub static SIGFPE : int = 8;
922             pub static SIGKILL : int = 9;
923             pub static SIGSEGV : int = 11;
924             pub static SIGPIPE : int = 13;
925             pub static SIGALRM : int = 14;
926             pub static SIGTERM : int = 15;
927         }
928         pub mod posix01 {
929             pub static SIGTRAP : int = 5;
930
931             pub static GLOB_ERR      : int = 1 << 0;
932             pub static GLOB_MARK     : int = 1 << 1;
933             pub static GLOB_NOSORT   : int = 1 << 2;
934             pub static GLOB_DOOFFS   : int = 1 << 3;
935             pub static GLOB_NOCHECK  : int = 1 << 4;
936             pub static GLOB_APPEND   : int = 1 << 5;
937             pub static GLOB_NOESCAPE : int = 1 << 6;
938
939             pub static GLOB_NOSPACE  : int = 1;
940             pub static GLOB_ABORTED  : int = 2;
941             pub static GLOB_NOMATCH  : int = 3;
942         }
943         pub mod posix08 {
944         }
945         pub mod bsd44 {
946         }
947         pub mod extra {
948             pub static O_RSYNC : int = 1052672;
949             pub static O_DSYNC : int = 4096;
950             pub static O_SYNC : int = 1052672;
951         }
952     }
953
954     #[cfg(target_os = "freebsd")]
955     pub mod os {
956         pub mod c95 {
957             pub static EXIT_FAILURE : int = 1;
958             pub static EXIT_SUCCESS : int = 0;
959             pub static RAND_MAX : int = 2147483647;
960             pub static EOF : int = -1;
961             pub static SEEK_SET : int = 0;
962             pub static SEEK_CUR : int = 1;
963             pub static SEEK_END : int = 2;
964             pub static _IOFBF : int = 0;
965             pub static _IONBF : int = 2;
966             pub static _IOLBF : int = 1;
967             pub static BUFSIZ : uint = 1024_u;
968             pub static FOPEN_MAX : uint = 20_u;
969             pub static FILENAME_MAX : uint = 1024_u;
970             pub static L_tmpnam : uint = 1024_u;
971             pub static TMP_MAX : uint = 308915776_u;
972         }
973         pub mod c99 {
974         }
975         pub mod posix88 {
976             pub static O_RDONLY : int = 0;
977             pub static O_WRONLY : int = 1;
978             pub static O_RDWR : int = 2;
979             pub static O_APPEND : int = 8;
980             pub static O_CREAT : int = 512;
981             pub static O_EXCL : int = 2048;
982             pub static O_TRUNC : int = 1024;
983             pub static S_IFIFO : int = 4096;
984             pub static S_IFCHR : int = 8192;
985             pub static S_IFBLK : int = 24576;
986             pub static S_IFDIR : int = 16384;
987             pub static S_IFREG : int = 32768;
988             pub static S_IFMT : int = 61440;
989             pub static S_IEXEC : int = 64;
990             pub static S_IWRITE : int = 128;
991             pub static S_IREAD : int = 256;
992             pub static S_IRWXU : int = 448;
993             pub static S_IXUSR : int = 64;
994             pub static S_IWUSR : int = 128;
995             pub static S_IRUSR : int = 256;
996             pub static F_OK : int = 0;
997             pub static R_OK : int = 4;
998             pub static W_OK : int = 2;
999             pub static X_OK : int = 1;
1000             pub static STDIN_FILENO : int = 0;
1001             pub static STDOUT_FILENO : int = 1;
1002             pub static STDERR_FILENO : int = 2;
1003             pub static F_LOCK : int = 1;
1004             pub static F_TEST : int = 3;
1005             pub static F_TLOCK : int = 2;
1006             pub static F_ULOCK : int = 0;
1007             pub static SIGHUP : int = 1;
1008             pub static SIGINT : int = 2;
1009             pub static SIGQUIT : int = 3;
1010             pub static SIGILL : int = 4;
1011             pub static SIGABRT : int = 6;
1012             pub static SIGFPE : int = 8;
1013             pub static SIGKILL : int = 9;
1014             pub static SIGSEGV : int = 11;
1015             pub static SIGPIPE : int = 13;
1016             pub static SIGALRM : int = 14;
1017             pub static SIGTERM : int = 15;
1018         }
1019         pub mod posix01 {
1020             pub static SIGTRAP : int = 5;
1021
1022             pub static GLOB_APPEND   : int = 0x0001;
1023             pub static GLOB_DOOFFS   : int = 0x0002;
1024             pub static GLOB_ERR      : int = 0x0004;
1025             pub static GLOB_MARK     : int = 0x0008;
1026             pub static GLOB_NOCHECK  : int = 0x0010;
1027             pub static GLOB_NOSORT   : int = 0x0020;
1028             pub static GLOB_NOESCAPE : int = 0x2000;
1029
1030             pub static GLOB_NOSPACE  : int = -1;
1031             pub static GLOB_ABORTED  : int = -2;
1032             pub static GLOB_NOMATCH  : int = -3;
1033         }
1034         pub mod posix08 {
1035         }
1036         pub mod bsd44 {
1037         }
1038         pub mod extra {
1039             pub static O_SYNC : int = 128;
1040             pub static CTL_KERN: int = 1;
1041             pub static KERN_PROC: int = 14;
1042             pub static KERN_PROC_PATHNAME: int = 12;
1043         }
1044     }
1045
1046     #[cfg(target_os = "macos")]
1047     pub mod os {
1048         pub mod c95 {
1049             pub static EXIT_FAILURE : int = 1;
1050             pub static EXIT_SUCCESS : int = 0;
1051             pub static RAND_MAX : int = 2147483647;
1052             pub static EOF : int = -1;
1053             pub static SEEK_SET : int = 0;
1054             pub static SEEK_CUR : int = 1;
1055             pub static SEEK_END : int = 2;
1056             pub static _IOFBF : int = 0;
1057             pub static _IONBF : int = 2;
1058             pub static _IOLBF : int = 1;
1059             pub static BUFSIZ : uint = 1024_u;
1060             pub static FOPEN_MAX : uint = 20_u;
1061             pub static FILENAME_MAX : uint = 1024_u;
1062             pub static L_tmpnam : uint = 1024_u;
1063             pub static TMP_MAX : uint = 308915776_u;
1064         }
1065         pub mod c99 {
1066         }
1067         pub mod posix88 {
1068             pub static O_RDONLY : int = 0;
1069             pub static O_WRONLY : int = 1;
1070             pub static O_RDWR : int = 2;
1071             pub static O_APPEND : int = 8;
1072             pub static O_CREAT : int = 512;
1073             pub static O_EXCL : int = 2048;
1074             pub static O_TRUNC : int = 1024;
1075             pub static S_IFIFO : int = 4096;
1076             pub static S_IFCHR : int = 8192;
1077             pub static S_IFBLK : int = 24576;
1078             pub static S_IFDIR : int = 16384;
1079             pub static S_IFREG : int = 32768;
1080             pub static S_IFMT : int = 61440;
1081             pub static S_IEXEC : int = 64;
1082             pub static S_IWRITE : int = 128;
1083             pub static S_IREAD : int = 256;
1084             pub static S_IRWXU : int = 448;
1085             pub static S_IXUSR : int = 64;
1086             pub static S_IWUSR : int = 128;
1087             pub static S_IRUSR : int = 256;
1088             pub static F_OK : int = 0;
1089             pub static R_OK : int = 4;
1090             pub static W_OK : int = 2;
1091             pub static X_OK : int = 1;
1092             pub static STDIN_FILENO : int = 0;
1093             pub static STDOUT_FILENO : int = 1;
1094             pub static STDERR_FILENO : int = 2;
1095             pub static F_LOCK : int = 1;
1096             pub static F_TEST : int = 3;
1097             pub static F_TLOCK : int = 2;
1098             pub static F_ULOCK : int = 0;
1099             pub static SIGHUP : int = 1;
1100             pub static SIGINT : int = 2;
1101             pub static SIGQUIT : int = 3;
1102             pub static SIGILL : int = 4;
1103             pub static SIGABRT : int = 6;
1104             pub static SIGFPE : int = 8;
1105             pub static SIGKILL : int = 9;
1106             pub static SIGSEGV : int = 11;
1107             pub static SIGPIPE : int = 13;
1108             pub static SIGALRM : int = 14;
1109             pub static SIGTERM : int = 15;
1110         }
1111         pub mod posix01 {
1112             pub static SIGTRAP : int = 5;
1113
1114             pub static GLOB_APPEND   : int = 0x0001;
1115             pub static GLOB_DOOFFS   : int = 0x0002;
1116             pub static GLOB_ERR      : int = 0x0004;
1117             pub static GLOB_MARK     : int = 0x0008;
1118             pub static GLOB_NOCHECK  : int = 0x0010;
1119             pub static GLOB_NOSORT   : int = 0x0020;
1120             pub static GLOB_NOESCAPE : int = 0x2000;
1121
1122             pub static GLOB_NOSPACE  : int = -1;
1123             pub static GLOB_ABORTED  : int = -2;
1124             pub static GLOB_NOMATCH  : int = -3;
1125         }
1126         pub mod posix08 {
1127         }
1128         pub mod bsd44 {
1129         }
1130         pub mod extra {
1131             pub static O_DSYNC : int = 4194304;
1132             pub static O_SYNC : int = 128;
1133             pub static F_FULLFSYNC : int = 51;
1134         }
1135     }
1136 }
1137
1138
1139 pub mod funcs {
1140     // Thankfull most of c95 is universally available and does not vary by OS
1141     // or anything. The same is not true of POSIX.
1142
1143     pub mod c95 {
1144         #[nolink]
1145         #[abi = "cdecl"]
1146         pub mod ctype {
1147             use libc::types::os::arch::c95::{c_char, c_int};
1148
1149             pub extern {
1150                 unsafe fn isalnum(c: c_int) -> c_int;
1151                 unsafe fn isalpha(c: c_int) -> c_int;
1152                 unsafe fn iscntrl(c: c_int) -> c_int;
1153                 unsafe fn isdigit(c: c_int) -> c_int;
1154                 unsafe fn isgraph(c: c_int) -> c_int;
1155                 unsafe fn islower(c: c_int) -> c_int;
1156                 unsafe fn isprint(c: c_int) -> c_int;
1157                 unsafe fn ispunct(c: c_int) -> c_int;
1158                 unsafe fn isspace(c: c_int) -> c_int;
1159                 unsafe fn isupper(c: c_int) -> c_int;
1160                 unsafe fn isxdigit(c: c_int) -> c_int;
1161                 unsafe fn tolower(c: c_char) -> c_char;
1162                 unsafe fn toupper(c: c_char) -> c_char;
1163             }
1164         }
1165
1166         #[nolink]
1167         #[abi = "cdecl"]
1168         pub mod stdio {
1169             use libc::types::common::c95::{FILE, c_void, fpos_t};
1170             use libc::types::os::arch::c95::{c_char, c_int, c_long, size_t};
1171
1172             pub extern {
1173                 unsafe fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
1174                 unsafe fn freopen(filename: *c_char, mode: *c_char,
1175                            file: *FILE) -> *FILE;
1176                 unsafe fn fflush(file: *FILE) -> c_int;
1177                 unsafe fn fclose(file: *FILE) -> c_int;
1178                 unsafe fn remove(filename: *c_char) -> c_int;
1179                 unsafe fn rename(oldname: *c_char, newname: *c_char) -> c_int;
1180                 unsafe fn tmpfile() -> *FILE;
1181                 unsafe fn setvbuf(stream: *FILE, buffer: *c_char,
1182                            mode: c_int, size: size_t) -> c_int;
1183                 unsafe fn setbuf(stream: *FILE, buf: *c_char);
1184                 // Omitted: printf and scanf variants.
1185                 unsafe fn fgetc(stream: *FILE) -> c_int;
1186                 #[fast_ffi]
1187                 unsafe fn fgets(buf: *mut c_char, n: c_int,
1188                          stream: *FILE) -> *c_char;
1189                 #[fast_ffi]
1190                 unsafe fn fputc(c: c_int, stream: *FILE) -> c_int;
1191                 #[fast_ffi]
1192                 unsafe fn fputs(s: *c_char, stream: *FILE) -> *c_char;
1193                 // Omitted: getc, getchar (might be macros).
1194
1195                 // Omitted: gets, so ridiculously unsafe that it should not
1196                 // survive.
1197
1198                 // Omitted: putc, putchar (might be macros).
1199                 unsafe fn puts(s: *c_char) -> c_int;
1200                 unsafe fn ungetc(c: c_int, stream: *FILE) -> c_int;
1201                 #[fast_ffi]
1202                 unsafe fn fread(ptr: *mut c_void, size: size_t,
1203                          nobj: size_t, stream: *FILE) -> size_t;
1204                 #[fast_ffi]
1205                 unsafe fn fwrite(ptr: *c_void, size: size_t,
1206                           nobj: size_t, stream: *FILE) -> size_t;
1207                 unsafe fn fseek(stream: *FILE, offset: c_long,
1208                          whence: c_int) -> c_int;
1209                 unsafe fn ftell(stream: *FILE) -> c_long;
1210                 unsafe fn rewind(stream: *FILE);
1211                 unsafe fn fgetpos(stream: *FILE, ptr: *fpos_t) -> c_int;
1212                 unsafe fn fsetpos(stream: *FILE, ptr: *fpos_t) -> c_int;
1213                 unsafe fn feof(stream: *FILE) -> c_int;
1214                 unsafe fn ferror(stream: *FILE) -> c_int;
1215                 unsafe fn perror(s: *c_char);
1216             }
1217         }
1218
1219         #[nolink]
1220         #[abi = "cdecl"]
1221         pub mod stdlib {
1222             use libc::types::common::c95::c_void;
1223             use libc::types::os::arch::c95::{c_char, c_double, c_int};
1224             use libc::types::os::arch::c95::{c_long, c_uint, c_ulong};
1225             use libc::types::os::arch::c95::{size_t};
1226
1227             pub extern {
1228                 unsafe fn abs(i: c_int) -> c_int;
1229                 unsafe fn labs(i: c_long) -> c_long;
1230                 // Omitted: div, ldiv (return pub type incomplete).
1231                 unsafe fn atof(s: *c_char) -> c_double;
1232                 unsafe fn atoi(s: *c_char) -> c_int;
1233                 unsafe fn strtod(s: *c_char, endp: **c_char) -> c_double;
1234                 unsafe fn strtol(s: *c_char, endp: **c_char, base: c_int)
1235                               -> c_long;
1236                 unsafe fn strtoul(s: *c_char, endp: **c_char, base: c_int)
1237                                -> c_ulong;
1238                 #[fast_ffi]
1239                 unsafe fn calloc(nobj: size_t, size: size_t) -> *c_void;
1240                 #[fast_ffi]
1241                 unsafe fn malloc(size: size_t) -> *c_void;
1242                 #[fast_ffi]
1243                 unsafe fn realloc(p: *c_void, size: size_t) -> *c_void;
1244                 #[fast_ffi]
1245                 unsafe fn free(p: *c_void);
1246                 unsafe fn abort() -> !;
1247                 unsafe fn exit(status: c_int) -> !;
1248                 // Omitted: atexit.
1249                 unsafe fn system(s: *c_char) -> c_int;
1250                 unsafe fn getenv(s: *c_char) -> *c_char;
1251                 // Omitted: bsearch, qsort
1252                 unsafe fn rand() -> c_int;
1253                 unsafe fn srand(seed: c_uint);
1254             }
1255         }
1256
1257         #[nolink]
1258         #[abi = "cdecl"]
1259         pub mod string {
1260             use libc::types::common::c95::c_void;
1261             use libc::types::os::arch::c95::{c_char, c_int, size_t};
1262             use libc::types::os::arch::c95::{wchar_t};
1263
1264             pub extern {
1265                 unsafe fn strcpy(dst: *c_char, src: *c_char) -> *c_char;
1266                 unsafe fn strncpy(dst: *c_char, src: *c_char, n: size_t)
1267                                -> *c_char;
1268                 unsafe fn strcat(s: *c_char, ct: *c_char) -> *c_char;
1269                 unsafe fn strncat(s: *c_char, ct: *c_char, n: size_t)
1270                                -> *c_char;
1271                 unsafe fn strcmp(cs: *c_char, ct: *c_char) -> c_int;
1272                 unsafe fn strncmp(cs: *c_char, ct: *c_char, n: size_t)
1273                                -> c_int;
1274                 unsafe fn strcoll(cs: *c_char, ct: *c_char) -> c_int;
1275                 unsafe fn strchr(cs: *c_char, c: c_int) -> *c_char;
1276                 unsafe fn strrchr(cs: *c_char, c: c_int) -> *c_char;
1277                 unsafe fn strspn(cs: *c_char, ct: *c_char) -> size_t;
1278                 unsafe fn strcspn(cs: *c_char, ct: *c_char) -> size_t;
1279                 unsafe fn strpbrk(cs: *c_char, ct: *c_char) -> *c_char;
1280                 unsafe fn strstr(cs: *c_char, ct: *c_char) -> *c_char;
1281                 unsafe fn strlen(cs: *c_char) -> size_t;
1282                 unsafe fn strerror(n: c_int) -> *c_char;
1283                 unsafe fn strtok(s: *c_char, t: *c_char) -> *c_char;
1284                 unsafe fn strxfrm(s: *c_char, ct: *c_char, n: size_t)
1285                                -> size_t;
1286                 unsafe fn wcslen(buf: *wchar_t) -> size_t;
1287
1288                 // These are fine to execute on the Rust stack. They must be,
1289                 // in fact, because LLVM generates calls to them!
1290                 #[rust_stack]
1291                 #[inline(always)]
1292                 unsafe fn memcpy(s: *c_void, ct: *c_void, n: size_t)
1293                               -> *c_void;
1294                 #[rust_stack]
1295                 #[inline(always)]
1296                 unsafe fn memmove(s: *c_void, ct: *c_void, n: size_t)
1297                                -> *c_void;
1298                 #[rust_stack]
1299                 #[inline(always)]
1300                 unsafe fn memcmp(cx: *c_void, ct: *c_void, n: size_t)
1301                               -> c_int;
1302                 #[rust_stack]
1303                 #[inline(always)]
1304                 unsafe fn memchr(cx: *c_void, c: c_int, n: size_t) -> *c_void;
1305                 #[rust_stack]
1306                 #[inline(always)]
1307                 unsafe fn memset(s: *c_void, c: c_int, n: size_t) -> *c_void;
1308             }
1309         }
1310     }
1311
1312     // Microsoft helpfully underscore-qualifies all of its POSIX-like symbols
1313     // to make sure you don't use them accidentally. It also randomly deviates
1314     // from the exact signatures you might otherwise expect, and omits much,
1315     // so be careful when trying to write portable code; it won't always work
1316     // with the same POSIX functions and types as other platforms.
1317
1318     #[cfg(target_os = "win32")]
1319     pub mod posix88 {
1320         #[nolink]
1321         #[abi = "cdecl"]
1322         pub mod stat_ {
1323             use libc::types::os::common::posix01::stat;
1324             use libc::types::os::arch::c95::{c_int, c_char};
1325
1326             pub extern {
1327                 #[link_name = "_chmod"]
1328                 unsafe fn chmod(path: *c_char, mode: c_int) -> c_int;
1329
1330                 #[link_name = "_mkdir"]
1331                 unsafe fn mkdir(path: *c_char) -> c_int;
1332
1333                 #[link_name = "_fstat64"]
1334                 unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
1335
1336                 #[link_name = "_stat64"]
1337                 unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
1338             }
1339         }
1340
1341         #[nolink]
1342         #[abi = "cdecl"]
1343         pub mod stdio {
1344             use libc::types::common::c95::FILE;
1345             use libc::types::os::arch::c95::{c_int, c_char};
1346
1347             pub extern {
1348                 #[link_name = "_popen"]
1349                 unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
1350
1351                 #[link_name = "_pclose"]
1352                 unsafe fn pclose(stream: *FILE) -> c_int;
1353
1354                 #[link_name = "_fdopen"]
1355                 #[fast_ffi]
1356                 unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
1357
1358                 #[link_name = "_fileno"]
1359                 unsafe fn fileno(stream: *FILE) -> c_int;
1360             }
1361         }
1362
1363         #[nolink]
1364         #[abi = "cdecl"]
1365         pub mod fcntl {
1366             use libc::types::os::arch::c95::{c_int, c_char};
1367             pub extern {
1368                 #[link_name = "_open"]
1369                 unsafe fn open(path: *c_char, oflag: c_int, mode: c_int)
1370                             -> c_int;
1371
1372                 #[link_name = "_creat"]
1373                 unsafe fn creat(path: *c_char, mode: c_int) -> c_int;
1374             }
1375         }
1376
1377         #[nolink]
1378         #[abi = "cdecl"]
1379         pub mod dirent {
1380             // Not supplied at all.
1381         }
1382
1383         #[nolink]
1384         #[abi = "cdecl"]
1385         pub mod unistd {
1386             use libc::types::common::c95::c_void;
1387             use libc::types::os::arch::c95::{c_int, c_uint, c_char,
1388                                              c_long, size_t};
1389             use libc::types::os::arch::c99::intptr_t;
1390
1391             pub extern {
1392                 #[link_name = "_access"]
1393                 unsafe fn access(path: *c_char, amode: c_int) -> c_int;
1394
1395                 #[link_name = "_chdir"]
1396                 unsafe fn chdir(dir: *c_char) -> c_int;
1397
1398                 #[link_name = "_close"]
1399                 unsafe fn close(fd: c_int) -> c_int;
1400
1401                 #[link_name = "_dup"]
1402                 unsafe fn dup(fd: c_int) -> c_int;
1403
1404                 #[link_name = "_dup2"]
1405                 unsafe fn dup2(src: c_int, dst: c_int) -> c_int;
1406
1407                 #[link_name = "_execv"]
1408                 unsafe fn execv(prog: *c_char, argv: **c_char) -> intptr_t;
1409
1410                 #[link_name = "_execve"]
1411                 unsafe fn execve(prog: *c_char, argv: **c_char,
1412                           envp: **c_char) -> c_int;
1413
1414                 #[link_name = "_execvp"]
1415                 unsafe fn execvp(c: *c_char, argv: **c_char) -> c_int;
1416
1417                 #[link_name = "_execvpe"]
1418                 unsafe fn execvpe(c: *c_char, argv: **c_char,
1419                            envp: **c_char) -> c_int;
1420
1421                 #[link_name = "_getcwd"]
1422                 unsafe fn getcwd(buf: *c_char, size: size_t) -> *c_char;
1423
1424                 #[link_name = "_getpid"]
1425                 unsafe fn getpid() -> c_int;
1426
1427                 #[link_name = "_isatty"]
1428                 unsafe fn isatty(fd: c_int) -> c_int;
1429
1430                 #[link_name = "_lseek"]
1431                 unsafe fn lseek(fd: c_int, offset: c_long, origin: c_int)
1432                              -> c_long;
1433
1434                 #[link_name = "_pipe"]
1435                 unsafe fn pipe(fds: *mut c_int, psize: c_uint,
1436                         textmode: c_int) -> c_int;
1437
1438                 #[link_name = "_read"]
1439                 #[fast_ffi]
1440                 unsafe fn read(fd: c_int, buf: *mut c_void, count: c_uint)
1441                             -> c_int;
1442
1443                 #[link_name = "_rmdir"]
1444                 unsafe fn rmdir(path: *c_char) -> c_int;
1445
1446                 #[link_name = "_unlink"]
1447                 unsafe fn unlink(c: *c_char) -> c_int;
1448
1449                 #[link_name = "_write"]
1450                 #[fast_ffi]
1451                 unsafe fn write(fd: c_int, buf: *c_void, count: c_uint)
1452                              -> c_int;
1453             }
1454         }
1455     }
1456
1457
1458     #[cfg(target_os = "linux")]
1459     #[cfg(target_os = "android")]
1460     #[cfg(target_os = "macos")]
1461     #[cfg(target_os = "freebsd")]
1462     pub mod posix88 {
1463         pub mod stat_ {
1464             use libc::types::os::arch::c95::{c_char, c_int};
1465             use libc::types::os::arch::posix01::stat;
1466             use libc::types::os::arch::posix88::mode_t;
1467
1468             #[nolink]
1469             #[abi = "cdecl"]
1470             pub extern {
1471                 unsafe fn chmod(path: *c_char, mode: mode_t) -> c_int;
1472                 unsafe fn fchmod(fd: c_int, mode: mode_t) -> c_int;
1473
1474                 #[cfg(target_os = "linux")]
1475                 #[cfg(target_os = "freebsd")]
1476                 #[cfg(target_os = "android")]
1477                unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
1478
1479                 #[cfg(target_os = "macos")]
1480                 #[link_name = "fstat64"]
1481                 unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
1482
1483                 unsafe fn mkdir(path: *c_char, mode: mode_t) -> c_int;
1484                 unsafe fn mkfifo(path: *c_char, mode: mode_t) -> c_int;
1485
1486                 #[cfg(target_os = "linux")]
1487                 #[cfg(target_os = "freebsd")]
1488                 #[cfg(target_os = "android")]
1489                 unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
1490
1491                 #[cfg(target_os = "macos")]
1492                 #[link_name = "stat64"]
1493                 unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
1494             }
1495         }
1496
1497         #[nolink]
1498         #[abi = "cdecl"]
1499         pub mod stdio {
1500             use libc::types::common::c95::FILE;
1501             use libc::types::os::arch::c95::{c_char, c_int};
1502
1503             pub extern {
1504                 unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
1505                 unsafe fn pclose(stream: *FILE) -> c_int;
1506                 unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
1507                 unsafe fn fileno(stream: *FILE) -> c_int;
1508             }
1509         }
1510
1511         #[nolink]
1512         #[abi = "cdecl"]
1513         pub mod fcntl {
1514             use libc::types::os::arch::c95::{c_char, c_int};
1515             use libc::types::os::arch::posix88::mode_t;
1516
1517             pub extern {
1518                 unsafe fn open(path: *c_char, oflag: c_int, mode: c_int)
1519                             -> c_int;
1520                 unsafe fn creat(path: *c_char, mode: mode_t) -> c_int;
1521                 unsafe fn fcntl(fd: c_int, cmd: c_int) -> c_int;
1522             }
1523         }
1524
1525         #[nolink]
1526         #[abi = "cdecl"]
1527         pub mod dirent {
1528             use libc::types::common::posix88::{DIR, dirent_t};
1529             use libc::types::os::arch::c95::{c_char, c_int, c_long};
1530
1531             // NB: On OS X opendir and readdir have two versions,
1532             // one for 32-bit kernelspace and one for 64.
1533             // We should be linking to the 64-bit ones, called
1534             // opendir$INODE64, etc. but for some reason rustc
1535             // doesn't link it correctly on i686, so we're going
1536             // through a C function that mysteriously does work.
1537             pub unsafe fn opendir(dirname: *c_char) -> *DIR {
1538                 rust_opendir(dirname)
1539             }
1540             pub unsafe fn readdir(dirp: *DIR) -> *dirent_t {
1541                 rust_readdir(dirp)
1542             }
1543
1544             extern {
1545                 unsafe fn rust_opendir(dirname: *c_char) -> *DIR;
1546                 unsafe fn rust_readdir(dirp: *DIR) -> *dirent_t;
1547             }
1548
1549             pub extern {
1550                 unsafe fn closedir(dirp: *DIR) -> c_int;
1551                 unsafe fn rewinddir(dirp: *DIR);
1552                 unsafe fn seekdir(dirp: *DIR, loc: c_long);
1553                 unsafe fn telldir(dirp: *DIR) -> c_long;
1554             }
1555         }
1556
1557         #[nolink]
1558         #[abi = "cdecl"]
1559         pub mod unistd {
1560             use libc::types::common::c95::c_void;
1561             use libc::types::os::arch::c95::{c_char, c_int, c_long, c_uint};
1562             use libc::types::os::arch::c95::{size_t};
1563             use libc::types::os::arch::posix88::{gid_t, off_t, pid_t};
1564             use libc::types::os::arch::posix88::{ssize_t, uid_t};
1565
1566             pub extern {
1567                 unsafe fn access(path: *c_char, amode: c_int) -> c_int;
1568                 unsafe fn alarm(seconds: c_uint) -> c_uint;
1569                 unsafe fn chdir(dir: *c_char) -> c_int;
1570                 unsafe fn chown(path: *c_char, uid: uid_t, gid: gid_t)
1571                              -> c_int;
1572                 unsafe fn close(fd: c_int) -> c_int;
1573                 unsafe fn dup(fd: c_int) -> c_int;
1574                 unsafe fn dup2(src: c_int, dst: c_int) -> c_int;
1575                 unsafe fn execv(prog: *c_char, argv: **c_char) -> c_int;
1576                 unsafe fn execve(prog: *c_char,
1577                                  argv: **c_char,
1578                                  envp: **c_char)
1579                               -> c_int;
1580                 unsafe fn execvp(c: *c_char, argv: **c_char) -> c_int;
1581                 unsafe fn fork() -> pid_t;
1582                 unsafe fn fpathconf(filedes: c_int, name: c_int) -> c_long;
1583                 unsafe fn getcwd(buf: *c_char, size: size_t) -> *c_char;
1584                 unsafe fn getegid() -> gid_t;
1585                 unsafe fn geteuid() -> uid_t;
1586                 unsafe fn getgid() -> gid_t ;
1587                 unsafe fn getgroups(ngroups_max: c_int, groups: *mut gid_t)
1588                                  -> c_int;
1589                 unsafe fn getlogin() -> *c_char;
1590                 unsafe fn getopt(argc: c_int, argv: **c_char, optstr: *c_char)
1591                               -> c_int;
1592                 unsafe fn getpgrp() -> pid_t;
1593                 unsafe fn getpid() -> pid_t;
1594                 unsafe fn getppid() -> pid_t;
1595                 unsafe fn getuid() -> uid_t;
1596                 unsafe fn isatty(fd: c_int) -> c_int;
1597                 unsafe fn link(src: *c_char, dst: *c_char) -> c_int;
1598                 unsafe fn lseek(fd: c_int, offset: off_t, whence: c_int)
1599                              -> off_t;
1600                 unsafe fn pathconf(path: *c_char, name: c_int) -> c_long;
1601                 unsafe fn pause() -> c_int;
1602                 unsafe fn pipe(fds: *mut c_int) -> c_int;
1603                 #[fast_ffi]
1604                 unsafe fn read(fd: c_int, buf: *mut c_void,
1605                         count: size_t) -> ssize_t;
1606                 unsafe fn rmdir(path: *c_char) -> c_int;
1607                 unsafe fn setgid(gid: gid_t) -> c_int;
1608                 unsafe fn setpgid(pid: pid_t, pgid: pid_t) -> c_int;
1609                 unsafe fn setsid() -> pid_t;
1610                 unsafe fn setuid(uid: uid_t) -> c_int;
1611                 unsafe fn sleep(secs: c_uint) -> c_uint;
1612                 unsafe fn sysconf(name: c_int) -> c_long;
1613                 unsafe fn tcgetpgrp(fd: c_int) -> pid_t;
1614                 unsafe fn ttyname(fd: c_int) -> *c_char;
1615                 unsafe fn unlink(c: *c_char) -> c_int;
1616                 #[fast_ffi]
1617                 unsafe fn write(fd: c_int, buf: *c_void, count: size_t)
1618                              -> ssize_t;
1619             }
1620         }
1621
1622         #[nolink]
1623         #[abi = "cdecl"]
1624         pub mod signal {
1625             use libc::types::os::arch::c95::{c_int};
1626             use libc::types::os::arch::posix88::{pid_t};
1627
1628             pub extern {
1629                 unsafe fn kill(pid: pid_t, sig: c_int) -> c_int;
1630             }
1631         }
1632     }
1633
1634     #[cfg(target_os = "linux")]
1635     #[cfg(target_os = "android")]
1636     #[cfg(target_os = "macos")]
1637     #[cfg(target_os = "freebsd")]
1638     pub mod posix01 {
1639         #[nolink]
1640         #[abi = "cdecl"]
1641         pub mod stat_ {
1642             use libc::types::os::arch::c95::{c_char, c_int};
1643             use libc::types::os::arch::posix01::stat;
1644
1645             pub extern {
1646                 #[cfg(target_os = "linux")]
1647                 #[cfg(target_os = "freebsd")]
1648                 #[cfg(target_os = "android")]
1649                 unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
1650
1651                 #[cfg(target_os = "macos")]
1652                 #[link_name = "lstat64"]
1653                 unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
1654             }
1655         }
1656
1657         #[nolink]
1658         #[abi = "cdecl"]
1659         pub mod unistd {
1660             use libc::types::os::arch::c95::{c_char, c_int, size_t};
1661             use libc::types::os::arch::posix88::{ssize_t};
1662
1663             pub extern {
1664                 unsafe fn readlink(path: *c_char, buf: *mut c_char,
1665                             bufsz: size_t) -> ssize_t;
1666
1667                 unsafe fn fsync(fd: c_int) -> c_int;
1668
1669                 #[cfg(target_os = "linux")]
1670                 #[cfg(target_os = "android")]
1671                 unsafe fn fdatasync(fd: c_int) -> c_int;
1672
1673                 unsafe fn setenv(name: *c_char, val: *c_char,
1674                           overwrite: c_int) -> c_int;
1675                 unsafe fn unsetenv(name: *c_char) -> c_int;
1676                 unsafe fn putenv(string: *c_char) -> c_int;
1677
1678                 unsafe fn symlink(path1: *c_char, path2: *c_char) -> c_int;
1679             }
1680         }
1681
1682         #[nolink]
1683         #[abi = "cdecl"]
1684         pub mod wait {
1685             use libc::types::os::arch::c95::{c_int};
1686             use libc::types::os::arch::posix88::{pid_t};
1687
1688             pub extern {
1689                 unsafe fn waitpid(pid: pid_t,
1690                                   status: *mut c_int,
1691                                   options: c_int)
1692                                -> pid_t;
1693             }
1694         }
1695
1696         #[nolink]
1697         #[abi = "cdecl"]
1698         pub mod glob {
1699             use libc::types::common::c95::{c_void};
1700             use libc::types::os::arch::c95::{c_char, c_int};
1701             use libc::types::os::common::posix01::{glob_t};
1702
1703             pub extern {
1704                 unsafe fn glob(pattern: *c_char, flags: c_int,
1705                                errfunc: *c_void, // XXX callback
1706                                pglob: *mut glob_t);
1707                 unsafe fn globfree(pglob: *mut glob_t);
1708             }
1709         }
1710     }
1711
1712     #[cfg(target_os = "win32")]
1713     pub mod posix01 {
1714         pub mod stat_ {
1715         }
1716
1717         pub mod unistd {
1718         }
1719
1720         pub mod glob {
1721         }
1722     }
1723
1724
1725     #[cfg(target_os = "win32")]
1726     #[cfg(target_os = "linux")]
1727     #[cfg(target_os = "android")]
1728     #[cfg(target_os = "macos")]
1729     #[cfg(target_os = "freebsd")]
1730     pub mod posix08 {
1731         pub mod unistd {
1732         }
1733     }
1734
1735
1736     #[cfg(target_os = "macos")]
1737     #[cfg(target_os = "freebsd")]
1738     pub mod bsd44 {
1739         use libc::types::common::c95::{c_void};
1740         use libc::types::os::arch::c95::{c_char, c_int, c_uint, size_t};
1741
1742         #[abi = "cdecl"]
1743         pub extern {
1744             unsafe fn sysctl(name: *c_int, namelen: c_uint,
1745                       oldp: *mut c_void, oldlenp: *mut size_t,
1746                       newp: *c_void, newlen: size_t) -> c_int;
1747
1748             unsafe fn sysctlbyname(name: *c_char,
1749                             oldp: *mut c_void, oldlenp: *mut size_t,
1750                             newp: *c_void, newlen: size_t) -> c_int;
1751
1752             unsafe fn sysctlnametomib(name: *c_char, mibp: *mut c_int,
1753                                sizep: *mut size_t) -> c_int;
1754         }
1755     }
1756
1757
1758     #[cfg(target_os = "linux")]
1759     #[cfg(target_os = "android")]
1760     #[cfg(target_os = "win32")]
1761     pub mod bsd44 {
1762     }
1763
1764     #[cfg(target_os = "macos")]
1765     #[nolink]
1766     pub mod extra {
1767         use libc::types::os::arch::c95::{c_char, c_int};
1768
1769         #[abi = "cdecl"]
1770         pub extern {
1771             unsafe fn _NSGetExecutablePath(buf: *mut c_char,
1772                                            bufsize: *mut u32)
1773                                         -> c_int;
1774         }
1775     }
1776
1777     #[cfg(target_os = "freebsd")]
1778     pub mod extra {
1779     }
1780
1781     #[cfg(target_os = "linux")]
1782     #[cfg(target_os = "android")]
1783     pub mod extra {
1784     }
1785
1786
1787     #[cfg(target_os = "win32")]
1788     pub mod extra {
1789
1790         pub mod kernel32 {
1791             use libc::types::os::arch::c95::{c_uint};
1792             use libc::types::os::arch::extra::{BOOL, DWORD, HMODULE};
1793             use libc::types::os::arch::extra::{LPCWSTR, LPWSTR, LPTCH};
1794             use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES};
1795             use libc::types::os::arch::extra::{HANDLE};
1796
1797             #[abi = "stdcall"]
1798             pub extern "stdcall" {
1799                 unsafe fn GetEnvironmentVariableW(n: LPCWSTR,
1800                                                   v: LPWSTR,
1801                                                   nsize: DWORD)
1802                                                -> DWORD;
1803                 unsafe fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR)
1804                                                -> BOOL;
1805                 unsafe fn GetEnvironmentStringsA() -> LPTCH;
1806                 unsafe fn FreeEnvironmentStringsA(env_ptr: LPTCH) -> BOOL;
1807
1808                 unsafe fn GetModuleFileNameW(hModule: HMODULE,
1809                                              lpFilename: LPWSTR,
1810                                              nSize: DWORD)
1811                                           -> DWORD;
1812                 unsafe fn CreateDirectoryW(lpPathName: LPCWSTR,
1813                                            lpSecurityAttributes:
1814                                            LPSECURITY_ATTRIBUTES)
1815                                         -> BOOL;
1816                 unsafe fn CopyFileW(lpExistingFileName: LPCWSTR,
1817                                     lpNewFileName: LPCWSTR,
1818                                     bFailIfExists: BOOL)
1819                                  -> BOOL;
1820                 unsafe fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
1821                 unsafe fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
1822                 unsafe fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
1823
1824                 unsafe fn GetLastError() -> DWORD;
1825                 unsafe fn FindFirstFileW(fileName: *u16,
1826                                         findFileData: HANDLE)
1827                     -> HANDLE;
1828                 unsafe fn FindNextFileW(findFile: HANDLE,
1829                                        findFileData: HANDLE)
1830                     -> BOOL;
1831                 unsafe fn FindClose(findFile: HANDLE) -> BOOL;
1832                 unsafe fn CloseHandle(hObject: HANDLE) -> BOOL;
1833                 unsafe fn TerminateProcess(hProcess: HANDLE, uExitCode: c_uint) -> BOOL;
1834             }
1835         }
1836
1837         pub mod msvcrt {
1838             use libc::types::os::arch::c95::c_int;
1839
1840             #[abi = "cdecl"]
1841             #[nolink]
1842             pub extern {
1843                 #[link_name = "_commit"]
1844                 unsafe fn commit(fd: c_int) -> c_int;
1845             }
1846         }
1847     }
1848 }