11pub type rlim_t = :: uintptr_t ;
22pub type sa_family_t = u8 ;
33pub type pthread_key_t = :: c_int ;
4- pub type nfds_t = :: c_long ;
4+ pub type nfds_t = :: c_ulong ;
55pub type tcflag_t = :: c_uint ;
6- pub type speed_t = :: c_uint ;
6+ pub type speed_t = :: c_uchar ;
77pub type c_char = i8 ;
88pub type clock_t = i32 ;
99pub type clockid_t = i32 ;
@@ -19,6 +19,7 @@ pub type nlink_t = i32;
1919pub type useconds_t = u32 ;
2020pub type socklen_t = u32 ;
2121pub type pthread_t = :: uintptr_t ;
22+ pub type pthread_condattr_t = :: uintptr_t ;
2223pub type pthread_mutexattr_t = :: uintptr_t ;
2324pub type pthread_rwlockattr_t = :: uintptr_t ;
2425pub type sigset_t = u64 ;
@@ -28,6 +29,7 @@ pub type pthread_attr_t = *mut ::c_void;
2829pub type nl_item = :: c_int ;
2930pub type id_t = i32 ;
3031pub type idtype_t = :: c_uint ;
32+ pub type fd_mask = u32 ;
3133
3234#[ cfg_attr( feature = "extra_traits" , derive( Debug ) ) ]
3335pub enum timezone { }
6971 pub struct sockaddr {
7072 pub sa_len: u8 ,
7173 pub sa_family: sa_family_t,
72- pub sa_data: [ :: c_char ; 30 ] ,
74+ pub sa_data: [ u8 ; 30 ] ,
7375 }
7476
7577 pub struct sockaddr_in {
7678 pub sin_len: u8 ,
7779 pub sin_family: sa_family_t,
7880 pub sin_port: :: in_port_t,
7981 pub sin_addr: :: in_addr,
80- pub sin_zero: [ u8 ; 24 ] ,
82+ pub sin_zero: [ i8 ; 24 ] ,
8183 }
8284
8385 pub struct sockaddr_in6 {
8486 pub sin6_len: u8 ,
85- pub sin6_family: sa_family_t ,
86- pub sin6_port: :: in_port_t ,
87+ pub sin6_family: u8 ,
88+ pub sin6_port: u16 ,
8789 pub sin6_flowinfo: u32 ,
8890 pub sin6_addr: :: in6_addr,
8991 pub sin6_scope_id: u32 ,
101103 }
102104
103105 pub struct fd_set {
104- fds_bits: [ c_ulong; FD_SETSIZE / ULONG_SIZE ] ,
106+ // size for 1024 bits, and a fd_mask with size u32
107+ fds_bits: [ fd_mask; 32 ] ,
105108 }
106109
107110 pub struct tm {
114117 pub tm_wday: :: c_int,
115118 pub tm_yday: :: c_int,
116119 pub tm_isdst: :: c_int,
117- pub tm_gmtoff: :: c_long ,
118- pub tm_zone: * const :: c_char,
120+ pub tm_gmtoff: :: c_int ,
121+ pub tm_zone: * mut :: c_char,
119122 }
120123
121124 pub struct utsname {
@@ -155,16 +158,16 @@ s! {
155158
156159 pub struct msghdr {
157160 pub msg_name: * mut :: c_void,
158- pub msg_namelen: :: socklen_t,
161+ pub msg_namelen: socklen_t,
159162 pub msg_iov: * mut :: iovec,
160163 pub msg_iovlen: :: c_int,
161164 pub msg_control: * mut :: c_void,
162- pub msg_controllen: :: socklen_t,
165+ pub msg_controllen: socklen_t,
163166 pub msg_flags: :: c_int,
164167 }
165168
166169 pub struct cmsghdr {
167- pub cmsg_len: :: size_t ,
170+ pub cmsg_len: :: socklen_t ,
168171 pub cmsg_level: :: c_int,
169172 pub cmsg_type: :: c_int,
170173 }
@@ -301,22 +304,16 @@ s! {
301304 }
302305
303306 pub struct sigaction {
304- pub sa_sigaction: :: sighandler_t,
307+ pub sa_sigaction: :: sighandler_t, //actually a union with sa_handler
305308 pub sa_mask: :: sigset_t,
306309 pub sa_flags: :: c_int,
307310 sa_userdata: * mut :: c_void,
308311 }
309312
310313 pub struct sem_t {
311- pub se_type: i32 ,
312- pub se_named_id: i32 , // this is actually a union
313- pub se_unnamed: i32 ,
314- pub se_padding: [ i32 ; 4 ] ,
315- }
316-
317- pub struct pthread_condattr_t {
318- pub process_shared: bool ,
319- pub clock_id: i32 ,
314+ pub type_: i32 ,
315+ pub named_sem_id: i32 , // actually a union with unnamed_sem (i32)
316+ pub padding: [ i32 ; 2 ] ,
320317 }
321318}
322319
@@ -491,17 +488,6 @@ cfg_if! {
491488 }
492489}
493490
494- // intentionally not public, only used for fd_set
495- cfg_if ! {
496- if #[ cfg( target_pointer_width = "32" ) ] {
497- const ULONG_SIZE : usize = 32 ;
498- } else if #[ cfg( target_pointer_width = "64" ) ] {
499- const ULONG_SIZE : usize = 64 ;
500- } else {
501- // Unknown target_pointer_width
502- }
503- }
504-
505491pub const EXIT_FAILURE : :: c_int = 1 ;
506492pub const EXIT_SUCCESS : :: c_int = 0 ;
507493pub const RAND_MAX : :: c_int = 2147483647 ;
@@ -559,7 +545,7 @@ pub const RLIMIT_STACK: ::c_int = 5;
559545pub const RLIMIT_AS : :: c_int = 6 ;
560546// Haiku specific
561547pub const RLIMIT_NOVMON : :: c_int = 7 ;
562- pub const RLIMIT_NLIMITS : :: c_int = 8 ;
548+ pub const RLIM_NLIMITS : :: c_int = 8 ;
563549
564550pub const RUSAGE_SELF : :: c_int = 0 ;
565551
@@ -596,18 +582,20 @@ pub const S_IFREG: ::mode_t = 32768;
596582pub const S_IFLNK : :: mode_t = 40960 ;
597583pub const S_IFSOCK : :: mode_t = 49152 ;
598584pub const S_IFMT : :: mode_t = 61440 ;
599- pub const S_IRWXU : :: mode_t = 448 ;
600- pub const S_IXUSR : :: mode_t = 64 ;
601- pub const S_IWUSR : :: mode_t = 128 ;
602- pub const S_IRUSR : :: mode_t = 256 ;
603- pub const S_IRWXG : :: mode_t = 70 ;
604- pub const S_IXGRP : :: mode_t = 10 ;
605- pub const S_IWGRP : :: mode_t = 20 ;
606- pub const S_IRGRP : :: mode_t = 40 ;
607- pub const S_IRWXO : :: mode_t = 7 ;
608- pub const S_IXOTH : :: mode_t = 1 ;
609- pub const S_IWOTH : :: mode_t = 2 ;
610- pub const S_IROTH : :: mode_t = 4 ;
585+
586+ pub const S_IRWXU : :: mode_t = 0o00700 ;
587+ pub const S_IRUSR : :: mode_t = 0o00400 ;
588+ pub const S_IWUSR : :: mode_t = 0o00200 ;
589+ pub const S_IXUSR : :: mode_t = 0o00100 ;
590+ pub const S_IRWXG : :: mode_t = 0o00070 ;
591+ pub const S_IRGRP : :: mode_t = 0o00040 ;
592+ pub const S_IWGRP : :: mode_t = 0o00020 ;
593+ pub const S_IXGRP : :: mode_t = 0o00010 ;
594+ pub const S_IRWXO : :: mode_t = 0o00007 ;
595+ pub const S_IROTH : :: mode_t = 0o00004 ;
596+ pub const S_IWOTH : :: mode_t = 0o00002 ;
597+ pub const S_IXOTH : :: mode_t = 0o00001 ;
598+
611599pub const F_OK : :: c_int = 0 ;
612600pub const R_OK : :: c_int = 4 ;
613601pub const W_OK : :: c_int = 2 ;
@@ -707,8 +695,8 @@ pub const ENOTTY: ::c_int = -2147454966;
707695pub const ENXIO : :: c_int = -2147454965 ;
708696pub const ESPIPE : :: c_int = -2147454964 ;
709697pub const ESRCH : :: c_int = -2147454963 ;
710- pub const EFPOS : :: c_int = -2147457962 ;
711- pub const ESIGPARM : :: c_int = -2147457961 ;
698+ pub const EFPOS : :: c_int = -2147454962 ;
699+ pub const ESIGPARM : :: c_int = -2147454961 ;
712700pub const EDOM : :: c_int = -2147454960 ;
713701pub const ERANGE : :: c_int = -2147454959 ;
714702pub const EPROTOTYPE : :: c_int = -2147454958 ;
@@ -756,7 +744,7 @@ pub const ETXTBSY: ::c_int = -2147454917;
756744pub const ENOATTR : :: c_int = -2147454916 ;
757745
758746// INT_MIN
759- pub const ENOMEM : :: c_int = -2147454976 ;
747+ pub const ENOMEM : :: c_int = -2147483648 ;
760748
761749// POSIX errors that can be mapped to BeOS error codes
762750pub const EACCES : :: c_int = -2147483646 ;
@@ -844,6 +832,9 @@ pub const TCP_MAXSEG: ::c_int = 0x02;
844832pub const TCP_NOPUSH : :: c_int = 0x04 ;
845833pub const TCP_NOOPT : :: c_int = 0x08 ;
846834
835+ pub const IF_NAMESIZE : :: size_t = 32 ;
836+ pub const IFNAMSIZ : :: size_t = IF_NAMESIZE ;
837+
847838pub const IPV6_MULTICAST_IF : :: c_int = 24 ;
848839pub const IPV6_MULTICAST_HOPS : :: c_int = 25 ;
849840pub const IPV6_MULTICAST_LOOP : :: c_int = 26 ;
@@ -854,7 +845,7 @@ pub const IPV6_V6ONLY: ::c_int = 30;
854845pub const IPV6_PKTINFO : :: c_int = 31 ;
855846pub const IPV6_RECVPKTINFO : :: c_int = 32 ;
856847pub const IPV6_HOPLIMIT : :: c_int = 33 ;
857- pub const IPV6_REVCHOPLIMIT : :: c_int = 34 ;
848+ pub const IPV6_RECVHOPLIMIT : :: c_int = 34 ;
858849pub const IPV6_HOPOPTS : :: c_int = 35 ;
859850pub const IPV6_DSTOPTS : :: c_int = 36 ;
860851pub const IPV6_RTHDR : :: c_int = 37 ;
@@ -1239,7 +1230,60 @@ pub const PRIO_PROCESS: ::c_int = 0;
12391230pub const PRIO_PGRP : :: c_int = 1 ;
12401231pub const PRIO_USER : :: c_int = 2 ;
12411232
1233+ pub const LOG_PID : :: c_int = 1 << 12 ;
1234+ pub const LOG_CONS : :: c_int = 2 << 12 ;
1235+ pub const LOG_ODELAY : :: c_int = 4 << 12 ;
1236+ pub const LOG_NDELAY : :: c_int = 8 << 12 ;
1237+ pub const LOG_SERIAL : :: c_int = 16 << 12 ;
1238+ pub const LOG_PERROR : :: c_int = 32 << 12 ;
1239+ pub const LOG_NOWAIT : :: c_int = 64 << 12 ;
1240+
1241+ const_fn ! {
1242+ { const } fn CMSG_ALIGN ( len: usize ) -> usize {
1243+ len + :: mem:: size_of:: <usize >( ) - 1 & !( :: mem:: size_of:: <usize >( ) - 1 )
1244+ }
1245+ }
1246+
12421247f ! {
1248+ pub fn CMSG_FIRSTHDR ( mhdr: * const msghdr) -> * mut cmsghdr {
1249+ if ( * mhdr) . msg_controllen as usize >= :: mem:: size_of:: <cmsghdr>( ) {
1250+ ( * mhdr) . msg_control as * mut cmsghdr
1251+ } else {
1252+ 0 as * mut cmsghdr
1253+ }
1254+ }
1255+
1256+ pub fn CMSG_DATA ( cmsg: * const :: cmsghdr) -> * mut :: c_uchar {
1257+ ( cmsg as * mut :: c_uchar)
1258+ . offset( CMSG_ALIGN ( :: mem:: size_of:: <:: cmsghdr>( ) ) as isize )
1259+ }
1260+
1261+ pub { const } fn CMSG_SPACE ( length: :: c_uint) -> :: c_uint {
1262+ ( CMSG_ALIGN ( length as usize ) + CMSG_ALIGN ( :: mem:: size_of:: <cmsghdr>( ) ) )
1263+ as :: c_uint
1264+ }
1265+
1266+ pub fn CMSG_LEN ( length: :: c_uint) -> :: c_uint {
1267+ CMSG_ALIGN ( :: mem:: size_of:: <cmsghdr>( ) ) as :: c_uint + length
1268+ }
1269+
1270+ pub fn CMSG_NXTHDR ( mhdr: * const msghdr,
1271+ cmsg: * const cmsghdr) -> * mut cmsghdr {
1272+ if cmsg. is_null( ) {
1273+ return :: CMSG_FIRSTHDR ( mhdr) ;
1274+ } ;
1275+ let next = cmsg as usize + CMSG_ALIGN ( ( * cmsg) . cmsg_len as usize )
1276+ + CMSG_ALIGN ( :: mem:: size_of:: <:: cmsghdr>( ) ) ;
1277+ let max = ( * mhdr) . msg_control as usize
1278+ + ( * mhdr) . msg_controllen as usize ;
1279+ if next > max {
1280+ 0 as * mut :: cmsghdr
1281+ } else {
1282+ ( cmsg as usize + CMSG_ALIGN ( ( * cmsg) . cmsg_len as usize ) )
1283+ as * mut :: cmsghdr
1284+ }
1285+ }
1286+
12431287 pub fn FD_CLR ( fd: :: c_int, set: * mut fd_set) -> ( ) {
12441288 let fd = fd as usize ;
12451289 let size = :: mem:: size_of_val( & ( * set) . fds_bits[ 0 ] ) * 8 ;
@@ -1368,10 +1412,10 @@ extern "C" {
13681412 clock_id : :: clockid_t ,
13691413 ) -> :: c_int ;
13701414 pub fn memalign ( align : :: size_t , size : :: size_t ) -> * mut :: c_void ;
1371- pub fn setgroups ( ngroups : :: size_t , ptr : * const :: gid_t ) -> :: c_int ;
1372- pub fn ioctl ( fd : :: c_int , request : :: c_int , ...) -> :: c_int ;
1415+ pub fn setgroups ( ngroups : :: c_int , ptr : * const :: gid_t ) -> :: c_int ;
1416+ pub fn ioctl ( fd : :: c_int , request : :: c_ulong , ...) -> :: c_int ;
13731417 pub fn mprotect (
1374- addr : * const :: c_void ,
1418+ addr : * mut :: c_void ,
13751419 len : :: size_t ,
13761420 prot : :: c_int ,
13771421 ) -> :: c_int ;
@@ -1380,9 +1424,9 @@ extern "C" {
13801424 sa : * const :: sockaddr ,
13811425 salen : :: socklen_t ,
13821426 host : * mut :: c_char ,
1383- hostlen : :: size_t ,
1427+ hostlen : :: socklen_t ,
13841428 serv : * mut :: c_char ,
1385- sevlen : :: size_t ,
1429+ sevlen : :: socklen_t ,
13861430 flags : :: c_int ,
13871431 ) -> :: c_int ;
13881432 pub fn pthread_mutex_timedlock (
@@ -1455,12 +1499,12 @@ extern "C" {
14551499 pub fn writev (
14561500 fd : :: c_int ,
14571501 iov : * const :: iovec ,
1458- iovcnt : :: c_int ,
1502+ count : :: size_t ,
14591503 ) -> :: ssize_t ;
14601504 pub fn readv (
14611505 fd : :: c_int ,
14621506 iov : * const :: iovec ,
1463- iovcnt : :: c_int ,
1507+ count : :: size_t ,
14641508 ) -> :: ssize_t ;
14651509
14661510 pub fn sendmsg (
0 commit comments