]> git.lizzy.rs Git - rust.git/blob - src/libcore/libc.rs
Convert most of rust_run_program.cpp to rust (issue #2674).
[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                 pub type LPTSTR = *mut CHAR;
586
587                 // Not really, but opaque to us.
588                 pub type LPSECURITY_ATTRIBUTES = LPVOID;
589
590                 pub type LPVOID = *mut c_void;
591                 pub type LPBYTE = *mut BYTE;
592                 pub type LPWORD = *mut WORD;
593                 pub type LPDWORD = *mut DWORD;
594                 pub type LPHANDLE = *mut HANDLE;
595
596                 pub type LRESULT = LONG_PTR;
597                 pub type PBOOL = *mut BOOL;
598                 pub type WCHAR = wchar_t;
599                 pub type WORD = u16;
600
601                 pub type time64_t = i64;
602                 pub type int64 = i64;
603
604                 pub struct STARTUPINFO {
605                     cb: DWORD,
606                     lpReserved: LPTSTR,
607                     lpDesktop: LPTSTR,
608                     lpTitle: LPTSTR,
609                     dwX: DWORD,
610                     dwY: DWORD,
611                     dwXSize: DWORD,
612                     dwYSize: DWORD,
613                     dwXCountChars: DWORD,
614                     dwYCountCharts: DWORD,
615                     dwFillAttribute: DWORD,
616                     dwFlags: DWORD,
617                     wShowWindow: WORD,
618                     cbReserved2: WORD,
619                     lpReserved2: LPBYTE,
620                     hStdInput: HANDLE,
621                     hStdOutput: HANDLE,
622                     hStdError: HANDLE
623                 }
624                 pub type LPSTARTUPINFO = *mut STARTUPINFO;
625
626                 pub struct PROCESS_INFORMATION {
627                     hProcess: HANDLE,
628                     hThread: HANDLE,
629                     dwProcessId: DWORD,
630                     dwThreadId: DWORD
631                 }
632                 pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
633             }
634         }
635     }
636
637     #[cfg(target_os = "macos")]
638     pub mod os {
639         pub mod common {
640             pub mod posix01 {
641                 use libc::types::common::c95::{c_void};
642                 use libc::types::os::arch::c95::{c_char, c_int, size_t};
643                 pub struct glob_t {
644                     gl_pathc:  size_t,
645                     __unused1: c_int,
646                     gl_offs:   size_t,
647                     __unused2: c_int,
648                     gl_pathv:  **c_char,
649
650                     __unused3: *c_void,
651
652                     __unused4: *c_void,
653                     __unused5: *c_void,
654                     __unused6: *c_void,
655                     __unused7: *c_void,
656                     __unused8: *c_void,
657                 }
658             }
659         }
660
661         #[cfg(target_arch = "x86")]
662         pub mod arch {
663             pub mod c95 {
664                 pub type c_char = i8;
665                 pub type c_schar = i8;
666                 pub type c_uchar = u8;
667                 pub type c_short = i16;
668                 pub type c_ushort = u16;
669                 pub type c_int = i32;
670                 pub type c_uint = u32;
671                 pub type c_long = i32;
672                 pub type c_ulong = u32;
673                 pub type c_float = f32;
674                 pub type c_double = f64;
675                 pub type size_t = u32;
676                 pub type ptrdiff_t = i32;
677                 pub type clock_t = u32;
678                 pub type time_t = i32;
679                 pub type wchar_t = i32;
680             }
681             pub mod c99 {
682                 pub type c_longlong = i64;
683                 pub type c_ulonglong = u64;
684                 pub type intptr_t = int;
685                 pub type uintptr_t = uint;
686             }
687             pub mod posix88 {
688                 pub type off_t = i64;
689                 pub type dev_t = i32;
690                 pub type ino_t = u64;
691                 pub type pid_t = i32;
692                 pub type uid_t = u32;
693                 pub type gid_t = u32;
694                 pub type useconds_t = u32;
695                 pub type mode_t = u16;
696                 pub type ssize_t = i32;
697             }
698             pub mod posix01 {
699                 use libc::types::common::c99::{int32_t, int64_t, uint32_t};
700                 use libc::types::os::arch::c95::{c_long, time_t};
701                 use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t,
702                                                      mode_t, off_t, uid_t};
703
704                 pub type nlink_t = u16;
705                 pub type blksize_t = i64;
706                 pub type blkcnt_t = i32;
707
708                 pub struct stat {
709                     st_dev: dev_t,
710                     st_mode: mode_t,
711                     st_nlink: nlink_t,
712                     st_ino: ino_t,
713                     st_uid: uid_t,
714                     st_gid: gid_t,
715                     st_rdev: dev_t,
716                     st_atime: time_t,
717                     st_atime_nsec: c_long,
718                     st_mtime: time_t,
719                     st_mtime_nsec: c_long,
720                     st_ctime: time_t,
721                     st_ctime_nsec: c_long,
722                     st_birthtime: time_t,
723                     st_birthtime_nsec: c_long,
724                     st_size: off_t,
725                     st_blocks: blkcnt_t,
726                     st_blksize: blksize_t,
727                     st_flags: uint32_t,
728                     st_gen: uint32_t,
729                     st_lspare: int32_t,
730                     st_qspare: [int64_t, ..2],
731                 }
732             }
733             pub mod posix08 {
734             }
735             pub mod bsd44 {
736             }
737             pub mod extra {
738             }
739         }
740
741         #[cfg(target_arch = "x86_64")]
742         pub mod arch {
743             pub mod c95 {
744                 pub type c_char = i8;
745                 pub type c_schar = i8;
746                 pub type c_uchar = u8;
747                 pub type c_short = i16;
748                 pub type c_ushort = u16;
749                 pub type c_int = i32;
750                 pub type c_uint = u32;
751                 pub type c_long = i64;
752                 pub type c_ulong = u64;
753                 pub type c_float = f32;
754                 pub type c_double = f64;
755                 pub type size_t = u64;
756                 pub type ptrdiff_t = i64;
757                 pub type clock_t = u64;
758                 pub type time_t = i64;
759                 pub type wchar_t = i32;
760             }
761             pub mod c99 {
762                 pub type c_longlong = i64;
763                 pub type c_ulonglong = u64;
764                 pub type intptr_t = int;
765                 pub type uintptr_t = uint;
766             }
767             pub mod posix88 {
768                 pub type off_t = i64;
769                 pub type dev_t = i32;
770                 pub type ino_t = u64;
771                 pub type pid_t = i32;
772                 pub type uid_t = u32;
773                 pub type gid_t = u32;
774                 pub type useconds_t = u32;
775                 pub type mode_t = u16;
776                 pub type ssize_t = i64;
777             }
778             pub mod posix01 {
779                 use libc::types::common::c99::{int32_t, int64_t};
780                 use libc::types::common::c99::{uint32_t};
781                 use libc::types::os::arch::c95::{c_long, time_t};
782                 use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
783                 use libc::types::os::arch::posix88::{mode_t, off_t, uid_t};
784
785                 pub type nlink_t = u16;
786                 pub type blksize_t = i64;
787                 pub type blkcnt_t = i32;
788
789                 pub struct stat {
790                     st_dev: dev_t,
791                     st_mode: mode_t,
792                     st_nlink: nlink_t,
793                     st_ino: ino_t,
794                     st_uid: uid_t,
795                     st_gid: gid_t,
796                     st_rdev: dev_t,
797                     st_atime: time_t,
798                     st_atime_nsec: c_long,
799                     st_mtime: time_t,
800                     st_mtime_nsec: c_long,
801                     st_ctime: time_t,
802                     st_ctime_nsec: c_long,
803                     st_birthtime: time_t,
804                     st_birthtime_nsec: c_long,
805                     st_size: off_t,
806                     st_blocks: blkcnt_t,
807                     st_blksize: blksize_t,
808                     st_flags: uint32_t,
809                     st_gen: uint32_t,
810                     st_lspare: int32_t,
811                     st_qspare: [int64_t, ..2],
812                 }
813             }
814             pub mod posix08 {
815             }
816             pub mod bsd44 {
817             }
818             pub mod extra {
819             }
820         }
821     }
822 }
823
824 pub mod consts {
825     // Consts tend to vary per OS so we pull their definitions out
826     // into this module.
827
828     #[cfg(target_os = "win32")]
829     pub mod os {
830         pub mod c95 {
831             pub static EXIT_FAILURE : int = 1;
832             pub static EXIT_SUCCESS : int = 0;
833             pub static RAND_MAX : int = 32767;
834             pub static EOF : int = -1;
835             pub static SEEK_SET : int = 0;
836             pub static SEEK_CUR : int = 1;
837             pub static SEEK_END : int = 2;
838             pub static _IOFBF : int = 0;
839             pub static _IONBF : int = 4;
840             pub static _IOLBF : int = 64;
841             pub static BUFSIZ : uint = 512_u;
842             pub static FOPEN_MAX : uint = 20_u;
843             pub static FILENAME_MAX : uint = 260_u;
844             pub static L_tmpnam : uint = 16_u;
845             pub static TMP_MAX : uint = 32767_u;
846         }
847         pub mod c99 {
848         }
849         pub mod posix88 {
850             pub static O_RDONLY : int = 0;
851             pub static O_WRONLY : int = 1;
852             pub static O_RDWR : int = 2;
853             pub static O_APPEND : int = 8;
854             pub static O_CREAT : int = 256;
855             pub static O_EXCL : int = 1024;
856             pub static O_TRUNC : int = 512;
857             pub static S_IFIFO : int = 4096;
858             pub static S_IFCHR : int = 8192;
859             pub static S_IFBLK : int = 12288;
860             pub static S_IFDIR : int = 16384;
861             pub static S_IFREG : int = 32768;
862             pub static S_IFMT : int = 61440;
863             pub static S_IEXEC : int = 64;
864             pub static S_IWRITE : int = 128;
865             pub static S_IREAD : int = 256;
866             pub static S_IRWXU : int = 448;
867             pub static S_IXUSR : int = 64;
868             pub static S_IWUSR : int = 128;
869             pub static S_IRUSR : int = 256;
870             pub static F_OK : int = 0;
871             pub static R_OK : int = 4;
872             pub static W_OK : int = 2;
873             pub static X_OK : int = 1;
874             pub static STDIN_FILENO : int = 0;
875             pub static STDOUT_FILENO : int = 1;
876             pub static STDERR_FILENO : int = 2;
877         }
878         pub mod posix01 {
879         }
880         pub mod posix08 {
881         }
882         pub mod bsd44 {
883         }
884         pub mod extra {
885             use libc::types::os::arch::extra::{DWORD, BOOL};
886
887             pub static TRUE : BOOL = 1;
888             pub static FALSE : BOOL = 0;
889
890             pub static O_TEXT : int = 16384;
891             pub static O_BINARY : int = 32768;
892             pub static O_NOINHERIT: int = 128;
893
894             pub static ERROR_SUCCESS : int = 0;
895             pub static ERROR_INSUFFICIENT_BUFFER : int = 122;
896             pub static INVALID_HANDLE_VALUE: int = -1;
897
898             pub static DELETE : DWORD = 0x00010000;
899             pub static READ_CONTROL : DWORD = 0x00020000;
900             pub static SYNCHRONIZE : DWORD = 0x00100000;
901             pub static WRITE_DAC : DWORD = 0x00040000;
902             pub static WRITE_OWNER : DWORD = 0x00080000;
903
904             pub static PROCESS_CREATE_PROCESS : DWORD = 0x0080;
905             pub static PROCESS_CREATE_THREAD : DWORD = 0x0002;
906             pub static PROCESS_DUP_HANDLE : DWORD = 0x0040;
907             pub static PROCESS_QUERY_INFORMATION : DWORD = 0x0400;
908             pub static PROCESS_QUERY_LIMITED_INFORMATION : DWORD = 0x1000;
909             pub static PROCESS_SET_INFORMATION : DWORD = 0x0200;
910             pub static PROCESS_SET_QUOTA : DWORD = 0x0100;
911             pub static PROCESS_SUSPEND_RESUME : DWORD = 0x0800;
912             pub static PROCESS_TERMINATE : DWORD = 0x0001;
913             pub static PROCESS_VM_OPERATION : DWORD = 0x0008;
914             pub static PROCESS_VM_READ : DWORD = 0x0010;
915             pub static PROCESS_VM_WRITE : DWORD = 0x0020;
916
917             pub static STARTF_FORCEONFEEDBACK : DWORD = 0x00000040;
918             pub static STARTF_FORCEOFFFEEDBACK : DWORD = 0x00000080;
919             pub static STARTF_PREVENTPINNING : DWORD = 0x00002000;
920             pub static STARTF_RUNFULLSCREEN : DWORD = 0x00000020;
921             pub static STARTF_TITLEISAPPID : DWORD = 0x00001000;
922             pub static STARTF_TITLEISLINKNAME : DWORD = 0x00000800;
923             pub static STARTF_USECOUNTCHARS : DWORD = 0x00000008;
924             pub static STARTF_USEFILLATTRIBUTE : DWORD = 0x00000010;
925             pub static STARTF_USEHOTKEY : DWORD = 0x00000200;
926             pub static STARTF_USEPOSITION : DWORD = 0x00000004;
927             pub static STARTF_USESHOWWINDOW : DWORD = 0x00000001;
928             pub static STARTF_USESIZE : DWORD = 0x00000002;
929             pub static STARTF_USESTDHANDLES : DWORD = 0x00000100;
930
931             pub static WAIT_ABANDONED : DWORD = 0x00000080;
932             pub static WAIT_OBJECT_0 : DWORD = 0x00000000;
933             pub static WAIT_TIMEOUT : DWORD = 0x00000102;
934             pub static WAIT_FAILED : DWORD = -1;
935
936             pub static DUPLICATE_CLOSE_SOURCE : DWORD = 0x00000001;
937             pub static DUPLICATE_SAME_ACCESS : DWORD = 0x00000002;
938
939             pub static INFINITE : DWORD = -1;
940             pub static STILL_ACTIVE : DWORD = 259;
941         }
942     }
943
944
945     #[cfg(target_os = "linux")]
946     #[cfg(target_os = "android")]
947     pub mod os {
948         pub mod c95 {
949             pub static EXIT_FAILURE : int = 1;
950             pub static EXIT_SUCCESS : int = 0;
951             pub static RAND_MAX : int = 2147483647;
952             pub static EOF : int = -1;
953             pub static SEEK_SET : int = 0;
954             pub static SEEK_CUR : int = 1;
955             pub static SEEK_END : int = 2;
956             pub static _IOFBF : int = 0;
957             pub static _IONBF : int = 2;
958             pub static _IOLBF : int = 1;
959             pub static BUFSIZ : uint = 8192_u;
960             pub static FOPEN_MAX : uint = 16_u;
961             pub static FILENAME_MAX : uint = 4096_u;
962             pub static L_tmpnam : uint = 20_u;
963             pub static TMP_MAX : uint = 238328_u;
964         }
965         pub mod c99 {
966         }
967         pub mod posix88 {
968             pub static O_RDONLY : int = 0;
969             pub static O_WRONLY : int = 1;
970             pub static O_RDWR : int = 2;
971             pub static O_APPEND : int = 1024;
972             pub static O_CREAT : int = 64;
973             pub static O_EXCL : int = 128;
974             pub static O_TRUNC : int = 512;
975             pub static S_IFIFO : int = 4096;
976             pub static S_IFCHR : int = 8192;
977             pub static S_IFBLK : int = 24576;
978             pub static S_IFDIR : int = 16384;
979             pub static S_IFREG : int = 32768;
980             pub static S_IFMT : int = 61440;
981             pub static S_IEXEC : int = 64;
982             pub static S_IWRITE : int = 128;
983             pub static S_IREAD : int = 256;
984             pub static S_IRWXU : int = 448;
985             pub static S_IXUSR : int = 64;
986             pub static S_IWUSR : int = 128;
987             pub static S_IRUSR : int = 256;
988             pub static F_OK : int = 0;
989             pub static R_OK : int = 4;
990             pub static W_OK : int = 2;
991             pub static X_OK : int = 1;
992             pub static STDIN_FILENO : int = 0;
993             pub static STDOUT_FILENO : int = 1;
994             pub static STDERR_FILENO : int = 2;
995             pub static F_LOCK : int = 1;
996             pub static F_TEST : int = 3;
997             pub static F_TLOCK : int = 2;
998             pub static F_ULOCK : int = 0;
999             pub static SIGHUP : int = 1;
1000             pub static SIGINT : int = 2;
1001             pub static SIGQUIT : int = 3;
1002             pub static SIGILL : int = 4;
1003             pub static SIGABRT : int = 6;
1004             pub static SIGFPE : int = 8;
1005             pub static SIGKILL : int = 9;
1006             pub static SIGSEGV : int = 11;
1007             pub static SIGPIPE : int = 13;
1008             pub static SIGALRM : int = 14;
1009             pub static SIGTERM : int = 15;
1010         }
1011         pub mod posix01 {
1012             pub static SIGTRAP : int = 5;
1013
1014             pub static GLOB_ERR      : int = 1 << 0;
1015             pub static GLOB_MARK     : int = 1 << 1;
1016             pub static GLOB_NOSORT   : int = 1 << 2;
1017             pub static GLOB_DOOFFS   : int = 1 << 3;
1018             pub static GLOB_NOCHECK  : int = 1 << 4;
1019             pub static GLOB_APPEND   : int = 1 << 5;
1020             pub static GLOB_NOESCAPE : int = 1 << 6;
1021
1022             pub static GLOB_NOSPACE  : int = 1;
1023             pub static GLOB_ABORTED  : int = 2;
1024             pub static GLOB_NOMATCH  : int = 3;
1025         }
1026         pub mod posix08 {
1027         }
1028         pub mod bsd44 {
1029         }
1030         pub mod extra {
1031             pub static O_RSYNC : int = 1052672;
1032             pub static O_DSYNC : int = 4096;
1033             pub static O_SYNC : int = 1052672;
1034         }
1035     }
1036
1037     #[cfg(target_os = "freebsd")]
1038     pub mod os {
1039         pub mod c95 {
1040             pub static EXIT_FAILURE : int = 1;
1041             pub static EXIT_SUCCESS : int = 0;
1042             pub static RAND_MAX : int = 2147483647;
1043             pub static EOF : int = -1;
1044             pub static SEEK_SET : int = 0;
1045             pub static SEEK_CUR : int = 1;
1046             pub static SEEK_END : int = 2;
1047             pub static _IOFBF : int = 0;
1048             pub static _IONBF : int = 2;
1049             pub static _IOLBF : int = 1;
1050             pub static BUFSIZ : uint = 1024_u;
1051             pub static FOPEN_MAX : uint = 20_u;
1052             pub static FILENAME_MAX : uint = 1024_u;
1053             pub static L_tmpnam : uint = 1024_u;
1054             pub static TMP_MAX : uint = 308915776_u;
1055         }
1056         pub mod c99 {
1057         }
1058         pub mod posix88 {
1059             pub static O_RDONLY : int = 0;
1060             pub static O_WRONLY : int = 1;
1061             pub static O_RDWR : int = 2;
1062             pub static O_APPEND : int = 8;
1063             pub static O_CREAT : int = 512;
1064             pub static O_EXCL : int = 2048;
1065             pub static O_TRUNC : int = 1024;
1066             pub static S_IFIFO : int = 4096;
1067             pub static S_IFCHR : int = 8192;
1068             pub static S_IFBLK : int = 24576;
1069             pub static S_IFDIR : int = 16384;
1070             pub static S_IFREG : int = 32768;
1071             pub static S_IFMT : int = 61440;
1072             pub static S_IEXEC : int = 64;
1073             pub static S_IWRITE : int = 128;
1074             pub static S_IREAD : int = 256;
1075             pub static S_IRWXU : int = 448;
1076             pub static S_IXUSR : int = 64;
1077             pub static S_IWUSR : int = 128;
1078             pub static S_IRUSR : int = 256;
1079             pub static F_OK : int = 0;
1080             pub static R_OK : int = 4;
1081             pub static W_OK : int = 2;
1082             pub static X_OK : int = 1;
1083             pub static STDIN_FILENO : int = 0;
1084             pub static STDOUT_FILENO : int = 1;
1085             pub static STDERR_FILENO : int = 2;
1086             pub static F_LOCK : int = 1;
1087             pub static F_TEST : int = 3;
1088             pub static F_TLOCK : int = 2;
1089             pub static F_ULOCK : int = 0;
1090             pub static SIGHUP : int = 1;
1091             pub static SIGINT : int = 2;
1092             pub static SIGQUIT : int = 3;
1093             pub static SIGILL : int = 4;
1094             pub static SIGABRT : int = 6;
1095             pub static SIGFPE : int = 8;
1096             pub static SIGKILL : int = 9;
1097             pub static SIGSEGV : int = 11;
1098             pub static SIGPIPE : int = 13;
1099             pub static SIGALRM : int = 14;
1100             pub static SIGTERM : int = 15;
1101         }
1102         pub mod posix01 {
1103             pub static SIGTRAP : int = 5;
1104
1105             pub static GLOB_APPEND   : int = 0x0001;
1106             pub static GLOB_DOOFFS   : int = 0x0002;
1107             pub static GLOB_ERR      : int = 0x0004;
1108             pub static GLOB_MARK     : int = 0x0008;
1109             pub static GLOB_NOCHECK  : int = 0x0010;
1110             pub static GLOB_NOSORT   : int = 0x0020;
1111             pub static GLOB_NOESCAPE : int = 0x2000;
1112
1113             pub static GLOB_NOSPACE  : int = -1;
1114             pub static GLOB_ABORTED  : int = -2;
1115             pub static GLOB_NOMATCH  : int = -3;
1116         }
1117         pub mod posix08 {
1118         }
1119         pub mod bsd44 {
1120         }
1121         pub mod extra {
1122             pub static O_SYNC : int = 128;
1123             pub static CTL_KERN: int = 1;
1124             pub static KERN_PROC: int = 14;
1125             pub static KERN_PROC_PATHNAME: int = 12;
1126         }
1127     }
1128
1129     #[cfg(target_os = "macos")]
1130     pub mod os {
1131         pub mod c95 {
1132             pub static EXIT_FAILURE : int = 1;
1133             pub static EXIT_SUCCESS : int = 0;
1134             pub static RAND_MAX : int = 2147483647;
1135             pub static EOF : int = -1;
1136             pub static SEEK_SET : int = 0;
1137             pub static SEEK_CUR : int = 1;
1138             pub static SEEK_END : int = 2;
1139             pub static _IOFBF : int = 0;
1140             pub static _IONBF : int = 2;
1141             pub static _IOLBF : int = 1;
1142             pub static BUFSIZ : uint = 1024_u;
1143             pub static FOPEN_MAX : uint = 20_u;
1144             pub static FILENAME_MAX : uint = 1024_u;
1145             pub static L_tmpnam : uint = 1024_u;
1146             pub static TMP_MAX : uint = 308915776_u;
1147         }
1148         pub mod c99 {
1149         }
1150         pub mod posix88 {
1151             pub static O_RDONLY : int = 0;
1152             pub static O_WRONLY : int = 1;
1153             pub static O_RDWR : int = 2;
1154             pub static O_APPEND : int = 8;
1155             pub static O_CREAT : int = 512;
1156             pub static O_EXCL : int = 2048;
1157             pub static O_TRUNC : int = 1024;
1158             pub static S_IFIFO : int = 4096;
1159             pub static S_IFCHR : int = 8192;
1160             pub static S_IFBLK : int = 24576;
1161             pub static S_IFDIR : int = 16384;
1162             pub static S_IFREG : int = 32768;
1163             pub static S_IFMT : int = 61440;
1164             pub static S_IEXEC : int = 64;
1165             pub static S_IWRITE : int = 128;
1166             pub static S_IREAD : int = 256;
1167             pub static S_IRWXU : int = 448;
1168             pub static S_IXUSR : int = 64;
1169             pub static S_IWUSR : int = 128;
1170             pub static S_IRUSR : int = 256;
1171             pub static F_OK : int = 0;
1172             pub static R_OK : int = 4;
1173             pub static W_OK : int = 2;
1174             pub static X_OK : int = 1;
1175             pub static STDIN_FILENO : int = 0;
1176             pub static STDOUT_FILENO : int = 1;
1177             pub static STDERR_FILENO : int = 2;
1178             pub static F_LOCK : int = 1;
1179             pub static F_TEST : int = 3;
1180             pub static F_TLOCK : int = 2;
1181             pub static F_ULOCK : int = 0;
1182             pub static SIGHUP : int = 1;
1183             pub static SIGINT : int = 2;
1184             pub static SIGQUIT : int = 3;
1185             pub static SIGILL : int = 4;
1186             pub static SIGABRT : int = 6;
1187             pub static SIGFPE : int = 8;
1188             pub static SIGKILL : int = 9;
1189             pub static SIGSEGV : int = 11;
1190             pub static SIGPIPE : int = 13;
1191             pub static SIGALRM : int = 14;
1192             pub static SIGTERM : int = 15;
1193         }
1194         pub mod posix01 {
1195             pub static SIGTRAP : int = 5;
1196
1197             pub static GLOB_APPEND   : int = 0x0001;
1198             pub static GLOB_DOOFFS   : int = 0x0002;
1199             pub static GLOB_ERR      : int = 0x0004;
1200             pub static GLOB_MARK     : int = 0x0008;
1201             pub static GLOB_NOCHECK  : int = 0x0010;
1202             pub static GLOB_NOSORT   : int = 0x0020;
1203             pub static GLOB_NOESCAPE : int = 0x2000;
1204
1205             pub static GLOB_NOSPACE  : int = -1;
1206             pub static GLOB_ABORTED  : int = -2;
1207             pub static GLOB_NOMATCH  : int = -3;
1208         }
1209         pub mod posix08 {
1210         }
1211         pub mod bsd44 {
1212         }
1213         pub mod extra {
1214             pub static O_DSYNC : int = 4194304;
1215             pub static O_SYNC : int = 128;
1216             pub static F_FULLFSYNC : int = 51;
1217         }
1218     }
1219 }
1220
1221
1222 pub mod funcs {
1223     // Thankfull most of c95 is universally available and does not vary by OS
1224     // or anything. The same is not true of POSIX.
1225
1226     pub mod c95 {
1227         #[nolink]
1228         #[abi = "cdecl"]
1229         pub mod ctype {
1230             use libc::types::os::arch::c95::{c_char, c_int};
1231
1232             pub extern {
1233                 unsafe fn isalnum(c: c_int) -> c_int;
1234                 unsafe fn isalpha(c: c_int) -> c_int;
1235                 unsafe fn iscntrl(c: c_int) -> c_int;
1236                 unsafe fn isdigit(c: c_int) -> c_int;
1237                 unsafe fn isgraph(c: c_int) -> c_int;
1238                 unsafe fn islower(c: c_int) -> c_int;
1239                 unsafe fn isprint(c: c_int) -> c_int;
1240                 unsafe fn ispunct(c: c_int) -> c_int;
1241                 unsafe fn isspace(c: c_int) -> c_int;
1242                 unsafe fn isupper(c: c_int) -> c_int;
1243                 unsafe fn isxdigit(c: c_int) -> c_int;
1244                 unsafe fn tolower(c: c_char) -> c_char;
1245                 unsafe fn toupper(c: c_char) -> c_char;
1246             }
1247         }
1248
1249         #[nolink]
1250         #[abi = "cdecl"]
1251         pub mod stdio {
1252             use libc::types::common::c95::{FILE, c_void, fpos_t};
1253             use libc::types::os::arch::c95::{c_char, c_int, c_long, size_t};
1254
1255             pub extern {
1256                 unsafe fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
1257                 unsafe fn freopen(filename: *c_char, mode: *c_char,
1258                            file: *FILE) -> *FILE;
1259                 unsafe fn fflush(file: *FILE) -> c_int;
1260                 unsafe fn fclose(file: *FILE) -> c_int;
1261                 unsafe fn remove(filename: *c_char) -> c_int;
1262                 unsafe fn rename(oldname: *c_char, newname: *c_char) -> c_int;
1263                 unsafe fn tmpfile() -> *FILE;
1264                 unsafe fn setvbuf(stream: *FILE, buffer: *c_char,
1265                            mode: c_int, size: size_t) -> c_int;
1266                 unsafe fn setbuf(stream: *FILE, buf: *c_char);
1267                 // Omitted: printf and scanf variants.
1268                 unsafe fn fgetc(stream: *FILE) -> c_int;
1269                 #[fast_ffi]
1270                 unsafe fn fgets(buf: *mut c_char, n: c_int,
1271                          stream: *FILE) -> *c_char;
1272                 #[fast_ffi]
1273                 unsafe fn fputc(c: c_int, stream: *FILE) -> c_int;
1274                 #[fast_ffi]
1275                 unsafe fn fputs(s: *c_char, stream: *FILE) -> *c_char;
1276                 // Omitted: getc, getchar (might be macros).
1277
1278                 // Omitted: gets, so ridiculously unsafe that it should not
1279                 // survive.
1280
1281                 // Omitted: putc, putchar (might be macros).
1282                 unsafe fn puts(s: *c_char) -> c_int;
1283                 unsafe fn ungetc(c: c_int, stream: *FILE) -> c_int;
1284                 #[fast_ffi]
1285                 unsafe fn fread(ptr: *mut c_void, size: size_t,
1286                          nobj: size_t, stream: *FILE) -> size_t;
1287                 #[fast_ffi]
1288                 unsafe fn fwrite(ptr: *c_void, size: size_t,
1289                           nobj: size_t, stream: *FILE) -> size_t;
1290                 unsafe fn fseek(stream: *FILE, offset: c_long,
1291                          whence: c_int) -> c_int;
1292                 unsafe fn ftell(stream: *FILE) -> c_long;
1293                 unsafe fn rewind(stream: *FILE);
1294                 unsafe fn fgetpos(stream: *FILE, ptr: *fpos_t) -> c_int;
1295                 unsafe fn fsetpos(stream: *FILE, ptr: *fpos_t) -> c_int;
1296                 unsafe fn feof(stream: *FILE) -> c_int;
1297                 unsafe fn ferror(stream: *FILE) -> c_int;
1298                 unsafe fn perror(s: *c_char);
1299             }
1300         }
1301
1302         #[nolink]
1303         #[abi = "cdecl"]
1304         pub mod stdlib {
1305             use libc::types::common::c95::c_void;
1306             use libc::types::os::arch::c95::{c_char, c_double, c_int};
1307             use libc::types::os::arch::c95::{c_long, c_uint, c_ulong};
1308             use libc::types::os::arch::c95::{size_t};
1309
1310             pub extern {
1311                 unsafe fn abs(i: c_int) -> c_int;
1312                 unsafe fn labs(i: c_long) -> c_long;
1313                 // Omitted: div, ldiv (return pub type incomplete).
1314                 unsafe fn atof(s: *c_char) -> c_double;
1315                 unsafe fn atoi(s: *c_char) -> c_int;
1316                 unsafe fn strtod(s: *c_char, endp: **c_char) -> c_double;
1317                 unsafe fn strtol(s: *c_char, endp: **c_char, base: c_int)
1318                               -> c_long;
1319                 unsafe fn strtoul(s: *c_char, endp: **c_char, base: c_int)
1320                                -> c_ulong;
1321                 #[fast_ffi]
1322                 unsafe fn calloc(nobj: size_t, size: size_t) -> *c_void;
1323                 #[fast_ffi]
1324                 unsafe fn malloc(size: size_t) -> *c_void;
1325                 #[fast_ffi]
1326                 unsafe fn realloc(p: *c_void, size: size_t) -> *c_void;
1327                 #[fast_ffi]
1328                 unsafe fn free(p: *c_void);
1329                 unsafe fn abort() -> !;
1330                 unsafe fn exit(status: c_int) -> !;
1331                 // Omitted: atexit.
1332                 unsafe fn system(s: *c_char) -> c_int;
1333                 unsafe fn getenv(s: *c_char) -> *c_char;
1334                 // Omitted: bsearch, qsort
1335                 unsafe fn rand() -> c_int;
1336                 unsafe fn srand(seed: c_uint);
1337             }
1338         }
1339
1340         #[nolink]
1341         #[abi = "cdecl"]
1342         pub mod string {
1343             use libc::types::common::c95::c_void;
1344             use libc::types::os::arch::c95::{c_char, c_int, size_t};
1345             use libc::types::os::arch::c95::{wchar_t};
1346
1347             pub extern {
1348                 unsafe fn strcpy(dst: *c_char, src: *c_char) -> *c_char;
1349                 unsafe fn strncpy(dst: *c_char, src: *c_char, n: size_t)
1350                                -> *c_char;
1351                 unsafe fn strcat(s: *c_char, ct: *c_char) -> *c_char;
1352                 unsafe fn strncat(s: *c_char, ct: *c_char, n: size_t)
1353                                -> *c_char;
1354                 unsafe fn strcmp(cs: *c_char, ct: *c_char) -> c_int;
1355                 unsafe fn strncmp(cs: *c_char, ct: *c_char, n: size_t)
1356                                -> c_int;
1357                 unsafe fn strcoll(cs: *c_char, ct: *c_char) -> c_int;
1358                 unsafe fn strchr(cs: *c_char, c: c_int) -> *c_char;
1359                 unsafe fn strrchr(cs: *c_char, c: c_int) -> *c_char;
1360                 unsafe fn strspn(cs: *c_char, ct: *c_char) -> size_t;
1361                 unsafe fn strcspn(cs: *c_char, ct: *c_char) -> size_t;
1362                 unsafe fn strpbrk(cs: *c_char, ct: *c_char) -> *c_char;
1363                 unsafe fn strstr(cs: *c_char, ct: *c_char) -> *c_char;
1364                 unsafe fn strlen(cs: *c_char) -> size_t;
1365                 unsafe fn strerror(n: c_int) -> *c_char;
1366                 unsafe fn strtok(s: *c_char, t: *c_char) -> *c_char;
1367                 unsafe fn strxfrm(s: *c_char, ct: *c_char, n: size_t)
1368                                -> size_t;
1369                 unsafe fn wcslen(buf: *wchar_t) -> size_t;
1370
1371                 // These are fine to execute on the Rust stack. They must be,
1372                 // in fact, because LLVM generates calls to them!
1373                 #[rust_stack]
1374                 #[inline(always)]
1375                 unsafe fn memcpy(s: *c_void, ct: *c_void, n: size_t)
1376                               -> *c_void;
1377                 #[rust_stack]
1378                 #[inline(always)]
1379                 unsafe fn memmove(s: *c_void, ct: *c_void, n: size_t)
1380                                -> *c_void;
1381                 #[rust_stack]
1382                 #[inline(always)]
1383                 unsafe fn memcmp(cx: *c_void, ct: *c_void, n: size_t)
1384                               -> c_int;
1385                 #[rust_stack]
1386                 #[inline(always)]
1387                 unsafe fn memchr(cx: *c_void, c: c_int, n: size_t) -> *c_void;
1388                 #[rust_stack]
1389                 #[inline(always)]
1390                 unsafe fn memset(s: *c_void, c: c_int, n: size_t) -> *c_void;
1391             }
1392         }
1393     }
1394
1395     // Microsoft helpfully underscore-qualifies all of its POSIX-like symbols
1396     // to make sure you don't use them accidentally. It also randomly deviates
1397     // from the exact signatures you might otherwise expect, and omits much,
1398     // so be careful when trying to write portable code; it won't always work
1399     // with the same POSIX functions and types as other platforms.
1400
1401     #[cfg(target_os = "win32")]
1402     pub mod posix88 {
1403         #[nolink]
1404         #[abi = "cdecl"]
1405         pub mod stat_ {
1406             use libc::types::os::common::posix01::stat;
1407             use libc::types::os::arch::c95::{c_int, c_char};
1408
1409             pub extern {
1410                 #[link_name = "_chmod"]
1411                 unsafe fn chmod(path: *c_char, mode: c_int) -> c_int;
1412
1413                 #[link_name = "_mkdir"]
1414                 unsafe fn mkdir(path: *c_char) -> c_int;
1415
1416                 #[link_name = "_fstat64"]
1417                 unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
1418
1419                 #[link_name = "_stat64"]
1420                 unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
1421             }
1422         }
1423
1424         #[nolink]
1425         #[abi = "cdecl"]
1426         pub mod stdio {
1427             use libc::types::common::c95::FILE;
1428             use libc::types::os::arch::c95::{c_int, c_char};
1429
1430             pub extern {
1431                 #[link_name = "_popen"]
1432                 unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
1433
1434                 #[link_name = "_pclose"]
1435                 unsafe fn pclose(stream: *FILE) -> c_int;
1436
1437                 #[link_name = "_fdopen"]
1438                 #[fast_ffi]
1439                 unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
1440
1441                 #[link_name = "_fileno"]
1442                 unsafe fn fileno(stream: *FILE) -> c_int;
1443             }
1444         }
1445
1446         #[nolink]
1447         #[abi = "cdecl"]
1448         pub mod fcntl {
1449             use libc::types::os::arch::c95::{c_int, c_char};
1450             pub extern {
1451                 #[link_name = "_open"]
1452                 unsafe fn open(path: *c_char, oflag: c_int, mode: c_int)
1453                             -> c_int;
1454
1455                 #[link_name = "_creat"]
1456                 unsafe fn creat(path: *c_char, mode: c_int) -> c_int;
1457             }
1458         }
1459
1460         #[nolink]
1461         #[abi = "cdecl"]
1462         pub mod dirent {
1463             // Not supplied at all.
1464         }
1465
1466         #[nolink]
1467         #[abi = "cdecl"]
1468         pub mod unistd {
1469             use libc::types::common::c95::c_void;
1470             use libc::types::os::arch::c95::{c_int, c_uint, c_char,
1471                                              c_long, size_t};
1472             use libc::types::os::arch::c99::intptr_t;
1473
1474             pub extern {
1475                 #[link_name = "_access"]
1476                 unsafe fn access(path: *c_char, amode: c_int) -> c_int;
1477
1478                 #[link_name = "_chdir"]
1479                 unsafe fn chdir(dir: *c_char) -> c_int;
1480
1481                 #[link_name = "_close"]
1482                 unsafe fn close(fd: c_int) -> c_int;
1483
1484                 #[link_name = "_dup"]
1485                 unsafe fn dup(fd: c_int) -> c_int;
1486
1487                 #[link_name = "_dup2"]
1488                 unsafe fn dup2(src: c_int, dst: c_int) -> c_int;
1489
1490                 #[link_name = "_execv"]
1491                 unsafe fn execv(prog: *c_char, argv: **c_char) -> intptr_t;
1492
1493                 #[link_name = "_execve"]
1494                 unsafe fn execve(prog: *c_char, argv: **c_char,
1495                           envp: **c_char) -> c_int;
1496
1497                 #[link_name = "_execvp"]
1498                 unsafe fn execvp(c: *c_char, argv: **c_char) -> c_int;
1499
1500                 #[link_name = "_execvpe"]
1501                 unsafe fn execvpe(c: *c_char, argv: **c_char,
1502                            envp: **c_char) -> c_int;
1503
1504                 #[link_name = "_getcwd"]
1505                 unsafe fn getcwd(buf: *c_char, size: size_t) -> *c_char;
1506
1507                 #[link_name = "_getpid"]
1508                 unsafe fn getpid() -> c_int;
1509
1510                 #[link_name = "_isatty"]
1511                 unsafe fn isatty(fd: c_int) -> c_int;
1512
1513                 #[link_name = "_lseek"]
1514                 unsafe fn lseek(fd: c_int, offset: c_long, origin: c_int)
1515                              -> c_long;
1516
1517                 #[link_name = "_pipe"]
1518                 unsafe fn pipe(fds: *mut c_int, psize: c_uint,
1519                         textmode: c_int) -> c_int;
1520
1521                 #[link_name = "_read"]
1522                 #[fast_ffi]
1523                 unsafe fn read(fd: c_int, buf: *mut c_void, count: c_uint)
1524                             -> c_int;
1525
1526                 #[link_name = "_rmdir"]
1527                 unsafe fn rmdir(path: *c_char) -> c_int;
1528
1529                 #[link_name = "_unlink"]
1530                 unsafe fn unlink(c: *c_char) -> c_int;
1531
1532                 #[link_name = "_write"]
1533                 #[fast_ffi]
1534                 unsafe fn write(fd: c_int, buf: *c_void, count: c_uint)
1535                              -> c_int;
1536             }
1537         }
1538     }
1539
1540
1541     #[cfg(target_os = "linux")]
1542     #[cfg(target_os = "android")]
1543     #[cfg(target_os = "macos")]
1544     #[cfg(target_os = "freebsd")]
1545     pub mod posix88 {
1546         pub mod stat_ {
1547             use libc::types::os::arch::c95::{c_char, c_int};
1548             use libc::types::os::arch::posix01::stat;
1549             use libc::types::os::arch::posix88::mode_t;
1550
1551             #[nolink]
1552             #[abi = "cdecl"]
1553             pub extern {
1554                 unsafe fn chmod(path: *c_char, mode: mode_t) -> c_int;
1555                 unsafe fn fchmod(fd: c_int, mode: mode_t) -> c_int;
1556
1557                 #[cfg(target_os = "linux")]
1558                 #[cfg(target_os = "freebsd")]
1559                 #[cfg(target_os = "android")]
1560                unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
1561
1562                 #[cfg(target_os = "macos")]
1563                 #[link_name = "fstat64"]
1564                 unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
1565
1566                 unsafe fn mkdir(path: *c_char, mode: mode_t) -> c_int;
1567                 unsafe fn mkfifo(path: *c_char, mode: mode_t) -> c_int;
1568
1569                 #[cfg(target_os = "linux")]
1570                 #[cfg(target_os = "freebsd")]
1571                 #[cfg(target_os = "android")]
1572                 unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
1573
1574                 #[cfg(target_os = "macos")]
1575                 #[link_name = "stat64"]
1576                 unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
1577             }
1578         }
1579
1580         #[nolink]
1581         #[abi = "cdecl"]
1582         pub mod stdio {
1583             use libc::types::common::c95::FILE;
1584             use libc::types::os::arch::c95::{c_char, c_int};
1585
1586             pub extern {
1587                 unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
1588                 unsafe fn pclose(stream: *FILE) -> c_int;
1589                 unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
1590                 unsafe fn fileno(stream: *FILE) -> c_int;
1591             }
1592         }
1593
1594         #[nolink]
1595         #[abi = "cdecl"]
1596         pub mod fcntl {
1597             use libc::types::os::arch::c95::{c_char, c_int};
1598             use libc::types::os::arch::posix88::mode_t;
1599
1600             pub extern {
1601                 unsafe fn open(path: *c_char, oflag: c_int, mode: c_int)
1602                             -> c_int;
1603                 unsafe fn creat(path: *c_char, mode: mode_t) -> c_int;
1604                 unsafe fn fcntl(fd: c_int, cmd: c_int) -> c_int;
1605             }
1606         }
1607
1608         #[nolink]
1609         #[abi = "cdecl"]
1610         pub mod dirent {
1611             use libc::types::common::posix88::{DIR, dirent_t};
1612             use libc::types::os::arch::c95::{c_char, c_int, c_long};
1613
1614             // NB: On OS X opendir and readdir have two versions,
1615             // one for 32-bit kernelspace and one for 64.
1616             // We should be linking to the 64-bit ones, called
1617             // opendir$INODE64, etc. but for some reason rustc
1618             // doesn't link it correctly on i686, so we're going
1619             // through a C function that mysteriously does work.
1620             pub unsafe fn opendir(dirname: *c_char) -> *DIR {
1621                 rust_opendir(dirname)
1622             }
1623             pub unsafe fn readdir(dirp: *DIR) -> *dirent_t {
1624                 rust_readdir(dirp)
1625             }
1626
1627             extern {
1628                 unsafe fn rust_opendir(dirname: *c_char) -> *DIR;
1629                 unsafe fn rust_readdir(dirp: *DIR) -> *dirent_t;
1630             }
1631
1632             pub extern {
1633                 unsafe fn closedir(dirp: *DIR) -> c_int;
1634                 unsafe fn rewinddir(dirp: *DIR);
1635                 unsafe fn seekdir(dirp: *DIR, loc: c_long);
1636                 unsafe fn telldir(dirp: *DIR) -> c_long;
1637             }
1638         }
1639
1640         #[nolink]
1641         #[abi = "cdecl"]
1642         pub mod unistd {
1643             use libc::types::common::c95::c_void;
1644             use libc::types::os::arch::c95::{c_char, c_int, c_long, c_uint};
1645             use libc::types::os::arch::c95::{size_t};
1646             use libc::types::os::arch::posix88::{gid_t, off_t, pid_t};
1647             use libc::types::os::arch::posix88::{ssize_t, uid_t};
1648
1649             pub extern {
1650                 unsafe fn access(path: *c_char, amode: c_int) -> c_int;
1651                 unsafe fn alarm(seconds: c_uint) -> c_uint;
1652                 unsafe fn chdir(dir: *c_char) -> c_int;
1653                 unsafe fn chown(path: *c_char, uid: uid_t, gid: gid_t)
1654                              -> c_int;
1655                 unsafe fn close(fd: c_int) -> c_int;
1656                 unsafe fn dup(fd: c_int) -> c_int;
1657                 unsafe fn dup2(src: c_int, dst: c_int) -> c_int;
1658                 unsafe fn execv(prog: *c_char, argv: **c_char) -> c_int;
1659                 unsafe fn execve(prog: *c_char,
1660                                  argv: **c_char,
1661                                  envp: **c_char)
1662                               -> c_int;
1663                 unsafe fn execvp(c: *c_char, argv: **c_char) -> c_int;
1664                 unsafe fn fork() -> pid_t;
1665                 unsafe fn fpathconf(filedes: c_int, name: c_int) -> c_long;
1666                 unsafe fn getcwd(buf: *c_char, size: size_t) -> *c_char;
1667                 unsafe fn getegid() -> gid_t;
1668                 unsafe fn geteuid() -> uid_t;
1669                 unsafe fn getgid() -> gid_t ;
1670                 unsafe fn getgroups(ngroups_max: c_int, groups: *mut gid_t)
1671                                  -> c_int;
1672                 unsafe fn getlogin() -> *c_char;
1673                 unsafe fn getopt(argc: c_int, argv: **c_char, optstr: *c_char)
1674                               -> c_int;
1675                 unsafe fn getpgrp() -> pid_t;
1676                 unsafe fn getpid() -> pid_t;
1677                 unsafe fn getppid() -> pid_t;
1678                 unsafe fn getuid() -> uid_t;
1679                 unsafe fn isatty(fd: c_int) -> c_int;
1680                 unsafe fn link(src: *c_char, dst: *c_char) -> c_int;
1681                 unsafe fn lseek(fd: c_int, offset: off_t, whence: c_int)
1682                              -> off_t;
1683                 unsafe fn pathconf(path: *c_char, name: c_int) -> c_long;
1684                 unsafe fn pause() -> c_int;
1685                 unsafe fn pipe(fds: *mut c_int) -> c_int;
1686                 #[fast_ffi]
1687                 unsafe fn read(fd: c_int, buf: *mut c_void,
1688                         count: size_t) -> ssize_t;
1689                 unsafe fn rmdir(path: *c_char) -> c_int;
1690                 unsafe fn setgid(gid: gid_t) -> c_int;
1691                 unsafe fn setpgid(pid: pid_t, pgid: pid_t) -> c_int;
1692                 unsafe fn setsid() -> pid_t;
1693                 unsafe fn setuid(uid: uid_t) -> c_int;
1694                 unsafe fn sleep(secs: c_uint) -> c_uint;
1695                 unsafe fn sysconf(name: c_int) -> c_long;
1696                 unsafe fn tcgetpgrp(fd: c_int) -> pid_t;
1697                 unsafe fn ttyname(fd: c_int) -> *c_char;
1698                 unsafe fn unlink(c: *c_char) -> c_int;
1699                 #[fast_ffi]
1700                 unsafe fn write(fd: c_int, buf: *c_void, count: size_t)
1701                              -> ssize_t;
1702             }
1703         }
1704
1705         #[nolink]
1706         #[abi = "cdecl"]
1707         pub mod signal {
1708             use libc::types::os::arch::c95::{c_int};
1709             use libc::types::os::arch::posix88::{pid_t};
1710
1711             pub extern {
1712                 unsafe fn kill(pid: pid_t, sig: c_int) -> c_int;
1713             }
1714         }
1715     }
1716
1717     #[cfg(target_os = "linux")]
1718     #[cfg(target_os = "android")]
1719     #[cfg(target_os = "macos")]
1720     #[cfg(target_os = "freebsd")]
1721     pub mod posix01 {
1722         #[nolink]
1723         #[abi = "cdecl"]
1724         pub mod stat_ {
1725             use libc::types::os::arch::c95::{c_char, c_int};
1726             use libc::types::os::arch::posix01::stat;
1727
1728             pub extern {
1729                 #[cfg(target_os = "linux")]
1730                 #[cfg(target_os = "freebsd")]
1731                 #[cfg(target_os = "android")]
1732                 unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
1733
1734                 #[cfg(target_os = "macos")]
1735                 #[link_name = "lstat64"]
1736                 unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
1737             }
1738         }
1739
1740         #[nolink]
1741         #[abi = "cdecl"]
1742         pub mod unistd {
1743             use libc::types::os::arch::c95::{c_char, c_int, size_t};
1744             use libc::types::os::arch::posix88::{ssize_t};
1745
1746             pub extern {
1747                 unsafe fn readlink(path: *c_char, buf: *mut c_char,
1748                             bufsz: size_t) -> ssize_t;
1749
1750                 unsafe fn fsync(fd: c_int) -> c_int;
1751
1752                 #[cfg(target_os = "linux")]
1753                 #[cfg(target_os = "android")]
1754                 unsafe fn fdatasync(fd: c_int) -> c_int;
1755
1756                 unsafe fn setenv(name: *c_char, val: *c_char,
1757                           overwrite: c_int) -> c_int;
1758                 unsafe fn unsetenv(name: *c_char) -> c_int;
1759                 unsafe fn putenv(string: *c_char) -> c_int;
1760
1761                 unsafe fn symlink(path1: *c_char, path2: *c_char) -> c_int;
1762             }
1763         }
1764
1765         #[nolink]
1766         #[abi = "cdecl"]
1767         pub mod wait {
1768             use libc::types::os::arch::c95::{c_int};
1769             use libc::types::os::arch::posix88::{pid_t};
1770
1771             pub extern {
1772                 unsafe fn waitpid(pid: pid_t,
1773                                   status: *mut c_int,
1774                                   options: c_int)
1775                                -> pid_t;
1776             }
1777         }
1778
1779         #[nolink]
1780         #[abi = "cdecl"]
1781         pub mod glob {
1782             use libc::types::common::c95::{c_void};
1783             use libc::types::os::arch::c95::{c_char, c_int};
1784             use libc::types::os::common::posix01::{glob_t};
1785
1786             pub extern {
1787                 unsafe fn glob(pattern: *c_char, flags: c_int,
1788                                errfunc: *c_void, // XXX callback
1789                                pglob: *mut glob_t);
1790                 unsafe fn globfree(pglob: *mut glob_t);
1791             }
1792         }
1793     }
1794
1795     #[cfg(target_os = "win32")]
1796     pub mod posix01 {
1797         pub mod stat_ {
1798         }
1799
1800         pub mod unistd {
1801         }
1802
1803         pub mod glob {
1804         }
1805     }
1806
1807
1808     #[cfg(target_os = "win32")]
1809     #[cfg(target_os = "linux")]
1810     #[cfg(target_os = "android")]
1811     #[cfg(target_os = "macos")]
1812     #[cfg(target_os = "freebsd")]
1813     pub mod posix08 {
1814         pub mod unistd {
1815         }
1816     }
1817
1818
1819     #[cfg(target_os = "macos")]
1820     #[cfg(target_os = "freebsd")]
1821     pub mod bsd44 {
1822         use libc::types::common::c95::{c_void};
1823         use libc::types::os::arch::c95::{c_char, c_int, c_uint, size_t};
1824
1825         #[abi = "cdecl"]
1826         pub extern {
1827             unsafe fn sysctl(name: *c_int, namelen: c_uint,
1828                       oldp: *mut c_void, oldlenp: *mut size_t,
1829                       newp: *c_void, newlen: size_t) -> c_int;
1830
1831             unsafe fn sysctlbyname(name: *c_char,
1832                             oldp: *mut c_void, oldlenp: *mut size_t,
1833                             newp: *c_void, newlen: size_t) -> c_int;
1834
1835             unsafe fn sysctlnametomib(name: *c_char, mibp: *mut c_int,
1836                                sizep: *mut size_t) -> c_int;
1837
1838             unsafe fn getdtablesize() -> c_int;
1839         }
1840     }
1841
1842
1843     #[cfg(target_os = "linux")]
1844     #[cfg(target_os = "android")]
1845     pub mod bsd44 {
1846         use libc::types::os::arch::c95::{c_int};
1847
1848         #[abi = "cdecl"]
1849         pub extern {
1850             unsafe fn getdtablesize() -> c_int;
1851         }
1852     }
1853
1854
1855     #[cfg(target_os = "win32")]
1856     pub mod bsd44 {
1857     }
1858
1859     #[cfg(target_os = "macos")]
1860     #[nolink]
1861     pub mod extra {
1862         use libc::types::os::arch::c95::{c_char, c_int};
1863
1864         #[abi = "cdecl"]
1865         pub extern {
1866             unsafe fn _NSGetExecutablePath(buf: *mut c_char,
1867                                            bufsize: *mut u32)
1868                                         -> c_int;
1869         }
1870     }
1871
1872     #[cfg(target_os = "freebsd")]
1873     pub mod extra {
1874     }
1875
1876     #[cfg(target_os = "linux")]
1877     #[cfg(target_os = "android")]
1878     pub mod extra {
1879     }
1880
1881
1882     #[cfg(target_os = "win32")]
1883     pub mod extra {
1884
1885         pub mod kernel32 {
1886             use libc::types::os::arch::c95::{c_uint};
1887             use libc::types::os::arch::extra::{BOOL, DWORD, HMODULE};
1888             use libc::types::os::arch::extra::{LPCWSTR, LPWSTR, LPCTSTR,
1889                                                LPTSTR, LPTCH, LPDWORD, LPVOID};
1890             use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, LPSTARTUPINFO,
1891                                                LPPROCESS_INFORMATION};
1892             use libc::types::os::arch::extra::{HANDLE, LPHANDLE};
1893
1894             #[abi = "stdcall"]
1895             pub extern "stdcall" {
1896                 unsafe fn GetEnvironmentVariableW(n: LPCWSTR,
1897                                                   v: LPWSTR,
1898                                                   nsize: DWORD)
1899                                                -> DWORD;
1900                 unsafe fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR)
1901                                                -> BOOL;
1902                 unsafe fn GetEnvironmentStringsA() -> LPTCH;
1903                 unsafe fn FreeEnvironmentStringsA(env_ptr: LPTCH) -> BOOL;
1904
1905                 unsafe fn GetModuleFileNameW(hModule: HMODULE,
1906                                              lpFilename: LPWSTR,
1907                                              nSize: DWORD)
1908                                           -> DWORD;
1909                 unsafe fn CreateDirectoryW(lpPathName: LPCWSTR,
1910                                            lpSecurityAttributes:
1911                                            LPSECURITY_ATTRIBUTES)
1912                                         -> BOOL;
1913                 unsafe fn CopyFileW(lpExistingFileName: LPCWSTR,
1914                                     lpNewFileName: LPCWSTR,
1915                                     bFailIfExists: BOOL)
1916                                  -> BOOL;
1917                 unsafe fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
1918                 unsafe fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
1919                 unsafe fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
1920
1921                 unsafe fn GetLastError() -> DWORD;
1922                 unsafe fn FindFirstFileW(fileName: *u16,
1923                                         findFileData: HANDLE)
1924                     -> HANDLE;
1925                 unsafe fn FindNextFileW(findFile: HANDLE,
1926                                        findFileData: HANDLE)
1927                     -> BOOL;
1928                 unsafe fn FindClose(findFile: HANDLE) -> BOOL;
1929                 unsafe fn DuplicateHandle(hSourceProcessHandle: HANDLE,
1930                                           hSourceHandle: HANDLE,
1931                                           hTargetProcessHandle: HANDLE,
1932                                           lpTargetHandle: LPHANDLE,
1933                                           dwDesiredAccess: DWORD,
1934                                           bInheritHandle: BOOL,
1935                                           dwOptions: DWORD) -> BOOL;
1936                 unsafe fn CloseHandle(hObject: HANDLE) -> BOOL;
1937                 unsafe fn OpenProcess(dwDesiredAccess: DWORD,
1938                                       bInheritHandle: BOOL,
1939                                       dwProcessId: DWORD) -> HANDLE;
1940                 unsafe fn GetCurrentProcess() -> HANDLE;
1941                 unsafe fn CreateProcessA(lpApplicationName: LPCTSTR,
1942                                          lpCommandLine: LPTSTR,
1943                                          lpProcessAttributes: LPSECURITY_ATTRIBUTES,
1944                                          lpThreadAttributes: LPSECURITY_ATTRIBUTES,
1945                                          bInheritHandles: BOOL,
1946                                          dwCreationFlags: DWORD,
1947                                          lpEnvironment: LPVOID,
1948                                          lpCurrentDirectory: LPCTSTR,
1949                                          lpStartupInfo: LPSTARTUPINFO,
1950                                          lpProcessInformation: LPPROCESS_INFORMATION) -> BOOL;
1951                 unsafe fn WaitForSingleObject(hHandle: HANDLE, dwMilliseconds: DWORD) -> DWORD;
1952                 unsafe fn TerminateProcess(hProcess: HANDLE, uExitCode: c_uint) -> BOOL;
1953                 unsafe fn GetExitCodeProcess(hProcess: HANDLE, lpExitCode: LPDWORD) -> BOOL;
1954             }
1955         }
1956
1957         pub mod msvcrt {
1958             use libc::types::os::arch::c95::{c_int, c_long};
1959
1960             #[abi = "cdecl"]
1961             #[nolink]
1962             pub extern {
1963                 #[link_name = "_commit"]
1964                 unsafe fn commit(fd: c_int) -> c_int;
1965
1966                 #[link_name = "_get_osfhandle"]
1967                 unsafe fn get_osfhandle(fd: c_int) -> c_long;
1968             }
1969         }
1970     }
1971 }