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.
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.
12 * Bindings for the C standard library and other platform libraries
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.
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.
26 * We consider the following specs reasonably normative with respect
27 * to interoperating with the C standard library (libc/msvcrt):
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').
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.
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.
44 * See standards(7) in linux-manpages for more details.
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
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
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
66 #[allow(non_camel_case_types)];
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.
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::*;
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::*;
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::*;
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::*;
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::*;
110 pub use libc::funcs::bsd44::*;
111 pub use libc::funcs::extra::*;
113 #[cfg(target_os = "win32")]
114 pub use libc::funcs::extra::kernel32::*;
115 #[cfg(target_os = "win32")]
116 pub use libc::funcs::extra::msvcrt::*;
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
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};
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};
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};
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};
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};
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};
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};
179 // Types tend to vary *per architecture* so we pull their definitions out
182 // Standard types that are opaque or common, so are not per-target.
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;
208 // Standard types that are scalar but vary by OS and arch.
210 #[cfg(target_os = "linux")]
211 #[cfg(target_os = "android")]
215 use libc::types::common::c95::{c_void};
216 use libc::types::os::arch::c95::{c_char, size_t};
231 #[cfg(target_arch = "x86")]
232 #[cfg(target_arch = "arm")]
233 #[cfg(target_arch = "mips")]
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;
254 pub type c_longlong = i64;
255 pub type c_ulonglong = u64;
256 pub type intptr_t = int;
257 pub type uintptr_t = uint;
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;
271 use libc::types::os::arch::c95::{c_int, c_short, c_long,
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};
277 pub type nlink_t = u32;
278 pub type blksize_t = i32;
279 pub type blkcnt_t = i32;
291 st_blksize: blksize_t,
294 st_atime_nsec: c_long,
296 st_mtime_nsec: c_long,
298 st_ctime_nsec: c_long,
308 #[cfg(target_arch = "x86_64")]
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;
329 pub type c_longlong = i64;
330 pub type c_ulonglong = u64;
331 pub type intptr_t = int;
332 pub type uintptr_t = uint;
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;
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};
351 pub type nlink_t = u64;
352 pub type blksize_t = i64;
353 pub type blkcnt_t = i64;
364 st_blksize: blksize_t,
367 st_atime_nsec: c_long,
369 st_mtime_nsec: c_long,
371 st_ctime_nsec: c_long,
372 __unused: [c_long, ..3],
384 #[cfg(target_os = "freebsd")]
388 use libc::types::common::c95::{c_void};
389 use libc::types::os::arch::c95::{c_char, c_int, size_t};
408 #[cfg(target_arch = "x86_64")]
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;
429 pub type c_longlong = i64;
430 pub type c_ulonglong = u64;
431 pub type intptr_t = int;
432 pub type uintptr_t = uint;
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;
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};
452 pub type nlink_t = u16;
453 pub type blksize_t = i64;
454 pub type blkcnt_t = i64;
455 pub type fflags_t = u32;
465 st_atime_nsec: c_long,
467 st_mtime_nsec: c_long,
469 st_ctime_nsec: c_long,
472 st_blksize: blksize_t,
476 st_birthtime: time_t,
477 st_birthtime_nsec: c_long,
478 __unused: [uint8_t, ..2],
490 #[cfg(target_os = "win32")]
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;
499 // Note: this is the struct called stat64 in win32. Not stat,
517 #[cfg(target_arch = "x86")]
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;
538 pub type c_longlong = i64;
539 pub type c_ulonglong = u64;
540 pub type intptr_t = int;
541 pub type uintptr_t = uint;
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;
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};
565 pub type BOOL = c_int;
567 pub type CCHAR = c_char;
568 pub type CHAR = c_char;
570 pub type DWORD = c_ulong;
571 pub type DWORDLONG = c_ulonglong;
573 pub type HANDLE = LPVOID;
574 pub type HMODULE = c_uint;
576 pub type LONG_PTR = c_long;
578 pub type LPCWSTR = *WCHAR;
579 pub type LPCSTR = *CHAR;
580 pub type LPCTSTR = *CHAR;
581 pub type LPTCH = *CHAR;
583 pub type LPWSTR = *mut WCHAR;
584 pub type LPSTR = *mut CHAR;
585 pub type LPTSTR = *mut CHAR;
587 // Not really, but opaque to us.
588 pub type LPSECURITY_ATTRIBUTES = LPVOID;
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;
596 pub type LRESULT = LONG_PTR;
597 pub type PBOOL = *mut BOOL;
598 pub type WCHAR = wchar_t;
601 pub type time64_t = i64;
602 pub type int64 = i64;
604 pub struct STARTUPINFO {
613 dwXCountChars: DWORD,
614 dwYCountCharts: DWORD,
615 dwFillAttribute: DWORD,
624 pub type LPSTARTUPINFO = *mut STARTUPINFO;
626 pub struct PROCESS_INFORMATION {
632 pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
637 #[cfg(target_os = "macos")]
641 use libc::types::common::c95::{c_void};
642 use libc::types::os::arch::c95::{c_char, c_int, size_t};
661 #[cfg(target_arch = "x86")]
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;
682 pub type c_longlong = i64;
683 pub type c_ulonglong = u64;
684 pub type intptr_t = int;
685 pub type uintptr_t = uint;
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;
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};
704 pub type nlink_t = u16;
705 pub type blksize_t = i64;
706 pub type blkcnt_t = i32;
717 st_atime_nsec: c_long,
719 st_mtime_nsec: c_long,
721 st_ctime_nsec: c_long,
722 st_birthtime: time_t,
723 st_birthtime_nsec: c_long,
726 st_blksize: blksize_t,
730 st_qspare: [int64_t, ..2],
741 #[cfg(target_arch = "x86_64")]
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;
762 pub type c_longlong = i64;
763 pub type c_ulonglong = u64;
764 pub type intptr_t = int;
765 pub type uintptr_t = uint;
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;
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};
785 pub type nlink_t = u16;
786 pub type blksize_t = i64;
787 pub type blkcnt_t = i32;
798 st_atime_nsec: c_long,
800 st_mtime_nsec: c_long,
802 st_ctime_nsec: c_long,
803 st_birthtime: time_t,
804 st_birthtime_nsec: c_long,
807 st_blksize: blksize_t,
811 st_qspare: [int64_t, ..2],
825 // Consts tend to vary per OS so we pull their definitions out
828 #[cfg(target_os = "win32")]
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;
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;
885 use libc::types::os::arch::extra::{DWORD, BOOL};
887 pub static TRUE : BOOL = 1;
888 pub static FALSE : BOOL = 0;
890 pub static O_TEXT : int = 16384;
891 pub static O_BINARY : int = 32768;
892 pub static O_NOINHERIT: int = 128;
894 pub static ERROR_SUCCESS : int = 0;
895 pub static ERROR_INSUFFICIENT_BUFFER : int = 122;
896 pub static INVALID_HANDLE_VALUE: int = -1;
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;
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;
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;
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;
936 pub static DUPLICATE_CLOSE_SOURCE : DWORD = 0x00000001;
937 pub static DUPLICATE_SAME_ACCESS : DWORD = 0x00000002;
939 pub static INFINITE : DWORD = -1;
940 pub static STILL_ACTIVE : DWORD = 259;
945 #[cfg(target_os = "linux")]
946 #[cfg(target_os = "android")]
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;
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;
1012 pub static SIGTRAP : int = 5;
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;
1022 pub static GLOB_NOSPACE : int = 1;
1023 pub static GLOB_ABORTED : int = 2;
1024 pub static GLOB_NOMATCH : int = 3;
1031 pub static O_RSYNC : int = 1052672;
1032 pub static O_DSYNC : int = 4096;
1033 pub static O_SYNC : int = 1052672;
1037 #[cfg(target_os = "freebsd")]
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;
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;
1103 pub static SIGTRAP : int = 5;
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;
1113 pub static GLOB_NOSPACE : int = -1;
1114 pub static GLOB_ABORTED : int = -2;
1115 pub static GLOB_NOMATCH : int = -3;
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;
1129 #[cfg(target_os = "macos")]
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;
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;
1195 pub static SIGTRAP : int = 5;
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;
1205 pub static GLOB_NOSPACE : int = -1;
1206 pub static GLOB_ABORTED : int = -2;
1207 pub static GLOB_NOMATCH : int = -3;
1214 pub static O_DSYNC : int = 4194304;
1215 pub static O_SYNC : int = 128;
1216 pub static F_FULLFSYNC : int = 51;
1223 // Thankfull most of c95 is universally available and does not vary by OS
1224 // or anything. The same is not true of POSIX.
1230 use libc::types::os::arch::c95::{c_char, c_int};
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;
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};
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;
1270 unsafe fn fgets(buf: *mut c_char, n: c_int,
1271 stream: *FILE) -> *c_char;
1273 unsafe fn fputc(c: c_int, stream: *FILE) -> c_int;
1275 unsafe fn fputs(s: *c_char, stream: *FILE) -> *c_char;
1276 // Omitted: getc, getchar (might be macros).
1278 // Omitted: gets, so ridiculously unsafe that it should not
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;
1285 unsafe fn fread(ptr: *mut c_void, size: size_t,
1286 nobj: size_t, stream: *FILE) -> size_t;
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);
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};
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)
1319 unsafe fn strtoul(s: *c_char, endp: **c_char, base: c_int)
1322 unsafe fn calloc(nobj: size_t, size: size_t) -> *c_void;
1324 unsafe fn malloc(size: size_t) -> *c_void;
1326 unsafe fn realloc(p: *c_void, size: size_t) -> *c_void;
1328 unsafe fn free(p: *c_void);
1329 unsafe fn abort() -> !;
1330 unsafe fn exit(status: c_int) -> !;
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);
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};
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)
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)
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)
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)
1369 unsafe fn wcslen(buf: *wchar_t) -> size_t;
1371 // These are fine to execute on the Rust stack. They must be,
1372 // in fact, because LLVM generates calls to them!
1375 unsafe fn memcpy(s: *c_void, ct: *c_void, n: size_t)
1379 unsafe fn memmove(s: *c_void, ct: *c_void, n: size_t)
1383 unsafe fn memcmp(cx: *c_void, ct: *c_void, n: size_t)
1387 unsafe fn memchr(cx: *c_void, c: c_int, n: size_t) -> *c_void;
1390 unsafe fn memset(s: *c_void, c: c_int, n: size_t) -> *c_void;
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.
1401 #[cfg(target_os = "win32")]
1406 use libc::types::os::common::posix01::stat;
1407 use libc::types::os::arch::c95::{c_int, c_char};
1410 #[link_name = "_chmod"]
1411 unsafe fn chmod(path: *c_char, mode: c_int) -> c_int;
1413 #[link_name = "_mkdir"]
1414 unsafe fn mkdir(path: *c_char) -> c_int;
1416 #[link_name = "_fstat64"]
1417 unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
1419 #[link_name = "_stat64"]
1420 unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
1427 use libc::types::common::c95::FILE;
1428 use libc::types::os::arch::c95::{c_int, c_char};
1431 #[link_name = "_popen"]
1432 unsafe fn popen(command: *c_char, mode: *c_char) -> *FILE;
1434 #[link_name = "_pclose"]
1435 unsafe fn pclose(stream: *FILE) -> c_int;
1437 #[link_name = "_fdopen"]
1439 unsafe fn fdopen(fd: c_int, mode: *c_char) -> *FILE;
1441 #[link_name = "_fileno"]
1442 unsafe fn fileno(stream: *FILE) -> c_int;
1449 use libc::types::os::arch::c95::{c_int, c_char};
1451 #[link_name = "_open"]
1452 unsafe fn open(path: *c_char, oflag: c_int, mode: c_int)
1455 #[link_name = "_creat"]
1456 unsafe fn creat(path: *c_char, mode: c_int) -> c_int;
1463 // Not supplied at all.
1469 use libc::types::common::c95::c_void;
1470 use libc::types::os::arch::c95::{c_int, c_uint, c_char,
1472 use libc::types::os::arch::c99::intptr_t;
1475 #[link_name = "_access"]
1476 unsafe fn access(path: *c_char, amode: c_int) -> c_int;
1478 #[link_name = "_chdir"]
1479 unsafe fn chdir(dir: *c_char) -> c_int;
1481 #[link_name = "_close"]
1482 unsafe fn close(fd: c_int) -> c_int;
1484 #[link_name = "_dup"]
1485 unsafe fn dup(fd: c_int) -> c_int;
1487 #[link_name = "_dup2"]
1488 unsafe fn dup2(src: c_int, dst: c_int) -> c_int;
1490 #[link_name = "_execv"]
1491 unsafe fn execv(prog: *c_char, argv: **c_char) -> intptr_t;
1493 #[link_name = "_execve"]
1494 unsafe fn execve(prog: *c_char, argv: **c_char,
1495 envp: **c_char) -> c_int;
1497 #[link_name = "_execvp"]
1498 unsafe fn execvp(c: *c_char, argv: **c_char) -> c_int;
1500 #[link_name = "_execvpe"]
1501 unsafe fn execvpe(c: *c_char, argv: **c_char,
1502 envp: **c_char) -> c_int;
1504 #[link_name = "_getcwd"]
1505 unsafe fn getcwd(buf: *c_char, size: size_t) -> *c_char;
1507 #[link_name = "_getpid"]
1508 unsafe fn getpid() -> c_int;
1510 #[link_name = "_isatty"]
1511 unsafe fn isatty(fd: c_int) -> c_int;
1513 #[link_name = "_lseek"]
1514 unsafe fn lseek(fd: c_int, offset: c_long, origin: c_int)
1517 #[link_name = "_pipe"]
1518 unsafe fn pipe(fds: *mut c_int, psize: c_uint,
1519 textmode: c_int) -> c_int;
1521 #[link_name = "_read"]
1523 unsafe fn read(fd: c_int, buf: *mut c_void, count: c_uint)
1526 #[link_name = "_rmdir"]
1527 unsafe fn rmdir(path: *c_char) -> c_int;
1529 #[link_name = "_unlink"]
1530 unsafe fn unlink(c: *c_char) -> c_int;
1532 #[link_name = "_write"]
1534 unsafe fn write(fd: c_int, buf: *c_void, count: c_uint)
1541 #[cfg(target_os = "linux")]
1542 #[cfg(target_os = "android")]
1543 #[cfg(target_os = "macos")]
1544 #[cfg(target_os = "freebsd")]
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;
1554 unsafe fn chmod(path: *c_char, mode: mode_t) -> c_int;
1555 unsafe fn fchmod(fd: c_int, mode: mode_t) -> c_int;
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;
1562 #[cfg(target_os = "macos")]
1563 #[link_name = "fstat64"]
1564 unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
1566 unsafe fn mkdir(path: *c_char, mode: mode_t) -> c_int;
1567 unsafe fn mkfifo(path: *c_char, mode: mode_t) -> c_int;
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;
1574 #[cfg(target_os = "macos")]
1575 #[link_name = "stat64"]
1576 unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
1583 use libc::types::common::c95::FILE;
1584 use libc::types::os::arch::c95::{c_char, c_int};
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;
1597 use libc::types::os::arch::c95::{c_char, c_int};
1598 use libc::types::os::arch::posix88::mode_t;
1601 unsafe fn open(path: *c_char, oflag: c_int, mode: 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;
1611 use libc::types::common::posix88::{DIR, dirent_t};
1612 use libc::types::os::arch::c95::{c_char, c_int, c_long};
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)
1623 pub unsafe fn readdir(dirp: *DIR) -> *dirent_t {
1628 unsafe fn rust_opendir(dirname: *c_char) -> *DIR;
1629 unsafe fn rust_readdir(dirp: *DIR) -> *dirent_t;
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;
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};
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)
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,
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)
1672 unsafe fn getlogin() -> *c_char;
1673 unsafe fn getopt(argc: c_int, argv: **c_char, optstr: *c_char)
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)
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;
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;
1700 unsafe fn write(fd: c_int, buf: *c_void, count: size_t)
1708 use libc::types::os::arch::c95::{c_int};
1709 use libc::types::os::arch::posix88::{pid_t};
1712 unsafe fn kill(pid: pid_t, sig: c_int) -> c_int;
1717 #[cfg(target_os = "linux")]
1718 #[cfg(target_os = "android")]
1719 #[cfg(target_os = "macos")]
1720 #[cfg(target_os = "freebsd")]
1725 use libc::types::os::arch::c95::{c_char, c_int};
1726 use libc::types::os::arch::posix01::stat;
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;
1734 #[cfg(target_os = "macos")]
1735 #[link_name = "lstat64"]
1736 unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
1743 use libc::types::os::arch::c95::{c_char, c_int, size_t};
1744 use libc::types::os::arch::posix88::{ssize_t};
1747 unsafe fn readlink(path: *c_char, buf: *mut c_char,
1748 bufsz: size_t) -> ssize_t;
1750 unsafe fn fsync(fd: c_int) -> c_int;
1752 #[cfg(target_os = "linux")]
1753 #[cfg(target_os = "android")]
1754 unsafe fn fdatasync(fd: c_int) -> c_int;
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;
1761 unsafe fn symlink(path1: *c_char, path2: *c_char) -> c_int;
1768 use libc::types::os::arch::c95::{c_int};
1769 use libc::types::os::arch::posix88::{pid_t};
1772 unsafe fn waitpid(pid: pid_t,
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};
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);
1795 #[cfg(target_os = "win32")]
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")]
1819 #[cfg(target_os = "macos")]
1820 #[cfg(target_os = "freebsd")]
1822 use libc::types::common::c95::{c_void};
1823 use libc::types::os::arch::c95::{c_char, c_int, c_uint, size_t};
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;
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;
1835 unsafe fn sysctlnametomib(name: *c_char, mibp: *mut c_int,
1836 sizep: *mut size_t) -> c_int;
1838 unsafe fn getdtablesize() -> c_int;
1843 #[cfg(target_os = "linux")]
1844 #[cfg(target_os = "android")]
1846 use libc::types::os::arch::c95::{c_int};
1850 unsafe fn getdtablesize() -> c_int;
1855 #[cfg(target_os = "win32")]
1859 #[cfg(target_os = "macos")]
1862 use libc::types::os::arch::c95::{c_char, c_int};
1866 unsafe fn _NSGetExecutablePath(buf: *mut c_char,
1872 #[cfg(target_os = "freebsd")]
1876 #[cfg(target_os = "linux")]
1877 #[cfg(target_os = "android")]
1882 #[cfg(target_os = "win32")]
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};
1895 pub extern "stdcall" {
1896 unsafe fn GetEnvironmentVariableW(n: LPCWSTR,
1900 unsafe fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR)
1902 unsafe fn GetEnvironmentStringsA() -> LPTCH;
1903 unsafe fn FreeEnvironmentStringsA(env_ptr: LPTCH) -> BOOL;
1905 unsafe fn GetModuleFileNameW(hModule: HMODULE,
1909 unsafe fn CreateDirectoryW(lpPathName: LPCWSTR,
1910 lpSecurityAttributes:
1911 LPSECURITY_ATTRIBUTES)
1913 unsafe fn CopyFileW(lpExistingFileName: LPCWSTR,
1914 lpNewFileName: LPCWSTR,
1915 bFailIfExists: BOOL)
1917 unsafe fn DeleteFileW(lpPathName: LPCWSTR) -> BOOL;
1918 unsafe fn RemoveDirectoryW(lpPathName: LPCWSTR) -> BOOL;
1919 unsafe fn SetCurrentDirectoryW(lpPathName: LPCWSTR) -> BOOL;
1921 unsafe fn GetLastError() -> DWORD;
1922 unsafe fn FindFirstFileW(fileName: *u16,
1923 findFileData: HANDLE)
1925 unsafe fn FindNextFileW(findFile: HANDLE,
1926 findFileData: HANDLE)
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;
1958 use libc::types::os::arch::c95::{c_int, c_long};
1963 #[link_name = "_commit"]
1964 unsafe fn commit(fd: c_int) -> c_int;
1966 #[link_name = "_get_osfhandle"]
1967 unsafe fn get_osfhandle(fd: c_int) -> c_long;