11use super :: { Send , Sync } ;
2- use core:: iter:: Iterator ;
32
43pub use ffi:: c_void;
54
@@ -10,8 +9,15 @@ pub type c_int = i32;
109pub type c_uint = u32 ;
1110pub type c_short = i16 ;
1211pub type c_ushort = u16 ;
13- pub type c_long = i32 ;
14- pub type c_ulong = u32 ;
12+ cfg_if ! {
13+ if #[ cfg( target_arch = "wasm64" ) ] {
14+ pub type c_long = i64 ;
15+ pub type c_ulong = u64 ;
16+ } else {
17+ pub type c_long = i32 ;
18+ pub type c_ulong = u32 ;
19+ }
20+ }
1521pub type c_longlong = i64 ;
1622pub type c_ulonglong = u64 ;
1723pub type intmax_t = i64 ;
@@ -28,7 +34,6 @@ pub type time_t = c_longlong;
2834pub type c_double = f64 ;
2935pub type c_float = f32 ;
3036pub type ino_t = u64 ;
31- pub type sigset_t = c_uchar ;
3237pub type suseconds_t = c_longlong ;
3338pub type mode_t = u32 ;
3439pub type dev_t = u64 ;
@@ -176,11 +181,6 @@ s! {
176181 pub st_ctim: timespec,
177182 __reserved: [ c_longlong; 3 ] ,
178183 }
179-
180- pub struct fd_set {
181- __nfds: usize ,
182- __fds: [ c_int; FD_SETSIZE as usize ] ,
183- }
184184}
185185
186186// Declare dirent outside of s! so that it doesn't implement Copy, Eq, Hash,
@@ -197,6 +197,9 @@ pub struct dirent {
197197 pub d_name : [ c_char ; 0 ] ,
198198}
199199
200+ pub const INT_MIN : c_int = -2147483648 ;
201+ pub const INT_MAX : c_int = 2147483647 ;
202+
200203pub const EXIT_SUCCESS : c_int = 0 ;
201204pub const EXIT_FAILURE : c_int = 1 ;
202205pub const STDIN_FILENO : c_int = 0 ;
@@ -212,6 +215,8 @@ pub const F_GETFD: c_int = 1;
212215pub const F_SETFD : c_int = 2 ;
213216pub const F_GETFL : c_int = 3 ;
214217pub const F_SETFL : c_int = 4 ;
218+ pub const F_DUPFD : c_int = 5 ;
219+ pub const F_DUPFD_CLOEXEC : c_int = 6 ;
215220pub const FD_CLOEXEC : c_int = 1 ;
216221pub const FD_SETSIZE : size_t = 1024 ;
217222pub const O_APPEND : c_int = 0x0001 ;
@@ -245,14 +250,14 @@ pub const AT_SYMLINK_FOLLOW: c_int = 0x2;
245250pub const AT_REMOVEDIR : c_int = 0x4 ;
246251pub const UTIME_OMIT : c_long = 0xfffffffe ;
247252pub const UTIME_NOW : c_long = 0xffffffff ;
248- pub const S_IFIFO : mode_t = 0o1_0000 ;
253+ pub const S_IFIFO : mode_t = 49152 ;
249254pub const S_IFCHR : mode_t = 8192 ;
250255pub const S_IFBLK : mode_t = 24576 ;
251256pub const S_IFDIR : mode_t = 16384 ;
252257pub const S_IFREG : mode_t = 32768 ;
253258pub const S_IFLNK : mode_t = 40960 ;
254259pub const S_IFSOCK : mode_t = 49152 ;
255- pub const S_IFMT : mode_t = 0o17_0000 ;
260+ pub const S_IFMT : mode_t = 57344 ;
256261pub const S_IRWXO : mode_t = 0x7 ;
257262pub const S_IXOTH : mode_t = 0x1 ;
258263pub const S_IWOTH : mode_t = 0x2 ;
@@ -370,28 +375,15 @@ pub const EWOULDBLOCK: c_int = EAGAIN;
370375pub const _SC_PAGESIZE: c_int = 30 ;
371376pub const _SC_PAGE_SIZE: :: c_int = _SC_PAGESIZE;
372377pub const _SC_IOV_MAX: c_int = 60 ;
378+ pub const _SC_NPROCESSORS_ONLN: :: c_int = 84 ;
373379pub const _SC_SYMLOOP_MAX: c_int = 173 ;
374380
375- cfg_if ! {
376- if #[ cfg( libc_ctest) ] {
377- // skip these constants when this is active because `ctest` currently
378- // panics on parsing the constants below
379- } else {
380- // `addr_of!(EXTERN_STATIC)` is now safe; remove `unsafe` when MSRV >= 1.82
381- #[ allow( unused_unsafe) ]
382- pub static CLOCK_MONOTONIC : clockid_t =
383- unsafe { clockid_t( ptr_addr_of!( _CLOCK_MONOTONIC) ) } ;
384- #[ allow( unused_unsafe) ]
385- pub static CLOCK_PROCESS_CPUTIME_ID : clockid_t =
386- unsafe { clockid_t( ptr_addr_of!( _CLOCK_PROCESS_CPUTIME_ID) ) } ;
387- #[ allow( unused_unsafe) ]
388- pub static CLOCK_REALTIME : clockid_t =
389- unsafe { clockid_t( ptr_addr_of!( _CLOCK_REALTIME) ) } ;
390- #[ allow( unused_unsafe) ]
391- pub static CLOCK_THREAD_CPUTIME_ID : clockid_t =
392- unsafe { clockid_t( ptr_addr_of!( _CLOCK_THREAD_CPUTIME_ID) ) } ;
393- }
394- }
381+ pub static CLOCK_MONOTONIC : clockid_t = unsafe { clockid_t ( ptr_addr_of ! ( _CLOCK_MONOTONIC) ) } ;
382+ pub static CLOCK_PROCESS_CPUTIME_ID : clockid_t =
383+ unsafe { clockid_t ( ptr_addr_of ! ( _CLOCK_PROCESS_CPUTIME_ID) ) } ;
384+ pub static CLOCK_REALTIME : clockid_t = unsafe { clockid_t ( ptr_addr_of ! ( _CLOCK_REALTIME) ) } ;
385+ pub static CLOCK_THREAD_CPUTIME_ID : clockid_t =
386+ unsafe { clockid_t ( ptr_addr_of ! ( _CLOCK_THREAD_CPUTIME_ID) ) } ;
395387
396388pub const ABDAY_1 : :: nl_item = 0x20000 ;
397389pub const ABDAY_2 : :: nl_item = 0x20001 ;
@@ -458,28 +450,6 @@ pub const NOEXPR: ::nl_item = 0x50001;
458450pub const YESSTR : :: nl_item = 0x50002 ;
459451pub const NOSTR : :: nl_item = 0x50003 ;
460452
461- f ! {
462- pub fn FD_ISSET ( fd: :: c_int, set: * const fd_set) -> bool {
463- let set = & * set;
464- let n = set. __nfds;
465- return set. __fds[ ..n] . iter( ) . any( |p| * p == fd)
466- }
467-
468- pub fn FD_SET ( fd: :: c_int, set: * mut fd_set) -> ( ) {
469- let set = & mut * set;
470- let n = set. __nfds;
471- if !set. __fds[ ..n] . iter( ) . any( |p| * p == fd) {
472- set. __nfds = n + 1 ;
473- set. __fds[ n] = fd;
474- }
475- }
476-
477- pub fn FD_ZERO ( set: * mut fd_set) -> ( ) {
478- ( * set) . __nfds = 0 ;
479- return
480- }
481- }
482-
483453#[ cfg_attr(
484454 feature = "rustc-dep-of-std" ,
485455 link(
@@ -775,14 +745,6 @@ extern "C" {
775745 pub fn nl_langinfo ( item : :: nl_item ) -> * mut :: c_char ;
776746 pub fn nl_langinfo_l ( item : :: nl_item , loc : :: locale_t ) -> * mut :: c_char ;
777747
778- pub fn select (
779- nfds : c_int ,
780- readfds : * mut fd_set ,
781- writefds : * mut fd_set ,
782- errorfds : * mut fd_set ,
783- timeout : * const timeval ,
784- ) -> c_int ;
785-
786748 pub fn __wasilibc_register_preopened_fd ( fd : c_int , path : * const c_char ) -> c_int ;
787749 pub fn __wasilibc_fd_renumber ( fd : c_int , newfd : c_int ) -> c_int ;
788750 pub fn __wasilibc_unlinkat ( fd : c_int , path : * const c_char ) -> c_int ;
@@ -880,9 +842,5 @@ extern "C" {
880842 pub fn __errno_location ( ) -> * mut :: c_int ;
881843}
882844
883- cfg_if ! {
884- if #[ cfg( target_env = "p2" ) ] {
885- mod p2;
886- pub use self :: p2:: * ;
887- }
888- }
845+ mod wasix;
846+ pub use self :: wasix:: * ;
0 commit comments