1# 2# 3# Nim's Runtime Library 4# (c) Copyright 2012 Andreas Rumpf 5# 6# See the file "copying.txt", included in this 7# distribution, for details about the copyright. 8# 9 10when defined(nimHasStyleChecks): 11 {.push styleChecks: off.} 12 13const 14 hasSpawnH = true # should exist for every Posix system nowadays 15 hasAioH = false 16 17type 18 DIR* {.importc: "DIR", header: "<dirent.h>", 19 incompleteStruct.} = object 20 ## A type representing a directory stream. 21 22type 23 SocketHandle* = distinct cint # The type used to represent socket descriptors 24 25type 26 Time* {.importc: "time_t", header: "<time.h>".} = distinct clong 27 28 Timespec* {.importc: "struct timespec", 29 header: "<time.h>", final, pure.} = object ## struct timespec 30 tv_sec*: Time ## Seconds. 31 tv_nsec*: int ## Nanoseconds. 32 33 Dirent* {.importc: "struct dirent", 34 header: "<dirent.h>", final, pure.} = object ## dirent_t struct 35 when defined(haiku): 36 d_dev*: Dev ## Device (not POSIX) 37 d_pdev*: Dev ## Parent device (only for queries) (not POSIX) 38 d_ino*: Ino ## File serial number. 39 when defined(dragonfly): 40 # DragonflyBSD doesn't have `d_reclen` field. 41 d_type*: uint8 42 elif defined(linux) or defined(macosx) or defined(freebsd) or 43 defined(netbsd) or defined(openbsd) or defined(genode): 44 d_reclen*: cshort ## Length of this record. (not POSIX) 45 d_type*: int8 ## Type of file; not supported by all filesystem types. 46 ## (not POSIX) 47 when defined(linux) or defined(openbsd): 48 d_off*: Off ## Not an offset. Value that `telldir()` would return. 49 elif defined(haiku): 50 d_pino*: Ino ## Parent inode (only for queries) (not POSIX) 51 d_reclen*: cushort ## Length of this record. (not POSIX) 52 53 d_name*: array[0..255, char] ## Name of entry. 54 55 Tflock* {.importc: "struct flock", final, pure, 56 header: "<fcntl.h>".} = object ## flock type 57 l_type*: cshort ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK. 58 l_whence*: cshort ## Flag for starting offset. 59 l_start*: Off ## Relative offset in bytes. 60 l_len*: Off ## Size; if 0 then until EOF. 61 l_pid*: Pid ## Process ID of the process holding the lock; 62 ## returned with F_GETLK. 63 64 FTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object 65 base*: cint 66 level*: cint 67 68 Glob* {.importc: "glob_t", header: "<glob.h>", 69 final, pure.} = object ## glob_t 70 gl_pathc*: int ## Count of paths matched by pattern. 71 gl_pathv*: cstringArray ## Pointer to a list of matched pathnames. 72 gl_offs*: int ## Slots to reserve at the beginning of gl_pathv. 73 74 Group* {.importc: "struct group", header: "<grp.h>", 75 final, pure.} = object ## struct group 76 gr_name*: cstring ## The name of the group. 77 gr_gid*: Gid ## Numerical group ID. 78 gr_mem*: cstringArray ## Pointer to a null-terminated array of character 79 ## pointers to member names. 80 81 Iconv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} = 82 object ## Identifies the conversion from one codeset to another. 83 84 Lconv* {.importc: "struct lconv", header: "<locale.h>", final, 85 pure.} = object 86 currency_symbol*: cstring 87 decimal_point*: cstring 88 frac_digits*: char 89 grouping*: cstring 90 int_curr_symbol*: cstring 91 int_frac_digits*: char 92 int_n_cs_precedes*: char 93 int_n_sep_by_space*: char 94 int_n_sign_posn*: char 95 int_p_cs_precedes*: char 96 int_p_sep_by_space*: char 97 int_p_sign_posn*: char 98 mon_decimal_point*: cstring 99 mon_grouping*: cstring 100 mon_thousands_sep*: cstring 101 negative_sign*: cstring 102 n_cs_precedes*: char 103 n_sep_by_space*: char 104 n_sign_posn*: char 105 positive_sign*: cstring 106 p_cs_precedes*: char 107 p_sep_by_space*: char 108 p_sign_posn*: char 109 thousands_sep*: cstring 110 111 Mqd* {.importc: "mqd_t", header: "<mqueue.h>", final, pure.} = object 112 MqAttr* {.importc: "struct mq_attr", 113 header: "<mqueue.h>", 114 final, pure.} = object ## message queue attribute 115 mq_flags*: int ## Message queue flags. 116 mq_maxmsg*: int ## Maximum number of messages. 117 mq_msgsize*: int ## Maximum message size. 118 mq_curmsgs*: int ## Number of messages currently queued. 119 120 Passwd* {.importc: "struct passwd", header: "<pwd.h>", 121 final, pure.} = object ## struct passwd 122 pw_name*: cstring ## User's login name. 123 pw_uid*: Uid ## Numerical user ID. 124 pw_gid*: Gid ## Numerical group ID. 125 pw_dir*: cstring ## Initial working directory. 126 pw_shell*: cstring ## Program to use as shell. 127 128 Blkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = int 129 ## used for file block counts 130 Blksize* {.importc: "blksize_t", header: "<sys/types.h>".} = int32 131 ## used for block sizes 132 Clock* {.importc: "clock_t", header: "<sys/types.h>".} = int 133 ClockId* {.importc: "clockid_t", header: "<sys/types.h>".} = int 134 Dev* {.importc: "dev_t", header: "<sys/types.h>".} = int32 135 Fsblkcnt* {.importc: "fsblkcnt_t", header: "<sys/types.h>".} = int 136 Fsfilcnt* {.importc: "fsfilcnt_t", header: "<sys/types.h>".} = int 137 Gid* {.importc: "gid_t", header: "<sys/types.h>".} = int32 138 Id* {.importc: "id_t", header: "<sys/types.h>".} = int 139 Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int 140 Key* {.importc: "key_t", header: "<sys/types.h>".} = int 141 Mode* {.importc: "mode_t", header: "<sys/types.h>".} = ( 142 when defined(openbsd) or defined(netbsd): 143 uint32 144 else: 145 uint16 146 ) 147 Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = int16 148 Off* {.importc: "off_t", header: "<sys/types.h>".} = int64 149 Pid* {.importc: "pid_t", header: "<sys/types.h>".} = int32 150 Pthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>".} = int 151 Pthread_barrier* {.importc: "pthread_barrier_t", 152 header: "<sys/types.h>".} = int 153 Pthread_barrierattr* {.importc: "pthread_barrierattr_t", 154 header: "<sys/types.h>".} = int 155 Pthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>".} = int 156 Pthread_condattr* {.importc: "pthread_condattr_t", 157 header: "<sys/types.h>".} = int 158 Pthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = int 159 Pthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>".} = int 160 Pthread_mutexattr* {.importc: "pthread_mutexattr_t", 161 header: "<sys/types.h>".} = int 162 Pthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = int 163 Pthread_rwlock* {.importc: "pthread_rwlock_t", 164 header: "<sys/types.h>".} = int 165 Pthread_rwlockattr* {.importc: "pthread_rwlockattr_t", 166 header: "<sys/types.h>".} = int 167 Pthread_spinlock* {.importc: "pthread_spinlock_t", 168 header: "<sys/types.h>".} = int 169 Pthread* {.importc: "pthread_t", header: "<sys/types.h>".} = int 170 Suseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = int32 171 #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int 172 Timer* {.importc: "timer_t", header: "<sys/types.h>".} = int 173 Trace_attr* {.importc: "trace_attr_t", header: "<sys/types.h>".} = int 174 Trace_event_id* {.importc: "trace_event_id_t", 175 header: "<sys/types.h>".} = int 176 Trace_event_set* {.importc: "trace_event_set_t", 177 header: "<sys/types.h>".} = int 178 Trace_id* {.importc: "trace_id_t", header: "<sys/types.h>".} = int 179 Uid* {.importc: "uid_t", header: "<sys/types.h>".} = int32 180 Useconds* {.importc: "useconds_t", header: "<sys/types.h>".} = int 181 182 Utsname* {.importc: "struct utsname", 183 header: "<sys/utsname.h>", 184 final, pure.} = object ## struct utsname 185 sysname*, ## Name of this implementation of the operating system. 186 nodename*, ## Name of this node within the communications 187 ## network to which this node is attached, if any. 188 release*, ## Current release level of this implementation. 189 version*, ## Current version level of this release. 190 machine*: array[0..255, char] ## Name of the hardware type on which the 191 ## system is running. 192 193 Sem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object 194 Ipc_perm* {.importc: "struct ipc_perm", 195 header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm 196 uid*: Uid ## Owner's user ID. 197 gid*: Gid ## Owner's group ID. 198 cuid*: Uid ## Creator's user ID. 199 cgid*: Gid ## Creator's group ID. 200 mode*: Mode ## Read/write permission. 201 202 Stat* {.importc: "struct stat", 203 header: "<sys/stat.h>", final, pure.} = object ## struct stat 204 st_dev*: Dev ## Device ID of device containing file. 205 st_ino*: Ino ## File serial number. 206 st_mode*: Mode ## Mode of file (see below). 207 st_nlink*: Nlink ## Number of hard links to the file. 208 st_uid*: Uid ## User ID of file. 209 st_gid*: Gid ## Group ID of file. 210 st_rdev*: Dev ## Device ID (if file is character or block special). 211 st_size*: Off ## For regular files, the file size in bytes. 212 ## For symbolic links, the length in bytes of the 213 ## pathname contained in the symbolic link. 214 ## For a shared memory object, the length in bytes. 215 ## For a typed memory object, the length in bytes. 216 ## For other file types, the use of this field is 217 ## unspecified. 218 when defined(osx): 219 st_atim* {.importc:"st_atimespec".}: Timespec ## Time of last access. 220 st_mtim* {.importc:"st_mtimespec".}: Timespec ## Time of last data modification. 221 st_ctim* {.importc:"st_ctimespec".}: Timespec ## Time of last status change. 222 elif StatHasNanoseconds: 223 st_atim*: Timespec ## Time of last access. 224 st_mtim*: Timespec ## Time of last data modification. 225 st_ctim*: Timespec ## Time of last status change. 226 else: 227 st_atime*: Time ## Time of last access. 228 st_mtime*: Time ## Time of last data modification. 229 st_ctime*: Time ## Time of last status change. 230 231 st_blksize*: Blksize ## A file system-specific preferred I/O block size 232 ## for this object. In some file system types, this 233 ## may vary from file to file. 234 st_blocks*: Blkcnt ## Number of blocks allocated for this object. 235 236 237 Statvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>", 238 final, pure.} = object ## struct statvfs 239 f_bsize*: int ## File system block size. 240 f_frsize*: int ## Fundamental file system block size. 241 f_blocks*: Fsblkcnt ## Total number of blocks on file system 242 ## in units of f_frsize. 243 f_bfree*: Fsblkcnt ## Total number of free blocks. 244 f_bavail*: Fsblkcnt ## Number of free blocks available to 245 ## non-privileged process. 246 f_files*: Fsfilcnt ## Total number of file serial numbers. 247 f_ffree*: Fsfilcnt ## Total number of free file serial numbers. 248 f_favail*: Fsfilcnt ## Number of file serial numbers available to 249 ## non-privileged process. 250 f_fsid*: int ## File system ID. 251 f_flag*: int ## Bit mask of f_flag values. 252 f_namemax*: int ## Maximum filename length. 253 254 Posix_typed_mem_info* {.importc: "struct posix_typed_mem_info", 255 header: "<sys/mman.h>", final, pure.} = object 256 posix_tmi_length*: int 257 258 Tm* {.importc: "struct tm", header: "<time.h>", 259 final, pure.} = object ## struct tm 260 tm_sec*: cint ## Seconds [0,60]. 261 tm_min*: cint ## Minutes [0,59]. 262 tm_hour*: cint ## Hour [0,23]. 263 tm_mday*: cint ## Day of month [1,31]. 264 tm_mon*: cint ## Month of year [0,11]. 265 tm_year*: cint ## Years since 1900. 266 tm_wday*: cint ## Day of week [0,6] (Sunday =0). 267 tm_yday*: cint ## Day of year [0,365]. 268 tm_isdst*: cint ## Daylight Savings flag. 269 Itimerspec* {.importc: "struct itimerspec", header: "<time.h>", 270 final, pure.} = object ## struct itimerspec 271 it_interval*: Timespec ## Timer period. 272 it_value*: Timespec ## Timer expiration. 273 274 Sig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint 275 ## Possibly volatile-qualified integer type of an object that can be 276 ## accessed as an atomic entity, even in the presence of asynchronous 277 ## interrupts. 278 Sigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object 279 280 SigEvent* {.importc: "struct sigevent", 281 header: "<signal.h>", final, pure.} = object ## struct sigevent 282 sigev_notify*: cint ## Notification type. 283 sigev_signo*: cint ## Signal number. 284 sigev_value*: SigVal ## Signal value. 285 sigev_notify_function*: proc (x: SigVal) {.noconv.} ## Notification func. 286 sigev_notify_attributes*: ptr Pthread_attr ## Notification attributes. 287 288 SigVal* {.importc: "union sigval", 289 header: "<signal.h>", final, pure.} = object ## struct sigval 290 sival_ptr*: pointer ## pointer signal value; 291 ## integer signal value not defined! 292 Sigaction* {.importc: "struct sigaction", 293 header: "<signal.h>", final, pure.} = object ## struct sigaction 294 sa_handler*: proc (x: cint) {.noconv.} ## Pointer to a signal-catching 295 ## function or one of the macros 296 ## SIG_IGN or SIG_DFL. 297 sa_mask*: Sigset ## Set of signals to be blocked during execution of 298 ## the signal handling function. 299 sa_flags*: cint ## Special flags. 300 sa_sigaction*: proc (x: cint, y: ptr SigInfo, z: pointer) {.noconv.} 301 302 Stack* {.importc: "stack_t", 303 header: "<signal.h>", final, pure.} = object ## stack_t 304 ss_sp*: pointer ## Stack base or pointer. 305 ss_size*: int ## Stack size. 306 ss_flags*: cint ## Flags. 307 308 SigStack* {.importc: "struct sigstack", 309 header: "<signal.h>", final, pure.} = object ## struct sigstack 310 ss_onstack*: cint ## Non-zero when signal stack is in use. 311 ss_sp*: pointer ## Signal stack pointer. 312 313 SigInfo* {.importc: "siginfo_t", 314 header: "<signal.h>", final, pure.} = object ## siginfo_t 315 si_signo*: cint ## Signal number. 316 si_code*: cint ## Signal code. 317 si_errno*: cint ## If non-zero, an errno value associated with 318 ## this signal, as defined in <errno.h>. 319 si_pid*: Pid ## Sending process ID. 320 si_uid*: Uid ## Real user ID of sending process. 321 si_addr*: pointer ## Address of faulting instruction. 322 si_status*: cint ## Exit value or signal. 323 si_band*: int ## Band event for SIGPOLL. 324 si_value*: SigVal ## Signal value. 325 326 Nl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint 327 Nl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint 328 329 Sched_param* {.importc: "struct sched_param", 330 header: "<sched.h>", 331 final, pure.} = object ## struct sched_param 332 sched_priority*: cint 333 sched_ss_low_priority*: cint ## Low scheduling priority for 334 ## sporadic server. 335 sched_ss_repl_period*: Timespec ## Replenishment period for 336 ## sporadic server. 337 sched_ss_init_budget*: Timespec ## Initial budget for sporadic server. 338 sched_ss_max_repl*: cint ## Maximum pending replenishments for 339 ## sporadic server. 340 341 Timeval* {.importc: "struct timeval", header: "<sys/select.h>", 342 final, pure.} = object ## struct timeval 343 tv_sec*: Time ## Seconds. 344 tv_usec*: Suseconds ## Microseconds. 345 TFdSet* {.importc: "fd_set", header: "<sys/select.h>", 346 final, pure.} = object 347 Mcontext* {.importc: "mcontext_t", header: "<ucontext.h>", 348 final, pure.} = object 349 Ucontext* {.importc: "ucontext_t", header: "<ucontext.h>", 350 final, pure.} = object ## ucontext_t 351 uc_link*: ptr Ucontext ## Pointer to the context that is resumed 352 ## when this context returns. 353 uc_sigmask*: Sigset ## The set of signals that are blocked when this 354 ## context is active. 355 uc_stack*: Stack ## The stack used by this context. 356 uc_mcontext*: Mcontext ## A machine-specific representation of the saved 357 ## context. 358 359when hasAioH: 360 type 361 Taiocb* {.importc: "struct aiocb", header: "<aio.h>", 362 final, pure.} = object ## struct aiocb 363 aio_fildes*: cint ## File descriptor. 364 aio_offset*: Off ## File offset. 365 aio_buf*: pointer ## Location of buffer. 366 aio_nbytes*: int ## Length of transfer. 367 aio_reqprio*: cint ## Request priority offset. 368 aio_sigevent*: SigEvent ## Signal number and value. 369 aio_lio_opcode: cint ## Operation to be performed. 370 371when hasSpawnH: 372 type 373 Tposix_spawnattr* {.importc: "posix_spawnattr_t", 374 header: "<spawn.h>", final, pure.} = object 375 Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t", 376 header: "<spawn.h>", final, pure.} = object 377 378when defined(linux): 379 # from sys/un.h 380 const Sockaddr_un_path_length* = 108 381else: 382 # according to http://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/un.h.html 383 # this is >=92 384 const Sockaddr_un_path_length* = 92 385 386type 387 SockLen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint 388 TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = uint8 389 390 SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>", 391 pure, final.} = object ## struct sockaddr 392 sa_family*: TSa_Family ## Address family. 393 sa_data*: array[0..255, char] ## Socket address (variable-length data). 394 395 Sockaddr_un* {.importc: "struct sockaddr_un", header: "<sys/un.h>", 396 pure, final.} = object ## struct sockaddr_un 397 sun_family*: TSa_Family ## Address family. 398 sun_path*: array[0..Sockaddr_un_path_length-1, char] ## Socket path 399 400 Sockaddr_storage* {.importc: "struct sockaddr_storage", 401 header: "<sys/socket.h>", 402 pure, final.} = object ## struct sockaddr_storage 403 ss_family*: TSa_Family ## Address family. 404 405 Tif_nameindex* {.importc: "struct if_nameindex", final, 406 pure, header: "<net/if.h>".} = object ## struct if_nameindex 407 if_index*: cint ## Numeric index of the interface. 408 if_name*: cstring ## Null-terminated name of the interface. 409 410 411 IOVec* {.importc: "struct iovec", pure, final, 412 header: "<sys/uio.h>".} = object ## struct iovec 413 iov_base*: pointer ## Base address of a memory region for input or output. 414 iov_len*: csize_t ## The size of the memory pointed to by iov_base. 415 416 Tmsghdr* {.importc: "struct msghdr", pure, final, 417 header: "<sys/socket.h>".} = object ## struct msghdr 418 msg_name*: pointer ## Optional address. 419 msg_namelen*: SockLen ## Size of address. 420 msg_iov*: ptr IOVec ## Scatter/gather array. 421 msg_iovlen*: cint ## Members in msg_iov. 422 msg_control*: pointer ## Ancillary data; see below. 423 msg_controllen*: SockLen ## Ancillary data buffer len. 424 msg_flags*: cint ## Flags on received message. 425 426 427 Tcmsghdr* {.importc: "struct cmsghdr", pure, final, 428 header: "<sys/socket.h>".} = object ## struct cmsghdr 429 cmsg_len*: SockLen ## Data byte count, including the cmsghdr. 430 cmsg_level*: cint ## Originating protocol. 431 cmsg_type*: cint ## Protocol-specific type. 432 433 TLinger* {.importc: "struct linger", pure, final, 434 header: "<sys/socket.h>".} = object ## struct linger 435 l_onoff*: cint ## Indicates whether linger option is enabled. 436 l_linger*: cint ## Linger time, in seconds. 437 438 InPort* = uint16 439 InAddrScalar* = uint32 440 441 InAddrT* {.importc: "in_addr_t", pure, final, 442 header: "<netinet/in.h>".} = uint32 443 444 InAddr* {.importc: "struct in_addr", pure, final, 445 header: "<netinet/in.h>".} = object ## struct in_addr 446 s_addr*: InAddrScalar 447 448 Sockaddr_in* {.importc: "struct sockaddr_in", pure, final, 449 header: "<netinet/in.h>".} = object ## struct sockaddr_in 450 sin_family*: TSa_Family ## AF_INET. 451 sin_port*: InPort ## Port number. 452 sin_addr*: InAddr ## IP address. 453 454 In6Addr* {.importc: "struct in6_addr", pure, final, 455 header: "<netinet/in.h>".} = object ## struct in6_addr 456 s6_addr*: array[0..15, char] 457 458 Sockaddr_in6* {.importc: "struct sockaddr_in6", pure, final, 459 header: "<netinet/in.h>".} = object ## struct sockaddr_in6 460 sin6_family*: TSa_Family ## AF_INET6. 461 sin6_port*: InPort ## Port number. 462 sin6_flowinfo*: int32 ## IPv6 traffic class and flow information. 463 sin6_addr*: In6Addr ## IPv6 address. 464 sin6_scope_id*: int32 ## Set of interfaces for a scope. 465 466 Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final, 467 header: "<netinet/in.h>".} = object ## struct ipv6_mreq 468 ipv6mr_multiaddr*: In6Addr ## IPv6 multicast address. 469 ipv6mr_interface*: cint ## Interface index. 470 471 Hostent* {.importc: "struct hostent", pure, final, 472 header: "<netdb.h>".} = object ## struct hostent 473 h_name*: cstring ## Official name of the host. 474 h_aliases*: cstringArray ## A pointer to an array of pointers to 475 ## alternative host names, terminated by a 476 ## null pointer. 477 h_addrtype*: cint ## Address type. 478 h_length*: cint ## The length, in bytes, of the address. 479 h_addr_list*: cstringArray ## A pointer to an array of pointers to network 480 ## addresses (in network byte order) for the 481 ## host, terminated by a null pointer. 482 483 Tnetent* {.importc: "struct netent", pure, final, 484 header: "<netdb.h>".} = object ## struct netent 485 n_name*: cstring ## Official, fully-qualified (including the 486 ## domain) name of the host. 487 n_aliases*: cstringArray ## A pointer to an array of pointers to 488 ## alternative network names, terminated by a 489 ## null pointer. 490 n_addrtype*: cint ## The address type of the network. 491 n_net*: int32 ## The network number, in host byte order. 492 493 Protoent* {.importc: "struct protoent", pure, final, 494 header: "<netdb.h>".} = object ## struct protoent 495 p_name*: cstring ## Official name of the protocol. 496 p_aliases*: cstringArray ## A pointer to an array of pointers to 497 ## alternative protocol names, terminated by 498 ## a null pointer. 499 p_proto*: cint ## The protocol number. 500 501 Servent* {.importc: "struct servent", pure, final, 502 header: "<netdb.h>".} = object ## struct servent 503 s_name*: cstring ## Official name of the service. 504 s_aliases*: cstringArray ## A pointer to an array of pointers to 505 ## alternative service names, terminated by 506 ## a null pointer. 507 s_port*: cint ## The port number at which the service 508 ## resides, in network byte order. 509 s_proto*: cstring ## The name of the protocol to use when 510 ## contacting the service. 511 512 AddrInfo* {.importc: "struct addrinfo", pure, final, 513 header: "<netdb.h>".} = object ## struct addrinfo 514 ai_flags*: cint ## Input flags. 515 ai_family*: cint ## Address family of socket. 516 ai_socktype*: cint ## Socket type. 517 ai_protocol*: cint ## Protocol of socket. 518 ai_addrlen*: SockLen ## Length of socket address. 519 ai_addr*: ptr SockAddr ## Socket address of socket. 520 ai_canonname*: cstring ## Canonical name of service location. 521 ai_next*: ptr AddrInfo ## Pointer to next in list. 522 523 TPollfd* {.importc: "struct pollfd", pure, final, 524 header: "<poll.h>".} = object ## struct pollfd 525 fd*: cint ## The following descriptor being polled. 526 events*: cshort ## The input event flags (see below). 527 revents*: cshort ## The output event flags (see below). 528 529 Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = cint 530 531var 532 errno* {.importc, header: "<errno.h>".}: cint ## error variable 533 h_errno* {.importc, header: "<netdb.h>".}: cint 534 daylight* {.importc, header: "<time.h>".}: cint 535 timezone* {.importc, header: "<time.h>".}: int 536 537# Regenerate using detect.nim! 538include posix_other_consts 539 540when defined(linux): 541 var 542 MAP_POPULATE* {.importc, header: "<sys/mman.h>".}: cint 543 ## Populate (prefault) page tables for a mapping. 544else: 545 var 546 MAP_POPULATE*: cint = 0 547 548when defined(linux) or defined(nimdoc): 549 when defined(alpha) or defined(mips) or defined(mipsel) or 550 defined(mips64) or defined(mips64el) or defined(parisc) or 551 defined(sparc) or defined(sparc64) or defined(nimdoc): 552 const SO_REUSEPORT* = cint(0x0200) 553 ## Multiple binding: load balancing on incoming TCP connections 554 ## or UDP packets. (Requires Linux kernel > 3.9) 555 else: 556 const SO_REUSEPORT* = cint(15) 557else: 558 var SO_REUSEPORT* {.importc, header: "<sys/socket.h>".}: cint 559 560when defined(linux) or defined(bsd): 561 var SOCK_CLOEXEC* {.importc, header: "<sys/socket.h>".}: cint 562 563when defined(macosx): 564 # We can't use the NOSIGNAL flag in the `send` function, it has no effect 565 # Instead we should use SO_NOSIGPIPE in setsockopt 566 const 567 MSG_NOSIGNAL* = 0'i32 568 var 569 SO_NOSIGPIPE* {.importc, header: "<sys/socket.h>".}: cint 570elif defined(solaris): 571 # Solaris doesn't have MSG_NOSIGNAL 572 const 573 MSG_NOSIGNAL* = 0'i32 574else: 575 var 576 MSG_NOSIGNAL* {.importc, header: "<sys/socket.h>".}: cint 577 ## No SIGPIPE generated when an attempt to send is made on a stream-oriented socket that is no longer connected. 578 579when defined(haiku): 580 const 581 SIGKILLTHR* = 21 ## BeOS specific: Kill just the thread, not team 582 583when hasSpawnH: 584 when defined(linux): 585 # better be safe than sorry; Linux has this flag, macosx doesn't, don't 586 # know about the other OSes 587 588 # Non-GNU systems like TCC and musl-libc don't define __USE_GNU, so we 589 # can't get the magic number from spawn.h 590 const POSIX_SPAWN_USEVFORK* = cint(0x40) 591 else: 592 # macosx lacks this, so we define the constant to be 0 to not affect 593 # OR'ing of flags: 594 const POSIX_SPAWN_USEVFORK* = cint(0) 595 596# <sys/wait.h> 597proc WEXITSTATUS*(s: cint): cint {.importc, header: "<sys/wait.h>".} 598 ## Exit code, if WIFEXITED(s) 599proc WTERMSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".} 600 ## Termination signal, if WIFSIGNALED(s) 601proc WSTOPSIG*(s: cint): cint {.importc, header: "<sys/wait.h>".} 602 ## Stop signal, if WIFSTOPPED(s) 603proc WIFEXITED*(s: cint): bool {.importc, header: "<sys/wait.h>".} 604 ## True if child exited normally. 605proc WIFSIGNALED*(s: cint): bool {.importc, header: "<sys/wait.h>".} 606 ## True if child exited due to uncaught signal. 607proc WIFSTOPPED*(s: cint): bool {.importc, header: "<sys/wait.h>".} 608 ## True if child is currently stopped. 609proc WIFCONTINUED*(s: cint): bool {.importc, header: "<sys/wait.h>".} 610 ## True if child has been continued. 611 612when defined(nimHasStyleChecks): 613 {.pop.} 614