1 use c_void; 2 use in6_addr; 3 use in_addr_t; 4 use timespec; 5 use DIR; 6 7 pub type nlink_t = u16; 8 pub type ino_t = u16; 9 pub type blkcnt_t = u64; 10 pub type blksize_t = i16; 11 pub type c_char = i8; 12 pub type c_long = isize; 13 pub type c_ulong = usize; 14 pub type cc_t = u8; 15 pub type clock_t = i64; 16 pub type dev_t = i32; 17 pub type fsblkcnt_t = u64; 18 pub type locale_t = *mut i8; 19 pub type mode_t = u32; 20 pub type nfds_t = u32; 21 pub type off_t = i64; 22 pub type pthread_key_t = i32; 23 pub type pthread_mutexattr_t = u8; 24 pub type pthread_rwlockattr_t = i32; 25 pub type pthread_t = i32; 26 pub type rlim_t = i64; 27 pub type sa_family_t = u16; 28 pub type socklen_t = u32; 29 pub type speed_t = usize; 30 pub type suseconds_t = i32; 31 pub type tcflag_t = u32; 32 pub type clockid_t = i32; 33 pub type time_t = i64; 34 pub type wchar_t = i32; 35 36 s! { 37 pub struct stat { 38 pub st_dev: dev_t, 39 pub st_ino: ino_t, 40 pub st_mode: mode_t, 41 pub st_nlink: u64, 42 pub st_uid: u32, 43 pub st_gid: u32, 44 pub st_rdev: dev_t, 45 pub st_size: off_t, 46 pub st_atim: timespec, 47 pub st_mtim: timespec, 48 pub st_ctim: timespec, 49 pub st_blksize: blksize_t, 50 pub st_blocks: i64, 51 __reserved: [usize; __DEFAULT_RESERVED_SIZE__], 52 } 53 54 pub struct sockaddr { 55 pub sa_family: sa_family_t, 56 pub sa_data: [u8; 14], 57 } 58 59 pub struct passwd { 60 pub pw_name: *const c_char, 61 pub pw_uid: u32, 62 pub pw_gid: u32, 63 pub pw_gecos: *const c_char, 64 pub pw_dir: *const c_char, 65 pub pw_shell: *const c_char, 66 __reserved: [usize; __DEFAULT_RESERVED_SIZE__] 67 } 68 69 pub struct sem_t { __val: [usize; __SEM_SIZE__] } 70 71 pub struct pthread_attr_t { __val: [usize; __PTHREAD_ATTR_SIZE__] } 72 73 pub struct pthread_mutex_t { __val: [usize; __PTHREAD_MUTEX_SIZE__] } 74 75 pub struct pthread_cond_t { __val: [usize; __PTHREAD_COND_SIZE__] } 76 77 pub struct pthread_condattr_t { __val: [usize; __PTHREAD_CONDATTR_SIZE__] } 78 79 pub struct Dl_info { 80 pub dli_fname: *const c_char, 81 pub dli_fbase: *mut c_void, 82 pub dli_sname: *const c_char, 83 pub dli_saddr: *mut c_void, 84 } 85 86 pub struct lconv { 87 pub decimal_point: *const c_char, 88 pub thousands_sep: *const c_char, 89 pub grouping: *const c_char, 90 pub int_curr_symbol: *const c_char, 91 pub currency_symbol: *const c_char, 92 pub mon_decimal_point: *const c_char, 93 pub mon_thousands_sep: *const c_char, 94 pub mon_grouping: *const c_char, 95 pub positive_sign: *const c_char, 96 pub negative_sign: *const c_char, 97 pub int_frac_digits: i8, 98 pub frac_digits: i8, 99 pub p_cs_precedes: i8, 100 pub p_sep_by_space: i8, 101 pub n_cs_precedes: i8, 102 pub n_sep_by_space: i8, 103 pub p_sign_posn: i8, 104 pub n_sign_posn: i8, 105 pub int_n_cs_precedes: i8, 106 pub int_n_sep_by_space: i8, 107 pub int_n_sign_posn: i8, 108 pub int_p_cs_precedes: i8, 109 pub int_p_sep_by_space: i8, 110 pub int_p_sign_posn: i8, 111 __reserved: [usize; __DEFAULT_RESERVED_SIZE__], 112 } 113 114 pub struct tm { 115 pub tm_sec: i32, 116 pub tm_min: i32, 117 pub tm_hour: i32, 118 pub tm_mday: i32, 119 pub tm_mon: i32, 120 pub tm_year: i32, 121 pub tm_wday: i32, 122 pub tm_yday: i32, 123 pub tm_isdst: i32, 124 pub tm_gmtoff: isize, 125 pub tm_zone: *const i8, 126 __reserved: [usize; __DEFAULT_RESERVED_SIZE__], 127 } 128 129 pub struct addrinfo { 130 pub ai_flags: i32, 131 pub ai_family: i32, 132 pub ai_socktype: i32, 133 pub ai_protocol: i32, 134 pub ai_addrlen: socklen_t, 135 pub ai_addr: *mut sockaddr, 136 pub ai_canonname: *mut c_char, 137 pub ai_next: *mut addrinfo, 138 __reserved: [usize; __DEFAULT_RESERVED_SIZE__], 139 } 140 141 pub struct pthread_rwlock_t { 142 __val: [usize; __PTHREAD_RWLOCK_SIZE__], 143 } 144 145 pub struct statvfs { 146 pub f_bsize: usize, 147 pub f_frsize: usize, 148 pub f_blocks: fsblkcnt_t, 149 pub f_bfree: fsblkcnt_t, 150 pub f_bavail: fsblkcnt_t, 151 pub f_files: fsblkcnt_t, 152 pub f_ffree: fsblkcnt_t, 153 pub f_favail: fsblkcnt_t, 154 pub f_fsid: usize, 155 pub f_flag: usize, 156 pub f_namemax: usize, 157 __reserved: [usize; __DEFAULT_RESERVED_SIZE__], 158 } 159 160 pub struct dirent { 161 pub d_type: u8, 162 pub d_name: [i8; __NAME_MAX__ + 1], 163 } 164 165 pub struct fd_set { 166 __val: [u32; __FDSET_SIZE__], 167 } 168 169 pub struct sigset_t { 170 __val: [u32; __SIGSET_SIZE__], 171 } 172 173 pub struct sigaction { 174 pub sa_handler: usize, 175 pub sa_mask: sigset_t, 176 pub sa_flags: i32, 177 pub sa_user: usize, 178 __reserved: [usize; __DEFAULT_RESERVED_SIZE__], 179 } 180 181 pub struct termios { 182 pub c_iflag: tcflag_t, 183 pub c_oflag: tcflag_t, 184 pub c_cflag: tcflag_t, 185 pub c_lflag: tcflag_t, 186 pub c_cc: [cc_t; 12], 187 pub c_speed: speed_t, 188 __reserved: [usize; __DEFAULT_RESERVED_SIZE__], 189 } 190 191 pub struct in_addr { 192 pub s_addr: in_addr_t, 193 } 194 195 pub struct sockaddr_in { 196 pub sin_family: sa_family_t, 197 pub sin_port: ::in_port_t, 198 pub sin_addr: ::in_addr, 199 pub sin_zero: [u8; 8], 200 } 201 202 pub struct sockaddr_in6 { 203 pub sin6_family: sa_family_t, 204 pub sin6_port: ::in_port_t, 205 pub sin6_flowinfo: u32, 206 pub sin6_addr: ::in6_addr, 207 pub sin6_scope_id: u32, 208 } 209 210 pub struct sockaddr_un { 211 pub sun_family: sa_family_t, 212 pub sun_path: [c_char; 108], 213 } 214 215 pub struct sockaddr_storage { 216 pub ss_family: sa_family_t, 217 ss_data: [u32; __SOCKADDR_STORAGE_SIZE__], 218 } 219 220 pub struct ip_mreq { 221 pub imr_multiaddr: in_addr, 222 pub imr_interface: in_addr, 223 } 224 225 pub struct ipv6_mreq { 226 pub ipv6mr_multiaddr: in6_addr, 227 pub ipv6mr_interface: u32, 228 } 229 230 pub struct timeval { 231 pub tv_sec: time_t, 232 pub tv_usec: suseconds_t, 233 } 234 } 235 236 // Reserved two pointer size for reserved area for some structures. 237 // This ensures that the size of these structures is large enough 238 // if more fields are added in the NuttX side. 239 // 240 // These structures are that defined by POSIX but only necessary fields are included, 241 // for example, struct passwd, https://pubs.opengroup.org/onlinepubs/009695399/basedefs/pwd.h.html, 242 // POSIX only defines following fields in struct passwd: 243 // char *pw_name User's login name. 244 // uid_t pw_uid Numerical user ID. 245 // gid_t pw_gid Numerical group ID. 246 // char *pw_dir Initial working directory. 247 // char *pw_shell Program to use as shell. 248 // Other fields can be different depending on the implementation. 249 250 const __DEFAULT_RESERVED_SIZE__: usize = 2; 251 252 const __SOCKADDR_STORAGE_SIZE__: usize = 36; 253 const __PTHREAD_ATTR_SIZE__: usize = 5; 254 const __PTHREAD_MUTEX_SIZE__: usize = 9; 255 const __PTHREAD_COND_SIZE__: usize = 7; 256 const __PTHREAD_CONDATTR_SIZE__: usize = 5; 257 const __PTHREAD_RWLOCK_SIZE__: usize = 17; 258 const __SEM_SIZE__: usize = 6; 259 const __NAME_MAX__: usize = 64; 260 const __FDSET_SIZE__: usize = 10; 261 const __SIGSET_SIZE__: usize = 8; 262 263 pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { 264 __val: [0; __PTHREAD_COND_SIZE__], 265 }; 266 pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { 267 __val: [0; __PTHREAD_MUTEX_SIZE__], 268 }; 269 270 // dlfcn.h 271 pub const RTLD_DEFAULT: *mut c_void = 0 as *mut c_void; 272 273 // stdlib.h 274 pub const EXIT_SUCCESS: i32 = 0; 275 pub const EXIT_FAILURE: i32 = 1; 276 277 // time.h 278 pub const CLOCK_REALTIME: i32 = 0; 279 pub const CLOCK_MONOTONIC: i32 = 1; 280 281 // errno.h 282 pub const EPERM: i32 = 1; 283 pub const ENOENT: i32 = 2; 284 pub const ESRCH: i32 = 3; 285 pub const EINTR: i32 = 4; 286 pub const EIO: i32 = 5; 287 pub const ENXIO: i32 = 6; 288 pub const E2BIG: i32 = 7; 289 pub const ENOEXEC: i32 = 8; 290 pub const EBADF: i32 = 9; 291 pub const ECHILD: i32 = 10; 292 pub const EAGAIN: i32 = 11; 293 pub const ENOMEM: i32 = 12; 294 pub const EACCES: i32 = 13; 295 pub const EFAULT: i32 = 14; 296 pub const ENOTBLK: i32 = 15; 297 pub const EBUSY: i32 = 16; 298 pub const EEXIST: i32 = 17; 299 pub const EXDEV: i32 = 18; 300 pub const ENODEV: i32 = 19; 301 pub const ENOTDIR: i32 = 20; 302 pub const EISDIR: i32 = 21; 303 pub const EINVAL: i32 = 22; 304 pub const ENFILE: i32 = 23; 305 pub const EMFILE: i32 = 24; 306 pub const ENOTTY: i32 = 25; 307 pub const ETXTBSY: i32 = 26; 308 pub const EFBIG: i32 = 27; 309 pub const ENOSPC: i32 = 28; 310 pub const ESPIPE: i32 = 29; 311 pub const EROFS: i32 = 30; 312 pub const EMLINK: i32 = 31; 313 pub const EPIPE: i32 = 32; 314 pub const EDOM: i32 = 33; 315 pub const ERANGE: i32 = 34; 316 pub const EDEADLK: i32 = 35; 317 pub const ENAMETOOLONG: i32 = 36; 318 pub const ENOLCK: i32 = 37; 319 pub const ENOSYS: i32 = 38; 320 pub const ENOTEMPTY: i32 = 39; 321 pub const ELOOP: i32 = 40; 322 pub const EWOULDBLOCK: i32 = EAGAIN; 323 pub const ENOMSG: i32 = 42; 324 pub const EIDRM: i32 = 43; 325 pub const ECHRNG: i32 = 44; 326 pub const EL2NSYNC: i32 = 45; 327 pub const EL3HLT: i32 = 46; 328 pub const EL3RST: i32 = 47; 329 pub const ELNRNG: i32 = 48; 330 pub const EUNATCH: i32 = 49; 331 pub const ENOCSI: i32 = 50; 332 pub const EL2HLT: i32 = 51; 333 pub const EBADE: i32 = 52; 334 pub const EBADR: i32 = 53; 335 pub const EXFULL: i32 = 54; 336 pub const ENOANO: i32 = 55; 337 pub const EBADRQC: i32 = 56; 338 pub const EBADSLT: i32 = 57; 339 pub const EDEADLOCK: i32 = EDEADLK; 340 pub const EBFONT: i32 = 59; 341 pub const ENOSTR: i32 = 60; 342 pub const ENODATA: i32 = 61; 343 pub const ETIME: i32 = 62; 344 pub const ENOSR: i32 = 63; 345 pub const ENONET: i32 = 64; 346 pub const ENOPKG: i32 = 65; 347 pub const EREMOTE: i32 = 66; 348 pub const ENOLINK: i32 = 67; 349 pub const EADV: i32 = 68; 350 pub const ESRMNT: i32 = 69; 351 pub const ECOMM: i32 = 70; 352 pub const EPROTO: i32 = 71; 353 pub const EMULTIHOP: i32 = 72; 354 pub const EDOTDOT: i32 = 73; 355 pub const EBADMSG: i32 = 74; 356 pub const EOVERFLOW: i32 = 75; 357 pub const ENOTUNIQ: i32 = 76; 358 pub const EBADFD: i32 = 77; 359 pub const EREMCHG: i32 = 78; 360 pub const ELIBACC: i32 = 79; 361 pub const ELIBBAD: i32 = 80; 362 pub const ELIBSCN: i32 = 81; 363 pub const ELIBMAX: i32 = 82; 364 pub const ELIBEXEC: i32 = 83; 365 pub const EILSEQ: i32 = 84; 366 pub const ERESTART: i32 = 85; 367 pub const ESTRPIPE: i32 = 86; 368 pub const EUSERS: i32 = 87; 369 pub const ENOTSOCK: i32 = 88; 370 pub const EDESTADDRREQ: i32 = 89; 371 pub const EMSGSIZE: i32 = 90; 372 pub const EPROTOTYPE: i32 = 91; 373 pub const ENOPROTOOPT: i32 = 92; 374 pub const EPROTONOSUPPORT: i32 = 93; 375 pub const ESOCKTNOSUPPORT: i32 = 94; 376 pub const EOPNOTSUPP: i32 = 95; 377 pub const EPFNOSUPPORT: i32 = 96; 378 pub const EAFNOSUPPORT: i32 = 97; 379 pub const EADDRINUSE: i32 = 98; 380 pub const EADDRNOTAVAIL: i32 = 99; 381 pub const ENETDOWN: i32 = 100; 382 pub const ENETUNREACH: i32 = 101; 383 pub const ENETRESET: i32 = 102; 384 pub const ECONNABORTED: i32 = 103; 385 pub const ECONNRESET: i32 = 104; 386 pub const ENOBUFS: i32 = 105; 387 pub const EISCONN: i32 = 106; 388 pub const ENOTCONN: i32 = 107; 389 pub const ESHUTDOWN: i32 = 108; 390 pub const ETOOMANYREFS: i32 = 109; 391 pub const ETIMEDOUT: i32 = 110; 392 pub const ECONNREFUSED: i32 = 111; 393 pub const EHOSTDOWN: i32 = 112; 394 pub const EHOSTUNREACH: i32 = 113; 395 pub const EALREADY: i32 = 114; 396 pub const EINPROGRESS: i32 = 115; 397 pub const ESTALE: i32 = 116; 398 pub const EUCLEAN: i32 = 117; 399 pub const ENOTNAM: i32 = 118; 400 pub const ENAVAIL: i32 = 119; 401 pub const EISNAM: i32 = 120; 402 pub const EREMOTEIO: i32 = 121; 403 pub const EDQUOT: i32 = 122; 404 pub const ENOMEDIUM: i32 = 123; 405 pub const EMEDIUMTYPE: i32 = 124; 406 pub const ECANCELED: i32 = 125; 407 pub const ENOKEY: i32 = 126; 408 pub const EKEYEXPIRED: i32 = 127; 409 pub const EKEYREVOKED: i32 = 128; 410 pub const EKEYREJECTED: i32 = 129; 411 pub const EOWNERDEAD: i32 = 130; 412 pub const ENOTRECOVERABLE: i32 = 131; 413 pub const ERFKILL: i32 = 132; 414 pub const EHWPOISON: i32 = 133; 415 pub const ELBIN: i32 = 134; 416 pub const EFTYPE: i32 = 135; 417 pub const ENMFILE: i32 = 136; 418 pub const EPROCLIM: i32 = 137; 419 pub const ENOTSUP: i32 = 138; 420 pub const ENOSHARE: i32 = 139; 421 pub const ECASECLASH: i32 = 140; 422 423 // fcntl.h 424 pub const FIOCLEX: i32 = 0x30b; 425 pub const F_SETFL: i32 = 0x9; 426 pub const F_DUPFD_CLOEXEC: i32 = 0x12; 427 pub const F_GETFD: i32 = 0x1; 428 pub const F_GETFL: i32 = 0x2; 429 pub const O_RDONLY: i32 = 0x1; 430 pub const O_WRONLY: i32 = 0x2; 431 pub const O_RDWR: i32 = 0x3; 432 pub const O_CREAT: i32 = 0x4; 433 pub const O_EXCL: i32 = 0x8; 434 pub const O_NOCTTY: i32 = 0x0; 435 pub const O_TRUNC: i32 = 0x20; 436 pub const O_APPEND: i32 = 0x10; 437 pub const O_NONBLOCK: i32 = 0x40; 438 pub const O_DSYNC: i32 = 0x80; 439 pub const O_DIRECT: i32 = 0x200; 440 pub const O_LARGEFILE: i32 = 0x2000; 441 pub const O_DIRECTORY: i32 = 0x800; 442 pub const O_NOFOLLOW: i32 = 0x1000; 443 pub const O_NOATIME: i32 = 0x40000; 444 pub const O_CLOEXEC: i32 = 0x400; 445 pub const O_ACCMODE: i32 = 0x0003; 446 pub const AT_FDCWD: i32 = -100; 447 pub const AT_REMOVEDIR: i32 = 0x200; 448 449 // sys/types.h 450 pub const SEEK_SET: i32 = 0; 451 pub const SEEK_CUR: i32 = 1; 452 pub const SEEK_END: i32 = 2; 453 454 // sys/stat.h 455 pub const S_IFDIR: u32 = 0x4000; 456 pub const S_IFLNK: u32 = 0xA000; 457 pub const S_IFREG: u32 = 0x8000; 458 pub const S_IFMT: u32 = 0xF000; 459 pub const S_IFIFO: u32 = 0x1000; 460 pub const S_IFSOCK: u32 = 0xc000; 461 pub const S_IFBLK: u32 = 0x6000; 462 pub const S_IFCHR: u32 = 0x2000; 463 pub const S_IRUSR: u32 = 0x100; 464 pub const S_IWUSR: u32 = 0x80; 465 pub const S_IXUSR: u32 = 0x40; 466 pub const S_IRGRP: u32 = 0x20; 467 pub const S_IWGRP: u32 = 0x10; 468 pub const S_IXGRP: u32 = 0x8; 469 pub const S_IROTH: u32 = 0x004; 470 pub const S_IWOTH: u32 = 0x002; 471 pub const S_IXOTH: u32 = 0x001; 472 473 // sys/poll.h 474 pub const POLLIN: i16 = 0x01; 475 pub const POLLOUT: i16 = 0x04; 476 pub const POLLHUP: i16 = 0x10; 477 pub const POLLERR: i16 = 0x08; 478 pub const POLLNVAL: i16 = 0x20; 479 480 // sys/socket.h 481 pub const AF_UNIX: i32 = 1; 482 pub const SOCK_DGRAM: i32 = 2; 483 pub const SOCK_STREAM: i32 = 1; 484 pub const AF_INET: i32 = 2; 485 pub const AF_INET6: i32 = 10; 486 pub const MSG_PEEK: i32 = 0x02; 487 pub const SOL_SOCKET: i32 = 1; 488 pub const SHUT_WR: i32 = 2; 489 pub const SHUT_RD: i32 = 1; 490 pub const SHUT_RDWR: i32 = 3; 491 pub const SO_ERROR: i32 = 4; 492 pub const SO_REUSEADDR: i32 = 11; 493 pub const SOMAXCONN: i32 = 8; 494 pub const SO_LINGER: i32 = 6; 495 pub const SO_RCVTIMEO: i32 = 0xa; 496 pub const SO_SNDTIMEO: i32 = 0xe; 497 pub const SO_BROADCAST: i32 = 1; 498 499 // netinet/tcp.h 500 pub const TCP_NODELAY: i32 = 0x10; 501 502 // nuttx/fs/ioctl.h 503 pub const FIONBIO: i32 = 0x30a; 504 505 // unistd.h 506 pub const STDIN_FILENO: i32 = 0; 507 pub const STDOUT_FILENO: i32 = 1; 508 pub const STDERR_FILENO: i32 = 2; 509 pub const _SC_PAGESIZE: i32 = 0x36; 510 pub const _SC_THREAD_STACK_MIN: i32 = 0x58; 511 pub const _SC_GETPW_R_SIZE_MAX: i32 = 0x25; 512 513 // signal.h 514 pub const SIGPIPE: i32 = 13; 515 516 // pthread.h 517 pub const PTHREAD_MUTEX_NORMAL: i32 = 0; 518 519 // netinet/in.h 520 pub const IP_TTL: i32 = 0x1e; 521 pub const IPV6_V6ONLY: i32 = 0x17; 522 pub const IPV6_JOIN_GROUP: i32 = 0x11; 523 pub const IPV6_LEAVE_GROUP: i32 = 0x12; 524 pub const IP_MULTICAST_LOOP: i32 = 0x13; 525 pub const IPV6_MULTICAST_LOOP: i32 = 0x15; 526 pub const IP_MULTICAST_TTL: i32 = 0x12; 527 pub const IP_ADD_MEMBERSHIP: i32 = 0x14; 528 pub const IP_DROP_MEMBERSHIP: i32 = 0x15; 529 530 extern "C" { bind(sockfd: i32, addr: *const sockaddr, addrlen: socklen_t) -> i32531 pub fn bind(sockfd: i32, addr: *const sockaddr, addrlen: socklen_t) -> i32; ioctl(fd: i32, request: i32, ...) -> i32532 pub fn ioctl(fd: i32, request: i32, ...) -> i32; dirfd(dirp: *mut DIR) -> i32533 pub fn dirfd(dirp: *mut DIR) -> i32; recvfrom( sockfd: i32, buf: *mut c_void, len: usize, flags: i32, src_addr: *mut sockaddr, addrlen: *mut socklen_t, ) -> i32534 pub fn recvfrom( 535 sockfd: i32, 536 buf: *mut c_void, 537 len: usize, 538 flags: i32, 539 src_addr: *mut sockaddr, 540 addrlen: *mut socklen_t, 541 ) -> i32; 542 pthread_create( thread: *mut pthread_t, attr: *const pthread_attr_t, start_routine: extern "C" fn(*mut c_void) -> *mut c_void, arg: *mut c_void, ) -> i32543 pub fn pthread_create( 544 thread: *mut pthread_t, 545 attr: *const pthread_attr_t, 546 start_routine: extern "C" fn(*mut c_void) -> *mut c_void, 547 arg: *mut c_void, 548 ) -> i32; 549 clock_gettime(clockid: clockid_t, tp: *mut timespec) -> i32550 pub fn clock_gettime(clockid: clockid_t, tp: *mut timespec) -> i32; futimens(fd: i32, times: *const timespec) -> i32551 pub fn futimens(fd: i32, times: *const timespec) -> i32; pthread_condattr_setclock(attr: *mut pthread_condattr_t, clock_id: clockid_t) -> i32552 pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t, clock_id: clockid_t) -> i32; pthread_set_name_np(thread: pthread_t, name: *const c_char) -> i32553 pub fn pthread_set_name_np(thread: pthread_t, name: *const c_char) -> i32; getrandom(buf: *mut c_void, buflen: usize, flags: u32) -> isize554 pub fn getrandom(buf: *mut c_void, buflen: usize, flags: u32) -> isize; 555 } 556