diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2014-02-01 16:11:09 -0800 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2014-02-01 16:11:09 -0800 |
commit | 087448d167531d4acdd9e85d32302b638bb268f7 (patch) | |
tree | 572be8806dd01e773e2b83ff2f7e239f1519294c /lib | |
parent | 8fa4401b20935ddc85bd160c82ce87c081d2f53b (diff) | |
parent | e0e0b409e49b53e9c95de6fcb0372707b3869de6 (diff) | |
download | Nim-087448d167531d4acdd9e85d32302b638bb268f7.tar.gz |
Merge pull request #830 from zielmicha/osproc
osproc: introduce poEvalCommand, poUsePath, fix remaining quoting issues.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/posix/posix.nim | 891 | ||||
-rw-r--r-- | lib/pure/osproc.nim | 179 |
2 files changed, 536 insertions, 534 deletions
diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim index 685a1dafc..c3d5b5939 100644 --- a/lib/posix/posix.nim +++ b/lib/posix/posix.nim @@ -14,7 +14,7 @@ ## This is a raw POSIX interface module. It does not not provide any ## convenience: cstrings are used instead of proper Nimrod strings and -## return codes indicate errors. If you want exceptions +## return codes indicate errors. If you want exceptions ## and a proper Nimrod-like interface, use the OS module or write a wrapper. ## Coding conventions: @@ -63,74 +63,74 @@ const MM_NULLTXT* = nil MM_NULLACT* = nil MM_NULLTAG* = nil - + STDERR_FILENO* = 2 ## File number of stderr; STDIN_FILENO* = 0 ## File number of stdin; - STDOUT_FILENO* = 1 ## File number of stdout; + STDOUT_FILENO* = 1 ## File number of stdout; when defined(endb): # to not break bootstrapping again ... type - TDIR* {.importc: "DIR", header: "<dirent.h>", + TDIR* {.importc: "DIR", header: "<dirent.h>", final, pure, incompleteStruct.} = object - ## A type representing a directory stream. + ## A type representing a directory stream. else: type - TDIR* {.importc: "DIR", header: "<dirent.h>", + TDIR* {.importc: "DIR", header: "<dirent.h>", final, pure.} = object - ## A type representing a directory stream. - + ## A type representing a directory stream. + type TSocketHandle* = distinct cint # The type used to represent socket descriptors - Tdirent* {.importc: "struct dirent", + Tdirent* {.importc: "struct dirent", header: "<dirent.h>", final, pure.} = object ## dirent_t struct d_ino*: Tino ## File serial number. d_name*: array [0..255, char] ## Name of entry. Tflock* {.importc: "flock", final, pure, header: "<fcntl.h>".} = object ## flock type - l_type*: cshort ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK. - l_whence*: cshort ## Flag for starting offset. - l_start*: TOff ## Relative offset in bytes. - l_len*: TOff ## Size; if 0 then until EOF. - l_pid*: TPid ## Process ID of the process holding the lock; - ## returned with F_GETLK. - - Tfenv* {.importc: "fenv_t", header: "<fenv.h>", final, pure.} = + l_type*: cshort ## Type of lock; F_RDLCK, F_WRLCK, F_UNLCK. + l_whence*: cshort ## Flag for starting offset. + l_start*: TOff ## Relative offset in bytes. + l_len*: TOff ## Size; if 0 then until EOF. + l_pid*: TPid ## Process ID of the process holding the lock; + ## returned with F_GETLK. + + Tfenv* {.importc: "fenv_t", header: "<fenv.h>", final, pure.} = object ## Represents the entire floating-point environment. The ## floating-point environment refers collectively to any ## floating-point status flags and control modes supported ## by the implementation. - Tfexcept* {.importc: "fexcept_t", header: "<fenv.h>", final, pure.} = - object ## Represents the floating-point status flags collectively, - ## including any status the implementation associates with the - ## flags. A floating-point status flag is a system variable + Tfexcept* {.importc: "fexcept_t", header: "<fenv.h>", final, pure.} = + object ## Represents the floating-point status flags collectively, + ## including any status the implementation associates with the + ## flags. A floating-point status flag is a system variable ## whose value is set (but never cleared) when a floating-point ## exception is raised, which occurs as a side effect of ## exceptional floating-point arithmetic to provide auxiliary ## information. A floating-point control mode is a system variable - ## whose value may be set by the user to affect the subsequent + ## whose value may be set by the user to affect the subsequent ## behavior of floating-point arithmetic. TFTW* {.importc: "struct FTW", header: "<ftw.h>", final, pure.} = object base*: cint level*: cint - - TGlob* {.importc: "glob_t", header: "<glob.h>", + + TGlob* {.importc: "glob_t", header: "<glob.h>", final, pure.} = object ## glob_t - gl_pathc*: int ## Count of paths matched by pattern. - gl_pathv*: cstringArray ## Pointer to a list of matched pathnames. - gl_offs*: int ## Slots to reserve at the beginning of gl_pathv. - - TGroup* {.importc: "struct group", header: "<grp.h>", + gl_pathc*: int ## Count of paths matched by pattern. + gl_pathv*: cstringArray ## Pointer to a list of matched pathnames. + gl_offs*: int ## Slots to reserve at the beginning of gl_pathv. + + TGroup* {.importc: "struct group", header: "<grp.h>", final, pure.} = object ## struct group - gr_name*: cstring ## The name of the group. - gr_gid*: TGid ## Numerical group ID. - gr_mem*: cstringArray ## Pointer to a null-terminated array of character - ## pointers to member names. + gr_name*: cstring ## The name of the group. + gr_gid*: TGid ## Numerical group ID. + gr_mem*: cstringArray ## Pointer to a null-terminated array of character + ## pointers to member names. - Ticonv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} = + Ticonv* {.importc: "iconv_t", header: "<iconv.h>", final, pure.} = object ## Identifies the conversion from one codeset to another. Tlconv* {.importc: "struct lconv", header: "<locale.h>", final, @@ -161,21 +161,21 @@ type thousands_sep*: cstring TMqd* {.importc: "mqd_t", header: "<mqueue.h>", final, pure.} = object - TMqAttr* {.importc: "struct mq_attr", - header: "<mqueue.h>", + TMqAttr* {.importc: "struct mq_attr", + header: "<mqueue.h>", final, pure.} = object ## message queue attribute - mq_flags*: int ## Message queue flags. - mq_maxmsg*: int ## Maximum number of messages. - mq_msgsize*: int ## Maximum message size. - mq_curmsgs*: int ## Number of messages currently queued. + mq_flags*: int ## Message queue flags. + mq_maxmsg*: int ## Maximum number of messages. + mq_msgsize*: int ## Maximum message size. + mq_curmsgs*: int ## Number of messages currently queued. - TPasswd* {.importc: "struct passwd", header: "<pwd.h>", + TPasswd* {.importc: "struct passwd", header: "<pwd.h>", final, pure.} = object ## struct passwd - pw_name*: cstring ## User's login name. - pw_uid*: Tuid ## Numerical user ID. - pw_gid*: TGid ## Numerical group ID. - pw_dir*: cstring ## Initial working directory. - pw_shell*: cstring ## Program to use as shell. + pw_name*: cstring ## User's login name. + pw_uid*: Tuid ## Numerical user ID. + pw_gid*: TGid ## Numerical group ID. + pw_dir*: cstring ## Initial working directory. + pw_shell*: cstring ## Program to use as shell. Tblkcnt* {.importc: "blkcnt_t", header: "<sys/types.h>".} = int ## used for file block counts @@ -195,289 +195,289 @@ type TOff* {.importc: "off_t", header: "<sys/types.h>".} = int64 TPid* {.importc: "pid_t", header: "<sys/types.h>".} = int Tpthread_attr* {.importc: "pthread_attr_t", header: "<sys/types.h>".} = int - Tpthread_barrier* {.importc: "pthread_barrier_t", + Tpthread_barrier* {.importc: "pthread_barrier_t", header: "<sys/types.h>".} = int - Tpthread_barrierattr* {.importc: "pthread_barrierattr_t", + Tpthread_barrierattr* {.importc: "pthread_barrierattr_t", header: "<sys/types.h>".} = int Tpthread_cond* {.importc: "pthread_cond_t", header: "<sys/types.h>".} = int - Tpthread_condattr* {.importc: "pthread_condattr_t", + Tpthread_condattr* {.importc: "pthread_condattr_t", header: "<sys/types.h>".} = int Tpthread_key* {.importc: "pthread_key_t", header: "<sys/types.h>".} = int Tpthread_mutex* {.importc: "pthread_mutex_t", header: "<sys/types.h>".} = int - Tpthread_mutexattr* {.importc: "pthread_mutexattr_t", + Tpthread_mutexattr* {.importc: "pthread_mutexattr_t", header: "<sys/types.h>".} = int Tpthread_once* {.importc: "pthread_once_t", header: "<sys/types.h>".} = int - Tpthread_rwlock* {.importc: "pthread_rwlock_t", + Tpthread_rwlock* {.importc: "pthread_rwlock_t", header: "<sys/types.h>".} = int - Tpthread_rwlockattr* {.importc: "pthread_rwlockattr_t", + Tpthread_rwlockattr* {.importc: "pthread_rwlockattr_t", header: "<sys/types.h>".} = int - Tpthread_spinlock* {.importc: "pthread_spinlock_t", + Tpthread_spinlock* {.importc: "pthread_spinlock_t", header: "<sys/types.h>".} = int Tpthread* {.importc: "pthread_t", header: "<sys/types.h>".} = int Tsuseconds* {.importc: "suseconds_t", header: "<sys/types.h>".} = int #Ttime* {.importc: "time_t", header: "<sys/types.h>".} = int Ttimer* {.importc: "timer_t", header: "<sys/types.h>".} = int Ttrace_attr* {.importc: "trace_attr_t", header: "<sys/types.h>".} = int - Ttrace_event_id* {.importc: "trace_event_id_t", + Ttrace_event_id* {.importc: "trace_event_id_t", header: "<sys/types.h>".} = int - Ttrace_event_set* {.importc: "trace_event_set_t", + Ttrace_event_set* {.importc: "trace_event_set_t", header: "<sys/types.h>".} = int Ttrace_id* {.importc: "trace_id_t", header: "<sys/types.h>".} = int Tuid* {.importc: "uid_t", header: "<sys/types.h>".} = int Tuseconds* {.importc: "useconds_t", header: "<sys/types.h>".} = int - - Tutsname* {.importc: "struct utsname", - header: "<sys/utsname.h>", + + Tutsname* {.importc: "struct utsname", + header: "<sys/utsname.h>", final, pure.} = object ## struct utsname - sysname*, ## Name of this implementation of the operating system. - nodename*, ## Name of this node within the communications - ## network to which this node is attached, if any. - release*, ## Current release level of this implementation. - version*, ## Current version level of this release. + sysname*, ## Name of this implementation of the operating system. + nodename*, ## Name of this node within the communications + ## network to which this node is attached, if any. + release*, ## Current release level of this implementation. + version*, ## Current version level of this release. machine*: array [0..255, char] ## Name of the hardware type on which the - ## system is running. + ## system is running. TSem* {.importc: "sem_t", header: "<semaphore.h>", final, pure.} = object - Tipc_perm* {.importc: "struct ipc_perm", + Tipc_perm* {.importc: "struct ipc_perm", header: "<sys/ipc.h>", final, pure.} = object ## struct ipc_perm - uid*: Tuid ## Owner's user ID. - gid*: TGid ## Owner's group ID. - cuid*: Tuid ## Creator's user ID. - cgid*: TGid ## Creator's group ID. - mode*: TMode ## Read/write permission. - - TStat* {.importc: "struct stat", + uid*: Tuid ## Owner's user ID. + gid*: TGid ## Owner's group ID. + cuid*: Tuid ## Creator's user ID. + cgid*: TGid ## Creator's group ID. + mode*: TMode ## Read/write permission. + + TStat* {.importc: "struct stat", header: "<sys/stat.h>", final, pure.} = object ## struct stat - st_dev*: TDev ## Device ID of device containing file. - st_ino*: Tino ## File serial number. - st_mode*: TMode ## Mode of file (see below). - st_nlink*: TNlink ## Number of hard links to the file. - st_uid*: Tuid ## User ID of file. - st_gid*: TGid ## Group ID of file. - st_rdev*: TDev ## Device ID (if file is character or block special). - st_size*: TOff ## For regular files, the file size in bytes. - ## For symbolic links, the length in bytes of the - ## pathname contained in the symbolic link. - ## For a shared memory object, the length in bytes. - ## For a typed memory object, the length in bytes. - ## For other file types, the use of this field is - ## unspecified. - st_atime*: TTime ## Time of last access. - st_mtime*: TTime ## Time of last data modification. - st_ctime*: TTime ## Time of last status change. - st_blksize*: Tblksize ## A file system-specific preferred I/O block size - ## for this object. In some file system types, this - ## may vary from file to file. - st_blocks*: Tblkcnt ## Number of blocks allocated for this object. - - - TStatvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>", + st_dev*: TDev ## Device ID of device containing file. + st_ino*: Tino ## File serial number. + st_mode*: TMode ## Mode of file (see below). + st_nlink*: TNlink ## Number of hard links to the file. + st_uid*: Tuid ## User ID of file. + st_gid*: TGid ## Group ID of file. + st_rdev*: TDev ## Device ID (if file is character or block special). + st_size*: TOff ## For regular files, the file size in bytes. + ## For symbolic links, the length in bytes of the + ## pathname contained in the symbolic link. + ## For a shared memory object, the length in bytes. + ## For a typed memory object, the length in bytes. + ## For other file types, the use of this field is + ## unspecified. + st_atime*: TTime ## Time of last access. + st_mtime*: TTime ## Time of last data modification. + st_ctime*: TTime ## Time of last status change. + st_blksize*: Tblksize ## A file system-specific preferred I/O block size + ## for this object. In some file system types, this + ## may vary from file to file. + st_blocks*: Tblkcnt ## Number of blocks allocated for this object. + + + TStatvfs* {.importc: "struct statvfs", header: "<sys/statvfs.h>", final, pure.} = object ## struct statvfs - f_bsize*: int ## File system block size. - f_frsize*: int ## Fundamental file system block size. + f_bsize*: int ## File system block size. + f_frsize*: int ## Fundamental file system block size. f_blocks*: Tfsblkcnt ## Total number of blocks on file system - ## in units of f_frsize. - f_bfree*: Tfsblkcnt ## Total number of free blocks. - f_bavail*: Tfsblkcnt ## Number of free blocks available to - ## non-privileged process. - f_files*: Tfsfilcnt ## Total number of file serial numbers. - f_ffree*: Tfsfilcnt ## Total number of free file serial numbers. - f_favail*: Tfsfilcnt ## Number of file serial numbers available to - ## non-privileged process. - f_fsid*: int ## File system ID. - f_flag*: int ## Bit mask of f_flag values. - f_namemax*: int ## Maximum filename length. - - Tposix_typed_mem_info* {.importc: "struct posix_typed_mem_info", + ## in units of f_frsize. + f_bfree*: Tfsblkcnt ## Total number of free blocks. + f_bavail*: Tfsblkcnt ## Number of free blocks available to + ## non-privileged process. + f_files*: Tfsfilcnt ## Total number of file serial numbers. + f_ffree*: Tfsfilcnt ## Total number of free file serial numbers. + f_favail*: Tfsfilcnt ## Number of file serial numbers available to + ## non-privileged process. + f_fsid*: int ## File system ID. + f_flag*: int ## Bit mask of f_flag values. + f_namemax*: int ## Maximum filename length. + + Tposix_typed_mem_info* {.importc: "struct posix_typed_mem_info", header: "<sys/mman.h>", final, pure.} = object posix_tmi_length*: int - - Ttm* {.importc: "struct tm", header: "<time.h>", + + Ttm* {.importc: "struct tm", header: "<time.h>", final, pure.} = object ## struct tm - tm_sec*: cint ## Seconds [0,60]. - tm_min*: cint ## Minutes [0,59]. - tm_hour*: cint ## Hour [0,23]. - tm_mday*: cint ## Day of month [1,31]. - tm_mon*: cint ## Month of year [0,11]. - tm_year*: cint ## Years since 1900. - tm_wday*: cint ## Day of week [0,6] (Sunday =0). - tm_yday*: cint ## Day of year [0,365]. - tm_isdst*: cint ## Daylight Savings flag. - Ttimespec* {.importc: "struct timespec", + tm_sec*: cint ## Seconds [0,60]. + tm_min*: cint ## Minutes [0,59]. + tm_hour*: cint ## Hour [0,23]. + tm_mday*: cint ## Day of month [1,31]. + tm_mon*: cint ## Month of year [0,11]. + tm_year*: cint ## Years since 1900. + tm_wday*: cint ## Day of week [0,6] (Sunday =0). + tm_yday*: cint ## Day of year [0,365]. + tm_isdst*: cint ## Daylight Savings flag. + Ttimespec* {.importc: "struct timespec", header: "<time.h>", final, pure.} = object ## struct timespec - tv_sec*: TTime ## Seconds. - tv_nsec*: int ## Nanoseconds. - titimerspec* {.importc: "struct itimerspec", header: "<time.h>", + tv_sec*: TTime ## Seconds. + tv_nsec*: int ## Nanoseconds. + titimerspec* {.importc: "struct itimerspec", header: "<time.h>", final, pure.} = object ## struct itimerspec - it_interval*: Ttimespec ## Timer period. - it_value*: Ttimespec ## Timer expiration. - + it_interval*: Ttimespec ## Timer period. + it_value*: Ttimespec ## Timer expiration. + Tsig_atomic* {.importc: "sig_atomic_t", header: "<signal.h>".} = cint - ## Possibly volatile-qualified integer type of an object that can be + ## Possibly volatile-qualified integer type of an object that can be ## accessed as an atomic entity, even in the presence of asynchronous ## interrupts. Tsigset* {.importc: "sigset_t", header: "<signal.h>", final, pure.} = object - - TsigEvent* {.importc: "struct sigevent", + + TsigEvent* {.importc: "struct sigevent", header: "<signal.h>", final, pure.} = object ## struct sigevent - sigev_notify*: cint ## Notification type. - sigev_signo*: cint ## Signal number. - sigev_value*: TsigVal ## Signal value. - sigev_notify_function*: proc (x: TsigVal) {.noconv.} ## Notification func. + sigev_notify*: cint ## Notification type. + sigev_signo*: cint ## Signal number. + sigev_value*: TsigVal ## Signal value. + sigev_notify_function*: proc (x: TsigVal) {.noconv.} ## Notification func. sigev_notify_attributes*: ptr Tpthread_attr ## Notification attributes. - TsigVal* {.importc: "union sigval", + TsigVal* {.importc: "union sigval", header: "<signal.h>", final, pure.} = object ## struct sigval - sival_ptr*: pointer ## pointer signal value; + sival_ptr*: pointer ## pointer signal value; ## integer signal value not defined! - TSigaction* {.importc: "struct sigaction", + TSigaction* {.importc: "struct sigaction", header: "<signal.h>", final, pure.} = object ## struct sigaction sa_handler*: proc (x: cint) {.noconv.} ## Pointer to a signal-catching - ## function or one of the macros - ## SIG_IGN or SIG_DFL. - sa_mask*: Tsigset ## Set of signals to be blocked during execution of - ## the signal handling function. - sa_flags*: cint ## Special flags. + ## function or one of the macros + ## SIG_IGN or SIG_DFL. + sa_mask*: Tsigset ## Set of signals to be blocked during execution of + ## the signal handling function. + sa_flags*: cint ## Special flags. sa_sigaction*: proc (x: cint, y: var TsigInfo, z: pointer) {.noconv.} TStack* {.importc: "stack_t", header: "<signal.h>", final, pure.} = object ## stack_t - ss_sp*: pointer ## Stack base or pointer. - ss_size*: int ## Stack size. - ss_flags*: cint ## Flags. + ss_sp*: pointer ## Stack base or pointer. + ss_size*: int ## Stack size. + ss_flags*: cint ## Flags. - TSigStack* {.importc: "struct sigstack", + TSigStack* {.importc: "struct sigstack", header: "<signal.h>", final, pure.} = object ## struct sigstack - ss_onstack*: cint ## Non-zero when signal stack is in use. - ss_sp*: pointer ## Signal stack pointer. + ss_onstack*: cint ## Non-zero when signal stack is in use. + ss_sp*: pointer ## Signal stack pointer. - TsigInfo* {.importc: "siginfo_t", + TsigInfo* {.importc: "siginfo_t", header: "<signal.h>", final, pure.} = object ## siginfo_t - si_signo*: cint ## Signal number. - si_code*: cint ## Signal code. - si_errno*: cint ## If non-zero, an errno value associated with - ## this signal, as defined in <errno.h>. - si_pid*: TPid ## Sending process ID. - si_uid*: Tuid ## Real user ID of sending process. - si_addr*: pointer ## Address of faulting instruction. - si_status*: cint ## Exit value or signal. - si_band*: int ## Band event for SIGPOLL. - si_value*: TsigVal ## Signal value. - + si_signo*: cint ## Signal number. + si_code*: cint ## Signal code. + si_errno*: cint ## If non-zero, an errno value associated with + ## this signal, as defined in <errno.h>. + si_pid*: TPid ## Sending process ID. + si_uid*: Tuid ## Real user ID of sending process. + si_addr*: pointer ## Address of faulting instruction. + si_status*: cint ## Exit value or signal. + si_band*: int ## Band event for SIGPOLL. + si_value*: TsigVal ## Signal value. + Tnl_item* {.importc: "nl_item", header: "<nl_types.h>".} = cint Tnl_catd* {.importc: "nl_catd", header: "<nl_types.h>".} = cint - Tsched_param* {.importc: "struct sched_param", - header: "<sched.h>", + Tsched_param* {.importc: "struct sched_param", + header: "<sched.h>", final, pure.} = object ## struct sched_param sched_priority*: cint - sched_ss_low_priority*: cint ## Low scheduling priority for - ## sporadic server. - sched_ss_repl_period*: Ttimespec ## Replenishment period for - ## sporadic server. - sched_ss_init_budget*: Ttimespec ## Initial budget for sporadic server. - sched_ss_max_repl*: cint ## Maximum pending replenishments for - ## sporadic server. - - Ttimeval* {.importc: "struct timeval", header: "<sys/select.h>", + sched_ss_low_priority*: cint ## Low scheduling priority for + ## sporadic server. + sched_ss_repl_period*: Ttimespec ## Replenishment period for + ## sporadic server. + sched_ss_init_budget*: Ttimespec ## Initial budget for sporadic server. + sched_ss_max_repl*: cint ## Maximum pending replenishments for + ## sporadic server. + + Ttimeval* {.importc: "struct timeval", header: "<sys/select.h>", final, pure.} = object ## struct timeval - tv_sec*: int ## Seconds. - tv_usec*: int ## Microseconds. - TFdSet* {.importc: "fd_set", header: "<sys/select.h>", + tv_sec*: int ## Seconds. + tv_usec*: int ## Microseconds. + TFdSet* {.importc: "fd_set", header: "<sys/select.h>", final, pure.} = object - Tmcontext* {.importc: "mcontext_t", header: "<ucontext.h>", + Tmcontext* {.importc: "mcontext_t", header: "<ucontext.h>", final, pure.} = object - Tucontext* {.importc: "ucontext_t", header: "<ucontext.h>", + Tucontext* {.importc: "ucontext_t", header: "<ucontext.h>", final, pure.} = object ## ucontext_t - uc_link*: ptr Tucontext ## Pointer to the context that is resumed - ## when this context returns. - uc_sigmask*: Tsigset ## The set of signals that are blocked when this - ## context is active. - uc_stack*: TStack ## The stack used by this context. - uc_mcontext*: Tmcontext ## A machine-specific representation of the saved - ## context. + uc_link*: ptr Tucontext ## Pointer to the context that is resumed + ## when this context returns. + uc_sigmask*: Tsigset ## The set of signals that are blocked when this + ## context is active. + uc_stack*: TStack ## The stack used by this context. + uc_mcontext*: Tmcontext ## A machine-specific representation of the saved + ## context. when hasAioH: type - Taiocb* {.importc: "struct aiocb", header: "<aio.h>", + Taiocb* {.importc: "struct aiocb", header: "<aio.h>", final, pure.} = object ## struct aiocb - aio_fildes*: cint ## File descriptor. - aio_offset*: TOff ## File offset. - aio_buf*: pointer ## Location of buffer. - aio_nbytes*: int ## Length of transfer. - aio_reqprio*: cint ## Request priority offset. - aio_sigevent*: TsigEvent ## Signal number and value. - aio_lio_opcode: cint ## Operation to be performed. - + aio_fildes*: cint ## File descriptor. + aio_offset*: TOff ## File offset. + aio_buf*: pointer ## Location of buffer. + aio_nbytes*: int ## Length of transfer. + aio_reqprio*: cint ## Request priority offset. + aio_sigevent*: TsigEvent ## Signal number and value. + aio_lio_opcode: cint ## Operation to be performed. + when hasSpawnH: type - Tposix_spawnattr* {.importc: "posix_spawnattr_t", + Tposix_spawnattr* {.importc: "posix_spawnattr_t", header: "<spawn.h>", final, pure.} = object - Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t", + Tposix_spawn_file_actions* {.importc: "posix_spawn_file_actions_t", header: "<spawn.h>", final, pure.} = object type TSocklen* {.importc: "socklen_t", header: "<sys/socket.h>".} = cuint TSa_Family* {.importc: "sa_family_t", header: "<sys/socket.h>".} = cint - - TSockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>", + + TSockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>", pure, final.} = object ## struct sockaddr - sa_family*: TSa_Family ## Address family. - sa_data*: array [0..255, char] ## Socket address (variable-length data). - + sa_family*: TSa_Family ## Address family. + sa_data*: array [0..255, char] ## Socket address (variable-length data). + Tsockaddr_storage* {.importc: "struct sockaddr_storage", - header: "<sys/socket.h>", + header: "<sys/socket.h>", pure, final.} = object ## struct sockaddr_storage - ss_family*: TSa_Family ## Address family. + ss_family*: TSa_Family ## Address family. - Tif_nameindex* {.importc: "struct if_nameindex", final, + Tif_nameindex* {.importc: "struct if_nameindex", final, pure, header: "<net/if.h>".} = object ## struct if_nameindex - if_index*: cint ## Numeric index of the interface. - if_name*: cstring ## Null-terminated name of the interface. + if_index*: cint ## Numeric index of the interface. + if_name*: cstring ## Null-terminated name of the interface. TIOVec* {.importc: "struct iovec", pure, final, header: "<sys/uio.h>".} = object ## struct iovec - iov_base*: pointer ## Base address of a memory region for input or output. - iov_len*: int ## The size of the memory pointed to by iov_base. - + iov_base*: pointer ## Base address of a memory region for input or output. + iov_len*: int ## The size of the memory pointed to by iov_base. + Tmsghdr* {.importc: "struct msghdr", pure, final, header: "<sys/socket.h>".} = object ## struct msghdr - msg_name*: pointer ## Optional address. - msg_namelen*: TSocklen ## Size of address. - msg_iov*: ptr TIOVec ## Scatter/gather array. - msg_iovlen*: cint ## Members in msg_iov. - msg_control*: pointer ## Ancillary data; see below. - msg_controllen*: TSocklen ## Ancillary data buffer len. - msg_flags*: cint ## Flags on received message. + msg_name*: pointer ## Optional address. + msg_namelen*: TSocklen ## Size of address. + msg_iov*: ptr TIOVec ## Scatter/gather array. + msg_iovlen*: cint ## Members in msg_iov. + msg_control*: pointer ## Ancillary data; see below. + msg_controllen*: TSocklen ## Ancillary data buffer len. + msg_flags*: cint ## Flags on received message. - Tcmsghdr* {.importc: "struct cmsghdr", pure, final, + Tcmsghdr* {.importc: "struct cmsghdr", pure, final, header: "<sys/socket.h>".} = object ## struct cmsghdr - cmsg_len*: TSocklen ## Data byte count, including the cmsghdr. - cmsg_level*: cint ## Originating protocol. - cmsg_type*: cint ## Protocol-specific type. + cmsg_len*: TSocklen ## Data byte count, including the cmsghdr. + cmsg_level*: cint ## Originating protocol. + cmsg_type*: cint ## Protocol-specific type. - TLinger* {.importc: "struct linger", pure, final, + TLinger* {.importc: "struct linger", pure, final, header: "<sys/socket.h>".} = object ## struct linger - l_onoff*: cint ## Indicates whether linger option is enabled. - l_linger*: cint ## Linger time, in seconds. - + l_onoff*: cint ## Indicates whether linger option is enabled. + l_linger*: cint ## Linger time, in seconds. + TInPort* = int16 ## unsigned! TInAddrScalar* = int32 ## unsigned! TInAddrT* {.importc: "in_addr_t", pure, final, header: "<netinet/in.h>".} = int32 ## unsigned! - TInAddr* {.importc: "struct in_addr", pure, final, + TInAddr* {.importc: "struct in_addr", pure, final, header: "<netinet/in.h>".} = object ## struct in_addr s_addr*: TInAddrScalar - Tsockaddr_in* {.importc: "struct sockaddr_in", pure, final, + Tsockaddr_in* {.importc: "struct sockaddr_in", pure, final, header: "<netinet/in.h>".} = object ## struct sockaddr_in - sin_family*: TSa_Family ## AF_INET. - sin_port*: TInPort ## Port number. - sin_addr*: TInAddr ## IP address. + sin_family*: TSa_Family ## AF_INET. + sin_port*: TInPort ## Port number. + sin_addr*: TInAddr ## IP address. TIn6Addr* {.importc: "struct in6_addr", pure, final, header: "<netinet/in.h>".} = object ## struct in6_addr @@ -485,75 +485,75 @@ type Tsockaddr_in6* {.importc: "struct sockaddr_in6", pure, final, header: "<netinet/in.h>".} = object ## struct sockaddr_in6 - sin6_family*: TSa_Family ## AF_INET6. - sin6_port*: TInPort ## Port number. - sin6_flowinfo*: int32 ## IPv6 traffic class and flow information. - sin6_addr*: TIn6Addr ## IPv6 address. - sin6_scope_id*: int32 ## Set of interfaces for a scope. - - Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final, + sin6_family*: TSa_Family ## AF_INET6. + sin6_port*: TInPort ## Port number. + sin6_flowinfo*: int32 ## IPv6 traffic class and flow information. + sin6_addr*: TIn6Addr ## IPv6 address. + sin6_scope_id*: int32 ## Set of interfaces for a scope. + + Tipv6_mreq* {.importc: "struct ipv6_mreq", pure, final, header: "<netinet/in.h>".} = object ## struct ipv6_mreq - ipv6mr_multiaddr*: TIn6Addr ## IPv6 multicast address. - ipv6mr_interface*: cint ## Interface index. + ipv6mr_multiaddr*: TIn6Addr ## IPv6 multicast address. + ipv6mr_interface*: cint ## Interface index. - Thostent* {.importc: "struct hostent", pure, final, + Thostent* {.importc: "struct hostent", pure, final, header: "<netdb.h>".} = object ## struct hostent - h_name*: cstring ## Official name of the host. - h_aliases*: cstringArray ## A pointer to an array of pointers to - ## alternative host names, terminated by a - ## null pointer. - h_addrtype*: cint ## Address type. - h_length*: cint ## The length, in bytes, of the address. - h_addr_list*: cstringArray ## A pointer to an array of pointers to network + h_name*: cstring ## Official name of the host. + h_aliases*: cstringArray ## A pointer to an array of pointers to + ## alternative host names, terminated by a + ## null pointer. + h_addrtype*: cint ## Address type. + h_length*: cint ## The length, in bytes, of the address. + h_addr_list*: cstringArray ## A pointer to an array of pointers to network ## addresses (in network byte order) for the - ## host, terminated by a null pointer. + ## host, terminated by a null pointer. - Tnetent* {.importc: "struct netent", pure, final, + Tnetent* {.importc: "struct netent", pure, final, header: "<netdb.h>".} = object ## struct netent - n_name*: cstring ## Official, fully-qualified (including the - ## domain) name of the host. - n_aliases*: cstringArray ## A pointer to an array of pointers to - ## alternative network names, terminated by a - ## null pointer. - n_addrtype*: cint ## The address type of the network. - n_net*: int32 ## The network number, in host byte order. - - TProtoent* {.importc: "struct protoent", pure, final, + n_name*: cstring ## Official, fully-qualified (including the + ## domain) name of the host. + n_aliases*: cstringArray ## A pointer to an array of pointers to + ## alternative network names, terminated by a + ## null pointer. + n_addrtype*: cint ## The address type of the network. + n_net*: int32 ## The network number, in host byte order. + + TProtoent* {.importc: "struct protoent", pure, final, header: "<netdb.h>".} = object ## struct protoent - p_name*: cstring ## Official name of the protocol. - p_aliases*: cstringArray ## A pointer to an array of pointers to - ## alternative protocol names, terminated by - ## a null pointer. - p_proto*: cint ## The protocol number. + p_name*: cstring ## Official name of the protocol. + p_aliases*: cstringArray ## A pointer to an array of pointers to + ## alternative protocol names, terminated by + ## a null pointer. + p_proto*: cint ## The protocol number. - TServent* {.importc: "struct servent", pure, final, + TServent* {.importc: "struct servent", pure, final, header: "<netdb.h>".} = object ## struct servent - s_name*: cstring ## Official name of the service. - s_aliases*: cstringArray ## A pointer to an array of pointers to - ## alternative service names, terminated by - ## a null pointer. - s_port*: cint ## The port number at which the service - ## resides, in network byte order. - s_proto*: cstring ## The name of the protocol to use when - ## contacting the service. - - Taddrinfo* {.importc: "struct addrinfo", pure, final, + s_name*: cstring ## Official name of the service. + s_aliases*: cstringArray ## A pointer to an array of pointers to + ## alternative service names, terminated by + ## a null pointer. + s_port*: cint ## The port number at which the service + ## resides, in network byte order. + s_proto*: cstring ## The name of the protocol to use when + ## contacting the service. + + Taddrinfo* {.importc: "struct addrinfo", pure, final, header: "<netdb.h>".} = object ## struct addrinfo - ai_flags*: cint ## Input flags. - ai_family*: cint ## Address family of socket. - ai_socktype*: cint ## Socket type. - ai_protocol*: cint ## Protocol of socket. - ai_addrlen*: TSocklen ## Length of socket address. - ai_addr*: ptr TSockAddr ## Socket address of socket. - ai_canonname*: cstring ## Canonical name of service location. - ai_next*: ptr Taddrinfo ## Pointer to next in list. - - TPollfd* {.importc: "struct pollfd", pure, final, + ai_flags*: cint ## Input flags. + ai_family*: cint ## Address family of socket. + ai_socktype*: cint ## Socket type. + ai_protocol*: cint ## Protocol of socket. + ai_addrlen*: TSocklen ## Length of socket address. + ai_addr*: ptr TSockAddr ## Socket address of socket. + ai_canonname*: cstring ## Canonical name of service location. + ai_next*: ptr Taddrinfo ## Pointer to next in list. + + TPollfd* {.importc: "struct pollfd", pure, final, header: "<poll.h>".} = object ## struct pollfd - fd*: cint ## The following descriptor being polled. - events*: cshort ## The input event flags (see below). - revents*: cshort ## The output event flags (see below). - + fd*: cint ## The following descriptor being polled. + events*: cshort ## The input event flags (see below). + revents*: cshort ## The output event flags (see below). + Tnfds* {.importc: "nfds_t", header: "<poll.h>".} = cint var @@ -561,31 +561,31 @@ var h_errno* {.importc, header: "<netdb.h>".}: cint daylight* {.importc, header: "<time.h>".}: cint timezone* {.importc, header: "<time.h>".}: int - + # Constants as variables: when hasAioH: var AIO_ALLDONE* {.importc, header: "<aio.h>".}: cint - ## A return value indicating that none of the requested operations + ## A return value indicating that none of the requested operations ## could be canceled since they are already complete. AIO_CANCELED* {.importc, header: "<aio.h>".}: cint ## A return value indicating that all requested operations have ## been canceled. AIO_NOTCANCELED* {.importc, header: "<aio.h>".}: cint - ## A return value indicating that some of the requested operations could + ## A return value indicating that some of the requested operations could ## not be canceled since they are in progress. LIO_NOP* {.importc, header: "<aio.h>".}: cint ## A lio_listio() element operation option indicating that no transfer is ## requested. LIO_NOWAIT* {.importc, header: "<aio.h>".}: cint - ## A lio_listio() synchronization operation indicating that the calling - ## thread is to continue execution while the lio_listio() operation is + ## A lio_listio() synchronization operation indicating that the calling + ## thread is to continue execution while the lio_listio() operation is ## being performed, and no notification is given when the operation is ## complete. LIO_READ* {.importc, header: "<aio.h>".}: cint ## A lio_listio() element operation option requesting a read. LIO_WAIT* {.importc, header: "<aio.h>".}: cint - ## A lio_listio() synchronization operation indicating that the calling + ## A lio_listio() synchronization operation indicating that the calling ## thread is to suspend until the lio_listio() operation is complete. LIO_WRITE* {.importc, header: "<aio.h>".}: cint ## A lio_listio() element operation option requesting a write. @@ -598,9 +598,9 @@ var RTLD_GLOBAL* {.importc, header: "<dlfcn.h>".}: cint ## All symbols are available for relocation processing of other modules. RTLD_LOCAL* {.importc, header: "<dlfcn.h>".}: cint - ## All symbols are not made available for relocation processing by - ## other modules. - + ## All symbols are not made available for relocation processing by + ## other modules. + E2BIG* {.importc, header: "<errno.h>".}: cint ## Argument list too long. EACCES* {.importc, header: "<errno.h>".}: cint @@ -758,7 +758,7 @@ var EWOULDBLOCK* {.importc, header: "<errno.h>".}: cint ## Operation would block (may be the same value as [EAGAIN]). EXDEV* {.importc, header: "<errno.h>".}: cint - ## Cross-device link. + ## Cross-device link. F_DUPFD* {.importc, header: "<fcntl.h>".}: cint ## Duplicate file descriptor. @@ -779,15 +779,15 @@ var F_GETOWN* {.importc, header: "<fcntl.h>".}: cint ## Get process or process group ID to receive SIGURG signals. F_SETOWN* {.importc, header: "<fcntl.h>".}: cint - ## Set process or process group ID to receive SIGURG signals. + ## Set process or process group ID to receive SIGURG signals. FD_CLOEXEC* {.importc, header: "<fcntl.h>".}: cint - ## Close the file descriptor upon execution of an exec family function. + ## Close the file descriptor upon execution of an exec family function. F_RDLCK* {.importc, header: "<fcntl.h>".}: cint ## Shared or read lock. F_UNLCK* {.importc, header: "<fcntl.h>".}: cint ## Unlock. F_WRLCK* {.importc, header: "<fcntl.h>".}: cint - ## Exclusive or write lock. + ## Exclusive or write lock. O_CREAT* {.importc, header: "<fcntl.h>".}: cint ## Create file if it does not exist. O_EXCL* {.importc, header: "<fcntl.h>".}: cint @@ -795,7 +795,7 @@ var O_NOCTTY* {.importc, header: "<fcntl.h>".}: cint ## Do not assign controlling terminal. O_TRUNC* {.importc, header: "<fcntl.h>".}: cint - ## Truncate flag. + ## Truncate flag. O_APPEND* {.importc, header: "<fcntl.h>".}: cint ## Set append mode. O_DSYNC* {.importc, header: "<fcntl.h>".}: cint @@ -805,21 +805,21 @@ var O_RSYNC* {.importc, header: "<fcntl.h>".}: cint ## Synchronized read I/O operations. O_SYNC* {.importc, header: "<fcntl.h>".}: cint - ## Write according to synchronized I/O file integrity completion. + ## Write according to synchronized I/O file integrity completion. O_ACCMODE* {.importc, header: "<fcntl.h>".}: cint - ## Mask for file access modes. + ## Mask for file access modes. O_RDONLY* {.importc, header: "<fcntl.h>".}: cint ## Open for reading only. O_RDWR* {.importc, header: "<fcntl.h>".}: cint ## Open for reading and writing. O_WRONLY* {.importc, header: "<fcntl.h>".}: cint - ## Open for writing only. + ## Open for writing only. POSIX_FADV_NORMAL* {.importc, header: "<fcntl.h>".}: cint ## The application has no advice to give on its behavior with ## respect to the specified data. It is the default characteristic ## if no advice is given for an open file. POSIX_FADV_SEQUENTIAL* {.importc, header: "<fcntl.h>".}: cint - ## The application expects to access the specified data + ## The application expects to access the specified data # sequentially from lower offsets to higher offsets. POSIX_FADV_RANDOM* {.importc, header: "<fcntl.h>".}: cint ## The application expects to access the specified data in a random order. @@ -829,8 +829,8 @@ var ## The application expects that it will not access the specified data ## in the near future. POSIX_FADV_NOREUSE* {.importc, header: "<fcntl.h>".}: cint - ## The application expects to access the specified data once and - ## then not reuse it thereafter. + ## The application expects to access the specified data once and + ## then not reuse it thereafter. FE_DIVBYZERO* {.importc, header: "<fenv.h>".}: cint FE_INEXACT* {.importc, header: "<fenv.h>".}: cint @@ -875,20 +875,20 @@ when not defined(haiku): MM_PRINT* {.importc, header: "<fmtmsg.h>".}: cint ## Display message on standard error. MM_CONSOLE* {.importc, header: "<fmtmsg.h>".}: cint - ## Display message on system console. + ## Display message on system console. MM_OK* {.importc, header: "<fmtmsg.h>".}: cint ## The function succeeded. MM_NOTOK* {.importc, header: "<fmtmsg.h>".}: cint ## The function failed completely. MM_NOMSG* {.importc, header: "<fmtmsg.h>".}: cint - ## The function was unable to generate a message on standard error, + ## The function was unable to generate a message on standard error, ## but otherwise succeeded. MM_NOCON* {.importc, header: "<fmtmsg.h>".}: cint - ## The function was unable to generate a console message, but - ## otherwise succeeded. + ## The function was unable to generate a console message, but + ## otherwise succeeded. -var +var FNM_NOMATCH* {.importc, header: "<fnmatch.h>".}: cint ## The string does not match the specified pattern. FNM_PATHNAME* {.importc, header: "<fnmatch.h>".}: cint @@ -916,14 +916,14 @@ var ## Symbolic link that names a nonexistent file. FTW_PHYS* {.importc, header: "<ftw.h>".}: cint - ## Physical walk, does not follow symbolic links. Otherwise, nftw() + ## Physical walk, does not follow symbolic links. Otherwise, nftw() ## follows links but does not walk down any path that crosses itself. FTW_MOUNT* {.importc, header: "<ftw.h>".}: cint ## The walk does not cross a mount point. FTW_DEPTH* {.importc, header: "<ftw.h>".}: cint ## All subdirectories are visited before the directory itself. FTW_CHDIR* {.importc, header: "<ftw.h>".}: cint - ## The walk changes to each directory before reading it. + ## The walk changes to each directory before reading it. GLOB_APPEND* {.importc, header: "<glob.h>".}: cint ## Append generated pathnames to those previously obtained. @@ -932,7 +932,7 @@ var GLOB_ERR* {.importc, header: "<glob.h>".}: cint ## Cause glob() to return on error. GLOB_MARK* {.importc, header: "<glob.h>".}: cint - ## Each pathname that is a directory that matches pattern has a + ## Each pathname that is a directory that matches pattern has a ## slash appended. GLOB_NOCHECK* {.importc, header: "<glob.h>".}: cint ## If pattern does not match any pathname, then return a list @@ -942,10 +942,10 @@ var GLOB_NOSORT* {.importc, header: "<glob.h>".}: cint ## Do not sort the pathnames returned. GLOB_ABORTED* {.importc, header: "<glob.h>".}: cint - ## The scan was stopped because GLOB_ERR was set or errfunc() + ## The scan was stopped because GLOB_ERR was set or errfunc() ## returned non-zero. GLOB_NOMATCH* {.importc, header: "<glob.h>".}: cint - ## The pattern does not match any existing pathname, and GLOB_NOCHECK + ## The pattern does not match any existing pathname, and GLOB_NOCHECK ## was not set in flags. GLOB_NOSPACE* {.importc, header: "<glob.h>".}: cint ## An attempt to allocate memory failed. @@ -1033,10 +1033,10 @@ var NOEXPR* {.importc, header: "<langinfo.h>".}: cint ## Negative response expression. CRNCYSTR* {.importc, header: "<langinfo.h>".}: cint - ## Local currency symbol, preceded by '-' if the symbol - ## should appear before the value, '+' if the symbol should appear + ## Local currency symbol, preceded by '-' if the symbol + ## should appear before the value, '+' if the symbol should appear ## after the value, or '.' if the symbol should replace the radix - ## character. If the local currency symbol is the empty string, + ## character. If the local currency symbol is the empty string, ## implementations may return the empty string ( "" ). LC_ALL* {.importc, header: "<locale.h>".}: cint @@ -1046,7 +1046,7 @@ var LC_MONETARY* {.importc, header: "<locale.h>".}: cint LC_NUMERIC* {.importc, header: "<locale.h>".}: cint LC_TIME* {.importc, header: "<locale.h>".}: cint - + PTHREAD_BARRIER_SERIAL_THREAD* {.importc, header: "<pthread.h>".}: cint PTHREAD_CANCEL_ASYNCHRONOUS* {.importc, header: "<pthread.h>".}: cint PTHREAD_CANCEL_ENABLE* {.importc, header: "<pthread.h>".}: cint @@ -1115,7 +1115,7 @@ var PC_ALLOC_SIZE_MIN* {.importc: "_PC_ALLOC_SIZE_MIN", header: "<unistd.h>".}: cint PC_ASYNC_IO* {.importc: "_PC_ASYNC_IO", header: "<unistd.h>".}: cint - PC_CHOWN_RESTRICTED* {.importc: "_PC_CHOWN_RESTRICTED", + PC_CHOWN_RESTRICTED* {.importc: "_PC_CHOWN_RESTRICTED", header: "<unistd.h>".}: cint PC_FILESIZEBITS* {.importc: "_PC_FILESIZEBITS", header: "<unistd.h>".}: cint PC_LINK_MAX* {.importc: "_PC_LINK_MAX", header: "<unistd.h>".}: cint @@ -1127,9 +1127,9 @@ var PC_PATH_MAX*{.importc: "_PC_PATH_MAX", header: "<unistd.h>".}: cint PC_PIPE_BUF*{.importc: "_PC_PIPE_BUF", header: "<unistd.h>".}: cint PC_PRIO_IO*{.importc: "_PC_PRIO_IO", header: "<unistd.h>".}: cint - PC_REC_INCR_XFER_SIZE*{.importc: "_PC_REC_INCR_XFER_SIZE", + PC_REC_INCR_XFER_SIZE*{.importc: "_PC_REC_INCR_XFER_SIZE", header: "<unistd.h>".}: cint - PC_REC_MIN_XFER_SIZE*{.importc: "_PC_REC_MIN_XFER_SIZE", + PC_REC_MIN_XFER_SIZE*{.importc: "_PC_REC_MIN_XFER_SIZE", header: "<unistd.h>".}: cint PC_REC_XFER_ALIGN*{.importc: "_PC_REC_XFER_ALIGN", header: "<unistd.h>".}: cint PC_SYMLINK_MAX*{.importc: "_PC_SYMLINK_MAX", header: "<unistd.h>".}: cint @@ -1142,9 +1142,9 @@ var SC_2_FORT_RUN*{.importc: "_SC_2_FORT_RUN", header: "<unistd.h>".}: cint SC_2_LOCALEDEF*{.importc: "_SC_2_LOCALEDEF", header: "<unistd.h>".}: cint SC_2_PBS*{.importc: "_SC_2_PBS", header: "<unistd.h>".}: cint - SC_2_PBS_ACCOUNTING*{.importc: "_SC_2_PBS_ACCOUNTING", + SC_2_PBS_ACCOUNTING*{.importc: "_SC_2_PBS_ACCOUNTING", header: "<unistd.h>".}: cint - SC_2_PBS_CHECKPOINT*{.importc: "_SC_2_PBS_CHECKPOINT", + SC_2_PBS_CHECKPOINT*{.importc: "_SC_2_PBS_CHECKPOINT", header: "<unistd.h>".}: cint SC_2_PBS_LOCATE*{.importc: "_SC_2_PBS_LOCATE", header: "<unistd.h>".}: cint SC_2_PBS_MESSAGE*{.importc: "_SC_2_PBS_MESSAGE", header: "<unistd.h>".}: cint @@ -1155,10 +1155,10 @@ var SC_ADVISORY_INFO*{.importc: "_SC_ADVISORY_INFO", header: "<unistd.h>".}: cint SC_AIO_LISTIO_MAX*{.importc: "_SC_AIO_LISTIO_MAX", header: "<unistd.h>".}: cint SC_AIO_MAX*{.importc: "_SC_AIO_MAX", header: "<unistd.h>".}: cint - SC_AIO_PRIO_DELTA_MAX*{.importc: "_SC_AIO_PRIO_DELTA_MAX", + SC_AIO_PRIO_DELTA_MAX*{.importc: "_SC_AIO_PRIO_DELTA_MAX", header: "<unistd.h>".}: cint SC_ARG_MAX*{.importc: "_SC_ARG_MAX", header: "<unistd.h>".}: cint - SC_ASYNCHRONOUS_IO*{.importc: "_SC_ASYNCHRONOUS_IO", + SC_ASYNCHRONOUS_IO*{.importc: "_SC_ASYNCHRONOUS_IO", header: "<unistd.h>".}: cint SC_ATEXIT_MAX*{.importc: "_SC_ATEXIT_MAX", header: "<unistd.h>".}: cint SC_BARRIERS*{.importc: "_SC_BARRIERS", header: "<unistd.h>".}: cint @@ -1168,17 +1168,17 @@ var SC_BC_STRING_MAX*{.importc: "_SC_BC_STRING_MAX", header: "<unistd.h>".}: cint SC_CHILD_MAX*{.importc: "_SC_CHILD_MAX", header: "<unistd.h>".}: cint SC_CLK_TCK*{.importc: "_SC_CLK_TCK", header: "<unistd.h>".}: cint - SC_CLOCK_SELECTION*{.importc: "_SC_CLOCK_SELECTION", + SC_CLOCK_SELECTION*{.importc: "_SC_CLOCK_SELECTION", header: "<unistd.h>".}: cint - SC_COLL_WEIGHTS_MAX*{.importc: "_SC_COLL_WEIGHTS_MAX", + SC_COLL_WEIGHTS_MAX*{.importc: "_SC_COLL_WEIGHTS_MAX", header: "<unistd.h>".}: cint SC_CPUTIME*{.importc: "_SC_CPUTIME", header: "<unistd.h>".}: cint SC_DELAYTIMER_MAX*{.importc: "_SC_DELAYTIMER_MAX", header: "<unistd.h>".}: cint SC_EXPR_NEST_MAX*{.importc: "_SC_EXPR_NEST_MAX", header: "<unistd.h>".}: cint SC_FSYNC*{.importc: "_SC_FSYNC", header: "<unistd.h>".}: cint - SC_GETGR_R_SIZE_MAX*{.importc: "_SC_GETGR_R_SIZE_MAX", + SC_GETGR_R_SIZE_MAX*{.importc: "_SC_GETGR_R_SIZE_MAX", header: "<unistd.h>".}: cint - SC_GETPW_R_SIZE_MAX*{.importc: "_SC_GETPW_R_SIZE_MAX", + SC_GETPW_R_SIZE_MAX*{.importc: "_SC_GETPW_R_SIZE_MAX", header: "<unistd.h>".}: cint SC_HOST_NAME_MAX*{.importc: "_SC_HOST_NAME_MAX", header: "<unistd.h>".}: cint SC_IOV_MAX*{.importc: "_SC_IOV_MAX", header: "<unistd.h>".}: cint @@ -1189,11 +1189,11 @@ var SC_MAPPED_FILES*{.importc: "_SC_MAPPED_FILES", header: "<unistd.h>".}: cint SC_MEMLOCK*{.importc: "_SC_MEMLOCK", header: "<unistd.h>".}: cint SC_MEMLOCK_RANGE*{.importc: "_SC_MEMLOCK_RANGE", header: "<unistd.h>".}: cint - SC_MEMORY_PROTECTION*{.importc: "_SC_MEMORY_PROTECTION", + SC_MEMORY_PROTECTION*{.importc: "_SC_MEMORY_PROTECTION", header: "<unistd.h>".}: cint - SC_MESSAGE_PASSING*{.importc: "_SC_MESSAGE_PASSING", + SC_MESSAGE_PASSING*{.importc: "_SC_MESSAGE_PASSING", header: "<unistd.h>".}: cint - SC_MONOTONIC_CLOCK*{.importc: "_SC_MONOTONIC_CLOCK", + SC_MONOTONIC_CLOCK*{.importc: "_SC_MONOTONIC_CLOCK", header: "<unistd.h>".}: cint SC_MQ_OPEN_MAX*{.importc: "_SC_MQ_OPEN_MAX", header: "<unistd.h>".}: cint SC_MQ_PRIO_MAX*{.importc: "_SC_MQ_PRIO_MAX", header: "<unistd.h>".}: cint @@ -1201,13 +1201,13 @@ var SC_OPEN_MAX*{.importc: "_SC_OPEN_MAX", header: "<unistd.h>".}: cint SC_PAGE_SIZE*{.importc: "_SC_PAGE_SIZE", header: "<unistd.h>".}: cint SC_PRIORITIZED_IO*{.importc: "_SC_PRIORITIZED_IO", header: "<unistd.h>".}: cint - SC_PRIORITY_SCHEDULING*{.importc: "_SC_PRIORITY_SCHEDULING", + SC_PRIORITY_SCHEDULING*{.importc: "_SC_PRIORITY_SCHEDULING", header: "<unistd.h>".}: cint SC_RAW_SOCKETS*{.importc: "_SC_RAW_SOCKETS", header: "<unistd.h>".}: cint SC_RE_DUP_MAX*{.importc: "_SC_RE_DUP_MAX", header: "<unistd.h>".}: cint - SC_READER_WRITER_LOCKS*{.importc: "_SC_READER_WRITER_LOCKS", + SC_READER_WRITER_LOCKS*{.importc: "_SC_READER_WRITER_LOCKS", header: "<unistd.h>".}: cint - SC_REALTIME_SIGNALS*{.importc: "_SC_REALTIME_SIGNALS", + SC_REALTIME_SIGNALS*{.importc: "_SC_REALTIME_SIGNALS", header: "<unistd.h>".}: cint SC_REGEXP*{.importc: "_SC_REGEXP", header: "<unistd.h>".}: cint SC_RTSIG_MAX*{.importc: "_SC_RTSIG_MAX", header: "<unistd.h>".}: cint @@ -1215,43 +1215,43 @@ var SC_SEM_NSEMS_MAX*{.importc: "_SC_SEM_NSEMS_MAX", header: "<unistd.h>".}: cint SC_SEM_VALUE_MAX*{.importc: "_SC_SEM_VALUE_MAX", header: "<unistd.h>".}: cint SC_SEMAPHORES*{.importc: "_SC_SEMAPHORES", header: "<unistd.h>".}: cint - SC_SHARED_MEMORY_OBJECTS*{.importc: "_SC_SHARED_MEMORY_OBJECTS", + SC_SHARED_MEMORY_OBJECTS*{.importc: "_SC_SHARED_MEMORY_OBJECTS", header: "<unistd.h>".}: cint SC_SHELL*{.importc: "_SC_SHELL", header: "<unistd.h>".}: cint SC_SIGQUEUE_MAX*{.importc: "_SC_SIGQUEUE_MAX", header: "<unistd.h>".}: cint SC_SPAWN*{.importc: "_SC_SPAWN", header: "<unistd.h>".}: cint SC_SPIN_LOCKS*{.importc: "_SC_SPIN_LOCKS", header: "<unistd.h>".}: cint - SC_SPORADIC_SERVER*{.importc: "_SC_SPORADIC_SERVER", + SC_SPORADIC_SERVER*{.importc: "_SC_SPORADIC_SERVER", header: "<unistd.h>".}: cint SC_SS_REPL_MAX*{.importc: "_SC_SS_REPL_MAX", header: "<unistd.h>".}: cint SC_STREAM_MAX*{.importc: "_SC_STREAM_MAX", header: "<unistd.h>".}: cint SC_SYMLOOP_MAX*{.importc: "_SC_SYMLOOP_MAX", header: "<unistd.h>".}: cint - SC_SYNCHRONIZED_IO*{.importc: "_SC_SYNCHRONIZED_IO", + SC_SYNCHRONIZED_IO*{.importc: "_SC_SYNCHRONIZED_IO", header: "<unistd.h>".}: cint - SC_THREAD_ATTR_STACKADDR*{.importc: "_SC_THREAD_ATTR_STACKADDR", + SC_THREAD_ATTR_STACKADDR*{.importc: "_SC_THREAD_ATTR_STACKADDR", header: "<unistd.h>".}: cint - SC_THREAD_ATTR_STACKSIZE*{.importc: "_SC_THREAD_ATTR_STACKSIZE", + SC_THREAD_ATTR_STACKSIZE*{.importc: "_SC_THREAD_ATTR_STACKSIZE", header: "<unistd.h>".}: cint SC_THREAD_CPUTIME*{.importc: "_SC_THREAD_CPUTIME", header: "<unistd.h>".}: cint SC_THREAD_DESTRUCTOR_ITERATIONS*{.importc: "_SC_THREAD_DESTRUCTOR_ITERATIONS", header: "<unistd.h>".}: cint - SC_THREAD_KEYS_MAX*{.importc: "_SC_THREAD_KEYS_MAX", + SC_THREAD_KEYS_MAX*{.importc: "_SC_THREAD_KEYS_MAX", header: "<unistd.h>".}: cint - SC_THREAD_PRIO_INHERIT*{.importc: "_SC_THREAD_PRIO_INHERIT", + SC_THREAD_PRIO_INHERIT*{.importc: "_SC_THREAD_PRIO_INHERIT", header: "<unistd.h>".}: cint - SC_THREAD_PRIO_PROTECT*{.importc: "_SC_THREAD_PRIO_PROTECT", + SC_THREAD_PRIO_PROTECT*{.importc: "_SC_THREAD_PRIO_PROTECT", header: "<unistd.h>".}: cint SC_THREAD_PRIORITY_SCHEDULING*{.importc: "_SC_THREAD_PRIORITY_SCHEDULING", header: "<unistd.h>".}: cint - SC_THREAD_PROCESS_SHARED*{.importc: "_SC_THREAD_PROCESS_SHARED", + SC_THREAD_PROCESS_SHARED*{.importc: "_SC_THREAD_PROCESS_SHARED", header: "<unistd.h>".}: cint - SC_THREAD_SAFE_FUNCTIONS*{.importc: "_SC_THREAD_SAFE_FUNCTIONS", + SC_THREAD_SAFE_FUNCTIONS*{.importc: "_SC_THREAD_SAFE_FUNCTIONS", header: "<unistd.h>".}: cint - SC_THREAD_SPORADIC_SERVER*{.importc: "_SC_THREAD_SPORADIC_SERVER", + SC_THREAD_SPORADIC_SERVER*{.importc: "_SC_THREAD_SPORADIC_SERVER", header: "<unistd.h>".}: cint - SC_THREAD_STACK_MIN*{.importc: "_SC_THREAD_STACK_MIN", + SC_THREAD_STACK_MIN*{.importc: "_SC_THREAD_STACK_MIN", header: "<unistd.h>".}: cint - SC_THREAD_THREADS_MAX*{.importc: "_SC_THREAD_THREADS_MAX", + SC_THREAD_THREADS_MAX*{.importc: "_SC_THREAD_THREADS_MAX", header: "<unistd.h>".}: cint SC_THREADS*{.importc: "_SC_THREADS", header: "<unistd.h>".}: cint SC_TIMEOUTS*{.importc: "_SC_TIMEOUTS", header: "<unistd.h>".}: cint @@ -1276,21 +1276,21 @@ var SC_XBS5_ILP32_OFF32*{.importc: "_SC_XBS5_ILP32_OFF32", header: "<unistd.h>".}: cint SC_XBS5_ILP32_OFFBIG*{.importc: "_SC_XBS5_ILP32_OFFBIG", header: "<unistd.h>".}: cint SC_XBS5_LP64_OFF64*{.importc: "_SC_XBS5_LP64_OFF64", header: "<unistd.h>".}: cint - SC_XBS5_LPBIG_OFFBIG*{.importc: "_SC_XBS5_LPBIG_OFFBIG", + SC_XBS5_LPBIG_OFFBIG*{.importc: "_SC_XBS5_LPBIG_OFFBIG", header: "<unistd.h>".}: cint SC_XOPEN_CRYPT*{.importc: "_SC_XOPEN_CRYPT", header: "<unistd.h>".}: cint SC_XOPEN_ENH_I18N*{.importc: "_SC_XOPEN_ENH_I18N", header: "<unistd.h>".}: cint SC_XOPEN_LEGACY*{.importc: "_SC_XOPEN_LEGACY", header: "<unistd.h>".}: cint SC_XOPEN_REALTIME*{.importc: "_SC_XOPEN_REALTIME", header: "<unistd.h>".}: cint - SC_XOPEN_REALTIME_THREADS*{.importc: "_SC_XOPEN_REALTIME_THREADS", + SC_XOPEN_REALTIME_THREADS*{.importc: "_SC_XOPEN_REALTIME_THREADS", header: "<unistd.h>".}: cint SC_XOPEN_SHM*{.importc: "_SC_XOPEN_SHM", header: "<unistd.h>".}: cint SC_XOPEN_STREAMS*{.importc: "_SC_XOPEN_STREAMS", header: "<unistd.h>".}: cint SC_XOPEN_UNIX*{.importc: "_SC_XOPEN_UNIX", header: "<unistd.h>".}: cint SC_XOPEN_VERSION*{.importc: "_SC_XOPEN_VERSION", header: "<unistd.h>".}: cint - SC_NPROCESSORS_ONLN*{.importc: "_SC_NPROCESSORS_ONLN", + SC_NPROCESSORS_ONLN*{.importc: "_SC_NPROCESSORS_ONLN", header: "<unistd.h>".}: cint - + SEM_FAILED* {.importc, header: "<semaphore.h>".}: pointer IPC_CREAT* {.importc, header: "<sys/ipc.h>".}: cint ## Create entry if key does not exist. @@ -1307,7 +1307,7 @@ var IPC_SET* {.importc, header: "<sys/ipc.h>".}: cint ## Set options. IPC_STAT* {.importc, header: "<sys/ipc.h>".}: cint - ## Get options. + ## Get options. S_IFMT* {.importc, header: "<sys/stat.h>".}: cint ## Type of file. @@ -1355,12 +1355,12 @@ var ## Set-group-ID on execution. S_ISVTX* {.importc, header: "<sys/stat.h>".}: cint ## On directories, restricted deletion flag. - + ST_RDONLY* {.importc, header: "<sys/statvfs.h>".}: cint ## Read-only file system. ST_NOSUID* {.importc, header: "<sys/statvfs.h>".}: cint ## Does not support the semantics of the ST_ISUID and ST_ISGID file mode bits. - + PROT_READ* {.importc, header: "<sys/mman.h>".}: cint ## Page can be read. PROT_WRITE* {.importc, header: "<sys/mman.h>".}: cint @@ -1387,8 +1387,8 @@ var ## Lock pages that become mapped. MAP_FAILED* {.importc, header: "<sys/mman.h>".}: cint POSIX_MADV_NORMAL* {.importc, header: "<sys/mman.h>".}: cint - ## The application has no advice to give on its behavior with - ## respect to the specified range. It is the default characteristic + ## The application has no advice to give on its behavior with + ## respect to the specified range. It is the default characteristic ## if no advice is given for a range of memory. POSIX_MADV_SEQUENTIAL* {.importc, header: "<sys/mman.h>".}: cint ## The application expects to access the specified range sequentially @@ -1407,13 +1407,13 @@ var ## A number used to convert the value returned by the clock() function ## into seconds. CLOCK_PROCESS_CPUTIME_ID* {.importc, header: "<time.h>".}: cint - ## The identifier of the CPU-time clock associated with the process + ## The identifier of the CPU-time clock associated with the process ## making a clock() or timer*() function call. CLOCK_THREAD_CPUTIME_ID* {.importc, header: "<time.h>".}: cint CLOCK_REALTIME* {.importc, header: "<time.h>".}: cint ## The identifier of the system-wide realtime clock. TIMER_ABSTIME* {.importc, header: "<time.h>".}: cint - ## Flag indicating time is absolute. For functions taking timer + ## Flag indicating time is absolute. For functions taking timer ## objects, this refers to the clock associated with the timer. CLOCK_MONOTONIC* {.importc, header: "<time.h>".}: cint @@ -1438,25 +1438,25 @@ var WEXITED* {.importc, header: "<sys/wait.h>".}: cint ## Wait for processes that have exited. WSTOPPED* {.importc, header: "<sys/wait.h>".}: cint - ## Status is returned for any child that has stopped upon receipt + ## Status is returned for any child that has stopped upon receipt ## of a signal. WCONTINUED* {.importc, header: "<sys/wait.h>".}: cint ## Status is returned for any child that was stopped and has been continued. WNOWAIT* {.importc, header: "<sys/wait.h>".}: cint - ## Keep the process whose status is returned in infop in a waitable state. - P_ALL* {.importc, header: "<sys/wait.h>".}: cint - P_PID* {.importc, header: "<sys/wait.h>".}: cint + ## Keep the process whose status is returned in infop in a waitable state. + P_ALL* {.importc, header: "<sys/wait.h>".}: cint + P_PID* {.importc, header: "<sys/wait.h>".}: cint P_PGID* {.importc, header: "<sys/wait.h>".}: cint - + SIG_DFL* {.importc, header: "<signal.h>".}: proc (x: cint) {.noconv.} ## Request for default signal handling. SIG_ERR* {.importc, header: "<signal.h>".}: proc (x: cint) {.noconv.} ## Return value from signal() in case of error. - cSIG_HOLD* {.importc: "SIG_HOLD", + cSIG_HOLD* {.importc: "SIG_HOLD", header: "<signal.h>".}: proc (x: cint) {.noconv.} ## Request that signal be held. SIG_IGN* {.importc, header: "<signal.h>".}: proc (x: cint) {.noconv.} - ## Request that signal be ignored. + ## Request that signal be ignored. SIGEV_NONE* {.importc, header: "<signal.h>".}: cint SIGEV_SIGNAL* {.importc, header: "<signal.h>".}: cint @@ -1518,8 +1518,8 @@ var SEEK_END* {.importc, header: "<unistd.h>".}: cint SCM_RIGHTS* {.importc, header: "<sys/socket.h>".}: cint - ## Indicates that the data array contains the access rights - ## to be sent or received. + ## Indicates that the data array contains the access rights + ## to be sent or received. SOCK_DGRAM* {.importc, header: "<sys/socket.h>".}: cint ## Datagram socket. SOCK_RAW* {.importc, header: "<sys/socket.h>".}: cint @@ -1527,11 +1527,11 @@ var SOCK_SEQPACKET* {.importc, header: "<sys/socket.h>".}: cint ## Sequenced-packet socket. SOCK_STREAM* {.importc, header: "<sys/socket.h>".}: cint - ## Byte-stream socket. - + ## Byte-stream socket. + SOL_SOCKET* {.importc, header: "<sys/socket.h>".}: cint - ## Options to be accessed at socket level, not protocol level. - + ## Options to be accessed at socket level, not protocol level. + SO_ACCEPTCONN* {.importc, header: "<sys/socket.h>".}: cint ## Socket is accepting connections. SO_BROADCAST* {.importc, header: "<sys/socket.h>".}: cint @@ -1563,11 +1563,11 @@ var SO_SNDTIMEO* {.importc, header: "<sys/socket.h>".}: cint ## Send timeout. SO_TYPE* {.importc, header: "<sys/socket.h>".}: cint - ## Socket type. - + ## Socket type. + SOMAXCONN* {.importc, header: "<sys/socket.h>".}: cint - ## The maximum backlog queue length. - + ## The maximum backlog queue length. + MSG_CTRUNC* {.importc, header: "<sys/socket.h>".}: cint ## Control data truncated. MSG_DONTROUTE* {.importc, header: "<sys/socket.h>".}: cint @@ -1583,7 +1583,7 @@ var MSG_TRUNC* {.importc, header: "<sys/socket.h>".}: cint ## Normal data truncated. MSG_WAITALL* {.importc, header: "<sys/socket.h>".}: cint - ## Attempt to fill the read buffer. + ## Attempt to fill the read buffer. AF_INET* {.importc, header: "<sys/socket.h>".}: cint ## Internet domain sockets for use with IPv4 addresses. @@ -1592,17 +1592,17 @@ var AF_UNIX* {.importc, header: "<sys/socket.h>".}: cint ## UNIX domain sockets. AF_UNSPEC* {.importc, header: "<sys/socket.h>".}: cint - ## Unspecified. + ## Unspecified. SHUT_RD* {.importc, header: "<sys/socket.h>".}: cint ## Disables further receive operations. SHUT_RDWR* {.importc, header: "<sys/socket.h>".}: cint ## Disables further send and receive operations. SHUT_WR* {.importc, header: "<sys/socket.h>".}: cint - ## Disables further send operations. + ## Disables further send operations. IF_NAMESIZE* {.importc, header: "<net/if.h>".}: cint - + IPPROTO_IP* {.importc, header: "<netinet/in.h>".}: cint ## Internet protocol. IPPROTO_IPV6* {.importc, header: "<netinet/in.h>".}: cint @@ -1610,7 +1610,7 @@ var IPPROTO_ICMP* {.importc, header: "<netinet/in.h>".}: cint ## Control message protocol. IPPROTO_RAW* {.importc, header: "<netinet/in.h>".}: cint - ## Raw IP Packets Protocol. + ## Raw IP Packets Protocol. IPPROTO_TCP* {.importc, header: "<netinet/in.h>".}: cint ## Transmission control protocol. IPPROTO_UDP* {.importc, header: "<netinet/in.h>".}: cint @@ -1622,7 +1622,7 @@ var ## IPv4 broadcast address. INET_ADDRSTRLEN* {.importc, header: "<netinet/in.h>".}: cint - ## 16. Length of the string form for IP. + ## 16. Length of the string form for IP. IPV6_JOIN_GROUP* {.importc, header: "<netinet/in.h>".}: cint ## Join a multicast group. @@ -1640,68 +1640,68 @@ var ## Restrict AF_INET6 socket to IPv6 communications only. TCP_NODELAY* {.importc, header: "<netinet/tcp.h>".}: cint - ## Avoid coalescing of small segments. + ## Avoid coalescing of small segments. - IPPORT_RESERVED* {.importc, header: "<netdb.h>".}: cint + IPPORT_RESERVED* {.importc, header: "<netdb.h>".}: cint - HOST_NOT_FOUND* {.importc, header: "<netdb.h>".}: cint - NO_DATA* {.importc, header: "<netdb.h>".}: cint - NO_RECOVERY* {.importc, header: "<netdb.h>".}: cint - TRY_AGAIN* {.importc, header: "<netdb.h>".}: cint + HOST_NOT_FOUND* {.importc, header: "<netdb.h>".}: cint + NO_DATA* {.importc, header: "<netdb.h>".}: cint + NO_RECOVERY* {.importc, header: "<netdb.h>".}: cint + TRY_AGAIN* {.importc, header: "<netdb.h>".}: cint - AI_PASSIVE* {.importc, header: "<netdb.h>".}: cint + AI_PASSIVE* {.importc, header: "<netdb.h>".}: cint ## Socket address is intended for bind(). - AI_CANONNAME* {.importc, header: "<netdb.h>".}: cint + AI_CANONNAME* {.importc, header: "<netdb.h>".}: cint ## Request for canonical name. - AI_NUMERICHOST* {.importc, header: "<netdb.h>".}: cint + AI_NUMERICHOST* {.importc, header: "<netdb.h>".}: cint ## Return numeric host address as name. - AI_NUMERICSERV* {.importc, header: "<netdb.h>".}: cint + AI_NUMERICSERV* {.importc, header: "<netdb.h>".}: cint ## Inhibit service name resolution. - AI_V4MAPPED* {.importc, header: "<netdb.h>".}: cint + AI_V4MAPPED* {.importc, header: "<netdb.h>".}: cint ## If no IPv6 addresses are found, query for IPv4 addresses and ## return them to the caller as IPv4-mapped IPv6 addresses. - AI_ALL* {.importc, header: "<netdb.h>".}: cint + AI_ALL* {.importc, header: "<netdb.h>".}: cint ## Query for both IPv4 and IPv6 addresses. - AI_ADDRCONFIG* {.importc, header: "<netdb.h>".}: cint - ## Query for IPv4 addresses only when an IPv4 address is configured; + AI_ADDRCONFIG* {.importc, header: "<netdb.h>".}: cint + ## Query for IPv4 addresses only when an IPv4 address is configured; ## query for IPv6 addresses only when an IPv6 address is configured. - NI_NOFQDN* {.importc, header: "<netdb.h>".}: cint + NI_NOFQDN* {.importc, header: "<netdb.h>".}: cint ## Only the nodename portion of the FQDN is returned for local hosts. - NI_NUMERICHOST* {.importc, header: "<netdb.h>".}: cint + NI_NUMERICHOST* {.importc, header: "<netdb.h>".}: cint ## The numeric form of the node's address is returned instead of its name. - NI_NAMEREQD* {.importc, header: "<netdb.h>".}: cint + NI_NAMEREQD* {.importc, header: "<netdb.h>".}: cint ## Return an error if the node's name cannot be located in the database. - NI_NUMERICSERV* {.importc, header: "<netdb.h>".}: cint + NI_NUMERICSERV* {.importc, header: "<netdb.h>".}: cint ## The numeric form of the service address is returned instead of its name. - NI_NUMERICSCOPE* {.importc, header: "<netdb.h>".}: cint + NI_NUMERICSCOPE* {.importc, header: "<netdb.h>".}: cint ## For IPv6 addresses, the numeric form of the scope identifier is ## returned instead of its name. - NI_DGRAM* {.importc, header: "<netdb.h>".}: cint - ## Indicates that the service is a datagram service (SOCK_DGRAM). + NI_DGRAM* {.importc, header: "<netdb.h>".}: cint + ## Indicates that the service is a datagram service (SOCK_DGRAM). - EAI_AGAIN* {.importc, header: "<netdb.h>".}: cint + EAI_AGAIN* {.importc, header: "<netdb.h>".}: cint ## The name could not be resolved at this time. Future attempts may succeed. - EAI_BADFLAGS* {.importc, header: "<netdb.h>".}: cint + EAI_BADFLAGS* {.importc, header: "<netdb.h>".}: cint ## The flags had an invalid value. - EAI_FAIL* {.importc, header: "<netdb.h>".}: cint + EAI_FAIL* {.importc, header: "<netdb.h>".}: cint ## A non-recoverable error occurred. - EAI_FAMILY* {.importc, header: "<netdb.h>".}: cint - ## The address family was not recognized or the address length + EAI_FAMILY* {.importc, header: "<netdb.h>".}: cint + ## The address family was not recognized or the address length ## was invalid for the specified family. - EAI_MEMORY* {.importc, header: "<netdb.h>".}: cint + EAI_MEMORY* {.importc, header: "<netdb.h>".}: cint ## There was a memory allocation failure. - EAI_NONAME* {.importc, header: "<netdb.h>".}: cint + EAI_NONAME* {.importc, header: "<netdb.h>".}: cint ## The name does not resolve for the supplied parameters. - ## NI_NAMEREQD is set and the host's name cannot be located, + ## NI_NAMEREQD is set and the host's name cannot be located, ## or both nodename and servname were null. - EAI_SERVICE* {.importc, header: "<netdb.h>".}: cint + EAI_SERVICE* {.importc, header: "<netdb.h>".}: cint ## The service passed was not recognized for the specified socket type. - EAI_SOCKTYPE* {.importc, header: "<netdb.h>".}: cint + EAI_SOCKTYPE* {.importc, header: "<netdb.h>".}: cint ## The intended socket type was not recognized. - EAI_SYSTEM* {.importc, header: "<netdb.h>".}: cint + EAI_SYSTEM* {.importc, header: "<netdb.h>".}: cint ## A system error occurred. The error code can be found in errno. - EAI_OVERFLOW* {.importc, header: "<netdb.h>".}: cint + EAI_OVERFLOW* {.importc, header: "<netdb.h>".}: cint ## An argument buffer overflowed. POLLIN* {.importc, header: "<poll.h>".}: cshort @@ -1723,7 +1723,7 @@ var POLLHUP* {.importc, header: "<poll.h>".}: cshort ## Device has been disconnected (revents only). POLLNVAL* {.importc, header: "<poll.h>".}: cshort - ## Invalid fd member (revents only). + ## Invalid fd member (revents only). when hasSpawnH: @@ -1743,7 +1743,7 @@ when hasSpawnH: # macosx lacks this, so we define the constant to be 0 to not affect # OR'ing of flags: const POSIX_SPAWN_USEVFORK* = cint(0) - + when hasAioH: proc aio_cancel*(a1: cint, a2: ptr Taiocb): cint {.importc, header: "<aio.h>".} proc aio_error*(a1: ptr Taiocb): cint {.importc, header: "<aio.h>".} @@ -1817,13 +1817,13 @@ proc feupdateenv*(a1: ptr Tfenv): cint {.importc, header: "<fenv.h>".} when not defined(haiku): proc fmtmsg*(a1: int, a2: cstring, a3: cint, a4, a5, a6: cstring): cint {.importc, header: "<fmtmsg.h>".} - + proc fnmatch*(a1, a2: cstring, a3: cint): cint {.importc, header: "<fnmatch.h>".} -proc ftw*(a1: cstring, +proc ftw*(a1: cstring, a2: proc (x1: cstring, x2: ptr TStat, x3: cint): cint {.noconv.}, a3: cint): cint {.importc, header: "<ftw.h>".} -proc nftw*(a1: cstring, - a2: proc (x1: cstring, x2: ptr TStat, +proc nftw*(a1: cstring, + a2: proc (x1: cstring, x2: ptr TStat, x3: cint, x4: ptr TFTW): cint {.noconv.}, a3: cint, a4: cint): cint {.importc, header: "<ftw.h>".} @@ -1837,7 +1837,7 @@ proc getgrgid*(a1: TGid): ptr TGroup {.importc, header: "<grp.h>".} proc getgrnam*(a1: cstring): ptr TGroup {.importc, header: "<grp.h>".} proc getgrgid_r*(a1: TGid, a2: ptr TGroup, a3: cstring, a4: int, a5: ptr ptr TGroup): cint {.importc, header: "<grp.h>".} -proc getgrnam_r*(a1: cstring, a2: ptr TGroup, a3: cstring, +proc getgrnam_r*(a1: cstring, a2: ptr TGroup, a3: cstring, a4: int, a5: ptr ptr TGroup): cint {. importc, header: "<grp.h>".} proc getgrent*(): ptr TGroup {.importc, header: "<grp.h>".} @@ -1876,9 +1876,9 @@ proc mq_send*(a1: TMqd, a2: cstring, a3: int, a4: int): cint {. proc mq_setattr*(a1: TMqd, a2, a3: ptr TMqAttr): cint {. importc, header: "<mqueue.h>".} -proc mq_timedreceive*(a1: TMqd, a2: cstring, a3: int, a4: int, +proc mq_timedreceive*(a1: TMqd, a2: cstring, a3: int, a4: int, a5: ptr Ttimespec): int {.importc, header: "<mqueue.h>".} -proc mq_timedsend*(a1: TMqd, a2: cstring, a3: int, a4: int, +proc mq_timedsend*(a1: TMqd, a2: cstring, a3: int, a4: int, a5: ptr Ttimespec): cint {.importc, header: "<mqueue.h>".} proc mq_unlink*(a1: cstring): cint {.importc, header: "<mqueue.h>".} @@ -1951,7 +1951,7 @@ proc pthread_barrierattr_getpshared*( importc, header: "<pthread.h>".} proc pthread_barrierattr_init*(a1: ptr Tpthread_barrierattr): cint {. importc, header: "<pthread.h>".} -proc pthread_barrierattr_setpshared*(a1: ptr Tpthread_barrierattr, +proc pthread_barrierattr_setpshared*(a1: ptr Tpthread_barrierattr, a2: cint): cint {.importc, header: "<pthread.h>".} proc pthread_cancel*(a1: Tpthread): cint {.importc, header: "<pthread.h>".} proc pthread_cleanup_push*(a1: proc (x: pointer) {.noconv.}, a2: pointer) {. @@ -1973,7 +1973,7 @@ proc pthread_condattr_getclock*(a1: ptr Tpthread_condattr, a2: var TClockId): cint {.importc, header: "<pthread.h>".} proc pthread_condattr_getpshared*(a1: ptr Tpthread_condattr, a2: var cint): cint {.importc, header: "<pthread.h>".} - + proc pthread_condattr_init*(a1: ptr Tpthread_condattr): cint {.importc, header: "<pthread.h>".} proc pthread_condattr_setclock*(a1: ptr Tpthread_condattr,a2: TClockId): cint {.importc, header: "<pthread.h>".} proc pthread_condattr_setpshared*(a1: ptr Tpthread_condattr, a2: cint): cint {.importc, header: "<pthread.h>".} @@ -2085,6 +2085,7 @@ proc execv*(a1: cstring, a2: cstringArray): cint {.importc, header: "<unistd.h>" proc execve*(a1: cstring, a2, a3: cstringArray): cint {. importc, header: "<unistd.h>".} proc execvp*(a1: cstring, a2: cstringArray): cint {.importc, header: "<unistd.h>".} +proc execvpe*(a1: cstring, a2: cstringArray, a3: cstringArray): cint {.importc, header: "<unistd.h>".} proc fchown*(a1: cint, a2: Tuid, a3: TGid): cint {.importc, header: "<unistd.h>".} proc fchdir*(a1: cint): cint {.importc, header: "<unistd.h>".} proc fdatasync*(a1: cint): cint {.importc, header: "<unistd.h>".} @@ -2205,18 +2206,18 @@ proc S_ISREG*(m: TMode): bool {.importc, header: "<sys/stat.h>".} proc S_ISLNK*(m: TMode): bool {.importc, header: "<sys/stat.h>".} ## Test for a symbolic link. proc S_ISSOCK*(m: TMode): bool {.importc, header: "<sys/stat.h>".} - ## Test for a socket. - + ## Test for a socket. + proc S_TYPEISMQ*(buf: var TStat): bool {.importc, header: "<sys/stat.h>".} ## Test for a message queue. proc S_TYPEISSEM*(buf: var TStat): bool {.importc, header: "<sys/stat.h>".} ## Test for a semaphore. proc S_TYPEISSHM*(buf: var TStat): bool {.importc, header: "<sys/stat.h>".} - ## Test for a shared memory object. - + ## Test for a shared memory object. + proc S_TYPEISTMO*(buf: var TStat): bool {.importc, header: "<sys/stat.h>".} - ## Test macro for a typed memory object. - + ## Test macro for a typed memory object. + proc mlock*(a1: pointer, a2: int): cint {.importc, header: "<sys/mman.h>".} proc mlockall*(a1: cint): cint {.importc, header: "<sys/mman.h>".} proc mmap*(a1: pointer, a2: int, a3, a4, a5: cint, a6: TOff): pointer {. @@ -2231,7 +2232,7 @@ proc posix_madvise*(a1: pointer, a2: int, a3: cint): cint {. importc, header: "<sys/mman.h>".} proc posix_mem_offset*(a1: pointer, a2: int, a3: var TOff, a4: var int, a5: var cint): cint {.importc, header: "<sys/mman.h>".} -proc posix_typed_mem_get_info*(a1: cint, +proc posix_typed_mem_get_info*(a1: cint, a2: var Tposix_typed_mem_info): cint {.importc, header: "<sys/mman.h>".} proc posix_typed_mem_open*(a1: cstring, a2, a3: cint): cint {. importc, header: "<sys/mman.h>".} @@ -2317,7 +2318,7 @@ proc sigrelse*(a1: cint): cint {.importc, header: "<signal.h>".} proc sigset*(a1: int, a2: proc (x: cint) {.noconv.}) {. importc, header: "<signal.h>".} proc sigsuspend*(a1: var Tsigset): cint {.importc, header: "<signal.h>".} -proc sigtimedwait*(a1: var Tsigset, a2: var TsigInfo, +proc sigtimedwait*(a1: var Tsigset, a2: var TsigInfo, a3: var Ttimespec): cint {.importc, header: "<signal.h>".} proc sigwait*(a1: var Tsigset, a2: var cint): cint {. importc, header: "<signal.h>".} @@ -2361,7 +2362,7 @@ proc select*(a1: cint, a2, a3, a4: ptr TFdSet, a5: ptr Ttimeval): cint {. when hasSpawnH: proc posix_spawn*(a1: var TPid, a2: cstring, a3: var Tposix_spawn_file_actions, - a4: var Tposix_spawnattr, + a4: var Tposix_spawnattr, a5, a6: cstringArray): cint {.importc, header: "<spawn.h>".} proc posix_spawn_file_actions_addclose*(a1: var Tposix_spawn_file_actions, a2: cint): cint {.importc, header: "<spawn.h>".} @@ -2388,7 +2389,7 @@ when hasSpawnH: a2: var cint): cint {.importc, header: "<spawn.h>".} proc posix_spawnattr_getsigmask*(a1: var Tposix_spawnattr, a2: var Tsigset): cint {.importc, header: "<spawn.h>".} - + proc posix_spawnattr_init*(a1: var Tposix_spawnattr): cint {. importc, header: "<spawn.h>".} proc posix_spawnattr_setsigdefault*(a1: var Tposix_spawnattr, @@ -2397,10 +2398,10 @@ when hasSpawnH: importc, header: "<spawn.h>".} proc posix_spawnattr_setpgroup*(a1: var Tposix_spawnattr, a2: TPid): cint {. importc, header: "<spawn.h>".} - + proc posix_spawnattr_setschedparam*(a1: var Tposix_spawnattr, a2: var Tsched_param): cint {.importc, header: "<spawn.h>".} - proc posix_spawnattr_setschedpolicy*(a1: var Tposix_spawnattr, + proc posix_spawnattr_setschedpolicy*(a1: var Tposix_spawnattr, a2: cint): cint {. importc, header: "<spawn.h>".} proc posix_spawnattr_setsigmask*(a1: var Tposix_spawnattr, @@ -2441,7 +2442,7 @@ proc accept*(a1: TSocketHandle, a2: ptr TSockAddr, a3: ptr TSocklen): TSocketHan proc bindSocket*(a1: TSocketHandle, a2: ptr TSockAddr, a3: TSocklen): cint {. importc: "bind", header: "<sys/socket.h>".} ## is Posix's ``bind``, because ``bind`` is a reserved word - + proc connect*(a1: TSocketHandle, a2: ptr TSockAddr, a3: TSocklen): cint {. importc, header: "<sys/socket.h>".} proc getpeername*(a1: TSocketHandle, a2: ptr TSockAddr, a3: ptr TSocklen): cint {. @@ -2530,9 +2531,9 @@ proc freeaddrinfo*(a1: ptr Taddrinfo) {.importc, header: "<netdb.h>".} proc gai_strerror*(a1: cint): cstring {.importc, header: "<netdb.h>".} -proc getaddrinfo*(a1, a2: cstring, a3: ptr Taddrinfo, +proc getaddrinfo*(a1, a2: cstring, a3: ptr Taddrinfo, a4: var ptr Taddrinfo): cint {.importc, header: "<netdb.h>".} - + proc gethostbyaddr*(a1: pointer, a2: TSocklen, a3: cint): ptr Thostent {. importc, header: "<netdb.h>".} proc gethostbyname*(a1: cstring): ptr Thostent {.importc, header: "<netdb.h>".} @@ -2565,5 +2566,3 @@ proc poll*(a1: ptr TPollfd, a2: Tnfds, a3: int): cint {. proc realpath*(name, resolved: cstring): cstring {. importc: "realpath", header: "<stdlib.h>".} - - diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 676707abb..c7678b214 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -13,7 +13,7 @@ include "system/inclrtl" import - strutils, os, strtabs, streams + strutils, os, strtabs, streams, sequtils when defined(windows): import winlean @@ -36,11 +36,17 @@ type TProcessOption* = enum ## options that can be passed `startProcess` poEchoCmd, ## echo the command before execution - poUseShell, ## use the shell to execute the command; NOTE: This - ## often creates a security hole! + poUsePath, ## Asks system to search for executable using PATH environment + ## variable. + ## On Windows, this is the default. + poEvalCommand, ## Pass `command` directly to the shell, without quoting. + ## Use it only if `command` comes from trused source. poStdErrToStdOut, ## merge stdout and stderr to the stdout stream poParentStreams ## use the parent's streams +template poUseShell*: TProcessOption {.deprecated.} = poUsePath + ## Deprecated alias for poUsePath. + proc quoteShellWindows*(s: string): string {.noSideEffect, rtl, extern: "nosp$1".} = ## Quote s, so it can be safely passed to Windows API. ## Based on Python's subprocess.list2cmdline @@ -94,12 +100,17 @@ proc quoteShell*(s: string): string {.noSideEffect, rtl, extern: "nosp$1".} = {.error:"quoteShell is not supported on your system".} proc execProcess*(command: string, + args: openarray[string] = [], + env: PStringTable = nil, options: set[TProcessOption] = {poStdErrToStdOut, - poUseShell}): TaintedString {. + poUsePath, + poEvalCommand}): TaintedString {. rtl, extern: "nosp$1", tags: [FExecIO, FReadIO].} ## A convenience procedure that executes ``command`` with ``startProcess`` ## and returns its output as a string. + ## WARNING: this function uses poEvalCommand by default for backward compatibility. + ## Make sure to pass options explicitly. proc execCmd*(command: string): int {.rtl, extern: "nosp$1", tags: [FExecIO].} ## Executes ``command`` and returns its error code. Standard input, output, @@ -109,8 +120,8 @@ proc execCmd*(command: string): int {.rtl, extern: "nosp$1", tags: [FExecIO].} proc startProcess*(command: string, workingDir: string = "", args: openArray[string] = [], - env: PStringTable = nil, - options: set[TProcessOption] = {poStdErrToStdOut}): + env: PStringTable = nil, + options: set[TProcessOption] = {poStdErrToStdOut}): PProcess {.rtl, extern: "nosp$1", tags: [FExecIO, FReadEnv].} ## Starts a process. `Command` is the executable file, `workingDir` is the ## process's working directory. If ``workingDir == ""`` the current directory @@ -127,16 +138,10 @@ proc startProcess*(command: string, ## but ``EOS`` is raised in case of an error. proc startCmd*(command: string, options: set[TProcessOption] = { - poStdErrToStdOut, poUseShell}): PProcess {. - tags: [FExecIO, FReadEnv].} = - ## a simpler version of `startProcess` that parses the command line into - ## program and arguments and then calls `startProcess` with the empty string - ## for `workingDir` and the nil string table for `env`. - var c = parseCmdLine(command) - var a: seq[string] - newSeq(a, c.len-1) # avoid slicing for now (still unstable) - for i in 1 .. c.len-1: a[i-1] = c[i] - result = startProcess(command=c[0], args=a, options=options) + poStdErrToStdOut, poUsePath}): PProcess {. + tags: [FExecIO, FReadEnv], deprecated.} = + ## Deprecated - use `startProcess` directly. + result = startProcess(command=command, options=options + {poEvalCommand}) proc close*(p: PProcess) {.rtl, extern: "nosp$1", tags: [].} ## When the process has finished executing, cleanup related handles @@ -157,7 +162,7 @@ proc processID*(p: PProcess): int {.rtl, extern: "nosp$1".} = ## returns `p`'s process ID. return p.id -proc waitForExit*(p: PProcess, timeout: int = -1): int {.rtl, +proc waitForExit*(p: PProcess, timeout: int = -1): int {.rtl, extern: "nosp$1", tags: [].} ## waits for the process to finish and returns `p`'s error code. @@ -167,19 +172,19 @@ proc peekExitCode*(p: PProcess): int {.tags: [].} proc inputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].} ## returns ``p``'s input stream for writing to. ## - ## **Warning**: The returned `PStream` should not be closed manually as it + ## **Warning**: The returned `PStream` should not be closed manually as it ## is closed when closing the PProcess ``p``. proc outputStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].} ## returns ``p``'s output stream for reading from. ## - ## **Warning**: The returned `PStream` should not be closed manually as it + ## **Warning**: The returned `PStream` should not be closed manually as it ## is closed when closing the PProcess ``p``. proc errorStream*(p: PProcess): PStream {.rtl, extern: "nosp$1", tags: [].} ## returns ``p``'s error stream for reading from. ## - ## **Warning**: The returned `PStream` should not be closed manually as it + ## **Warning**: The returned `PStream` should not be closed manually as it ## is closed when closing the PProcess ``p``. proc inputHandle*(p: PProcess): TFileHandle {.rtl, extern: "nosp$1", @@ -245,15 +250,15 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} = proc execProcesses*(cmds: openArray[string], options = {poStdErrToStdOut, poParentStreams}, - n = countProcessors()): int {.rtl, extern: "nosp$1", - tags: [FExecIO, FTime, FReadEnv].} = + n = countProcessors()): int {.rtl, extern: "nosp$1", + tags: [FExecIO, FTime, FReadEnv]} = ## executes the commands `cmds` in parallel. Creates `n` processes ## that execute in parallel. The highest return value of all processes ## is returned. when defined(posix): # poParentStreams causes problems on Posix, so we simply disable it: var options = options - {poParentStreams} - + assert n > 0 if n > 1: var q: seq[PProcess] @@ -307,13 +312,17 @@ proc select*(readfds: var seq[PProcess], timeout = 500): int when not defined(useNimRtl): proc execProcess(command: string, + args: openarray[string] = [], + env: PStringTable = nil, options: set[TProcessOption] = {poStdErrToStdOut, - poUseShell}): TaintedString = - var p = startCmd(command, options=options) + poUsePath, + poEvalCommand}): TaintedString = + var p = startProcess(command, args=args, env=env, options=options) var outp = outputStream(p) result = TaintedString"" var line = newStringOfCap(120).TaintedString while true: + # FIXME: converts CR-LF to LF. if outp.readLine(line): result.string.add(line.string) result.string.add("\n") @@ -427,8 +436,9 @@ when defined(Windows) and not defined(useNimRtl): result.errHandle = TFileHandle(si.hStdError) var cmdl: cstring - when false: # poUseShell in options: - cmdl = buildCommandLine(getEnv("COMSPEC"), @["/c", command] & args) + if poEvalCommand in options: + cmdl = command + assert args.len == 0 else: cmdl = buildCommandLine(command, args) var wd: cstring = nil @@ -441,7 +451,7 @@ when defined(Windows) and not defined(useNimRtl): var ee = newWideCString(e) var wwd = newWideCString(wd) success = winlean.createProcessW(nil, - tmp, nil, nil, 1, NORMAL_PRIORITY_CLASS or CREATE_UNICODE_ENVIRONMENT, + tmp, nil, nil, 1, NORMAL_PRIORITY_CLASS or CREATE_UNICODE_ENVIRONMENT, ee, wwd, si, procInfo) else: success = winlean.createProcessA(nil, @@ -455,7 +465,6 @@ when defined(Windows) and not defined(useNimRtl): fileClose(si.hStdError) if e != nil: dealloc(e) - dealloc(cmdl) if success == 0: osError(lastError) # Close the handle now so anyone waiting is woken: discard closeHandle(procInfo.hThread) @@ -495,7 +504,7 @@ when defined(Windows) and not defined(useNimRtl): proc peekExitCode(p: PProcess): int = var b = waitForSingleObject(p.fProcessHandle, 50) == WAIT_TIMEOUT if b: result = -1 - else: + else: var res: int32 discard getExitCodeProcess(p.fProcessHandle, res) return res @@ -538,13 +547,13 @@ when defined(Windows) and not defined(useNimRtl): result = -1 discard closeHandle(process) - proc select(readfds: var seq[PProcess], timeout = 500): int = + proc select(readfds: var seq[PProcess], timeout = 500): int = assert readfds.len <= MAXIMUM_WAIT_OBJECTS var rfds: TWOHandleArray for i in 0..readfds.len()-1: rfds[i] = readfds[i].fProcessHandle - - var ret = waitForMultipleObjects(readfds.len.int32, + + var ret = waitForMultipleObjects(readfds.len.int32, addr(rfds), 0'i32, timeout.int32) case ret of WAIT_TIMEOUT: @@ -561,22 +570,7 @@ elif not defined(useNimRtl): readIdx = 0 writeIdx = 1 - proc addCmdArgs(command: string, args: openArray[string]): string = - result = quoteShell(command) - for i in 0 .. high(args): - add(result, " ") - add(result, quoteShell(args[i])) - - proc toCStringArray(b, a: openArray[string]): cstringArray = - result = cast[cstringArray](alloc0((a.len + b.len + 1) * sizeof(cstring))) - for i in 0..high(b): - result[i] = cast[cstring](alloc(b[i].len+1)) - copyMem(result[i], cstring(b[i]), b[i].len+1) - for i in 0..high(a): - result[i+b.len] = cast[cstring](alloc(a[i].len+1)) - copyMem(result[i+b.len], cstring(a[i]), a[i].len+1) - - proc toCStringArray(t: PStringTable): cstringArray = + proc envToCStringArray(t: PStringTable): cstringArray = result = cast[cstringArray](alloc0((t.len + 1) * sizeof(cstring))) var i = 0 for key, val in pairs(t): @@ -595,7 +589,7 @@ elif not defined(useNimRtl): result[i] = cast[cstring](alloc(x.len+1)) copyMem(result[i], addr(x[0]), x.len+1) inc(i) - + proc startProcess(command: string, workingDir: string = "", args: openArray[string] = [], @@ -609,23 +603,38 @@ elif not defined(useNimRtl): if pipe(pStdin) != 0'i32 or pipe(pStdout) != 0'i32 or pipe(pStderr) != 0'i32: osError(osLastError()) - + + var sys_command: string + var sys_args_raw: seq[string] + if poEvalCommand in options: + sys_command = "/bin/sh" + sys_args_raw = @[sys_command, "-c", command] + assert args.len == 0 + else: + sys_command = command + sys_args_raw = @[command] + for arg in args.items: + sys_args_raw.add arg + + var sys_args = allocCStringArray(sys_args_raw) + finally: deallocCStringArray(sys_args) + var pid: TPid when defined(posix_spawn) and not defined(useFork): var attr: Tposix_spawnattr var fops: Tposix_spawn_file_actions - template chck(e: expr) = + template chck(e: expr) = if e != 0'i32: osError(osLastError()) chck posix_spawn_file_actions_init(fops) chck posix_spawnattr_init(attr) - + var mask: Tsigset chck sigemptyset(mask) chck posix_spawnattr_setsigmask(attr, mask) chck posix_spawnattr_setpgroup(attr, 0'i32) - + chck posix_spawnattr_setflags(attr, POSIX_SPAWN_USEVFORK or POSIX_SPAWN_SETSIGMASK or POSIX_SPAWN_SETPGROUP) @@ -639,27 +648,22 @@ elif not defined(useNimRtl): if poStdErrToStdOut in options: chck posix_spawn_file_actions_adddup2(fops, pStdout[writeIdx], 2) else: - chck posix_spawn_file_actions_adddup2(fops, pStderr[writeIdx], 2) - - var e = if env == nil: envToCStringArray() else: toCStringArray(env) - var a: cstringArray + chck posix_spawn_file_actions_adddup2(fops, p_stderr[writeIdx], 2) + + var sys_env = if env == nil: envToCStringArray() else: envToCStringArray(env) var res: cint + # This is incorrect! if workingDir.len > 0: os.setCurrentDir(workingDir) - if poUseShell notin options: - a = toCStringArray([extractFilename(command)], args) - res = posix_spawn(pid, command, fops, attr, a, e) + if poUsePath in options: + res = posix_spawnp(pid, sys_command, fops, attr, sys_args, sys_env) else: - var x = addCmdArgs(command, args) - a = toCStringArray(["sh", "-c"], [x]) - res = posix_spawn(pid, "/bin/sh", fops, attr, a, e) - deallocCStringArray(a) - deallocCStringArray(e) + res = posix_spawn(pid, sys_command, fops, attr, sys_args, sys_env) + deallocCStringArray(sys_env) discard posix_spawn_file_actions_destroy(fops) discard posix_spawnattr_destroy(attr) chck res else: - pid = fork() if pid < 0: osError(osLastError()) if pid == 0: @@ -680,19 +684,18 @@ elif not defined(useNimRtl): if setpgid(0, 0) == -1: quit("setpgid call failed: " & $strerror(errno)) if workingDir.len > 0: os.setCurrentDir(workingDir) - if poUseShell notin options: - var a = toCStringArray([extractFilename(command)], args) - if env == nil: - discard execv(command, a) + + if env == nil: + if poUsePath in options: + discard execvp(sys_command, sys_args) else: - discard execve(command, a, toCStringArray(env)) + discard execv(sys_command, sys_args) else: - var x = addCmdArgs(command, args) - var a = toCStringArray(["sh", "-c"], [x]) - if env == nil: - discard execv("/bin/sh", a) + var c_env = envToCStringArray(env) + if poUsePath in options: + discard execvpe(sys_command, sys_args, c_env) else: - discard execve("/bin/sh", a, toCStringArray(env)) + discard execve(sys_command, sys_args, c_env) # too risky to raise an exception here: quit("execve call failed: " & $strerror(errno)) # Parent process. Copy process information. @@ -790,13 +793,13 @@ elif not defined(useNimRtl): proc execCmd(command: string): int = result = csystem(command) - proc createFdSet(fd: var TFdSet, s: seq[PProcess], m: var int) = + proc createFdSet(fd: var TFdSet, s: seq[PProcess], m: var int) = FD_ZERO(fd) - for i in items(s): + for i in items(s): m = max(m, int(i.outHandle)) FD_SET(cint(i.outHandle), fd) - - proc pruneProcessSet(s: var seq[PProcess], fd: var TFdSet) = + + proc pruneProcessSet(s: var seq[PProcess], fd: var TFdSet) = var i = 0 var L = s.len while i < L: @@ -807,26 +810,26 @@ elif not defined(useNimRtl): inc(i) setLen(s, L) - proc select(readfds: var seq[PProcess], timeout = 500): int = - var tv: Ttimeval + proc select(readfds: var seq[PProcess], timeout = 500): int = + var tv: TTimeVal tv.tv_sec = 0 tv.tv_usec = timeout * 1000 - + var rd: TFdSet var m = 0 createFdSet((rd), readfds, m) - + if timeout != -1: result = int(select(cint(m+1), addr(rd), nil, nil, addr(tv))) else: result = int(select(cint(m+1), addr(rd), nil, nil, nil)) - + pruneProcessSet(readfds, (rd)) proc execCmdEx*(command: string, options: set[TProcessOption] = { - poStdErrToStdOut, poUseShell}): tuple[ - output: TaintedString, + poStdErrToStdOut, poUsePath}): tuple[ + output: TaintedString, exitCode: int] {.tags: [FExecIO, FReadIO].} = ## a convenience proc that runs the `command`, grabs all its output and ## exit code and returns both. |