Sys

Usage

use Sys;

or

import Sys;

Support for low-level programming and system calls.

This module is for low-level programming. It provides Chapel versions of many POSIX/Linux C library or system calls. For documentation on these system calls and constants, please see your system’s manual pages.

Each of the functions in this file provides the same functionality as the corresponding function without the sys_ prefix, except that the sys_ versions all return an error code (of type c_int) and return any other values (such as how much was read) through an out argument.

For example, you can find more about the mmap call with:

man mmap

The call available here, sys_mmap, always returns an error code (or 0 for no error). The pointer value normally returned by mmap will be returned through the final ret_out argument.

Warning

The ‘Sys’ module has been deprecated; please find replacement symbols in the ‘OS’ and ‘Socket’ modules

const F_GETFL: c_int
const F_SETFL: c_int
const F_GETFD: c_int
const F_SETFD: c_int
const SIGABRT: c_int

Warning

‘Sys.SIGABRT’ is deprecated; please use ‘OS.POSIX.SIGABRT’ instead

const SIGALRM: c_int

Warning

‘Sys.SIGALRM’ is deprecated; please use ‘OS.POSIX.SIGALRM’ instead

const SIGBUS: c_int

Warning

‘Sys.SIGBUS’ is deprecated; please use ‘OS.POSIX.SIGBUS’ instead

const SIGCHLD: c_int

Warning

‘Sys.SIGCHLD’ is deprecated; please use ‘OS.POSIX.SIGCHLD’ instead

const SIGCONT: c_int

Warning

‘Sys.SIGCONT’ is deprecated; please use ‘OS.POSIX.SIGCONT’ instead

const SIGFPE: c_int

Warning

‘Sys.SIGFPE’ is deprecated; please use ‘OS.POSIX.SIGFPE’ instead

const SIGHUP: c_int

Warning

‘Sys.SIGHUP’ is deprecated; please use ‘OS.POSIX.SIGHUP’ instead

const SIGILL: c_int

Warning

‘Sys.SIGILL’ is deprecated; please use ‘OS.POSIX.SIGILL’ instead

const SIGINT: c_int

Warning

‘Sys.SIGINT’ is deprecated; please use ‘OS.POSIX.SIGINT’ instead

const SIGKILL: c_int

Warning

‘Sys.SIGKILL’ is deprecated; please use ‘OS.POSIX.SIGKILL’ instead

const SIGPIPE: c_int

Warning

‘Sys.SIGPIPE’ is deprecated; please use ‘OS.POSIX.SIGPIPE’ instead

const SIGQUIT: c_int

Warning

‘Sys.SIGQUIT’ is deprecated; please use ‘OS.POSIX.SIGQUIT’ instead

const SIGSEGV: c_int

Warning

‘Sys.SIGSEGV’ is deprecated; please use ‘OS.POSIX.SIGSEGV’ instead

const SIGSTOP: c_int

Warning

‘Sys.SIGSTOP’ is deprecated; please use ‘OS.POSIX.SIGSTOP’ instead

const SIGTERM: c_int

Warning

‘Sys.SIGTERM’ is deprecated; please use ‘OS.POSIX.SIGTERM’ instead

const SIGTRAP: c_int

Warning

‘Sys.SIGTRAP’ is deprecated; please use ‘OS.POSIX.SIGTRAP’ instead

const SIGTSTP: c_int

Warning

‘Sys.SIGTSTP’ is deprecated; please use ‘OS.POSIX.SIGTSTP’ instead

const SIGTTIN: c_int

Warning

‘Sys.SIGTTIN’ is deprecated; please use ‘OS.POSIX.SIGTTIN’ instead

const SIGTTOU: c_int

Warning

‘Sys.SIGTTOU’ is deprecated; please use ‘OS.POSIX.SIGTTOU’ instead

const SIGURG: c_int

Warning

‘Sys.SIGURG’ is deprecated; please use ‘OS.POSIX.SIGURG’ instead

const SIGUSR1: c_int

Warning

‘Sys.SIGUSR1’ is deprecated; please use ‘OS.POSIX.SIGUSR1’ instead

const SIGUSR2: c_int

Warning

‘Sys.SIGUSR2’ is deprecated; please use ‘OS.POSIX.SIGUSR2’ instead

const SIGXCPU: c_int

Warning

‘Sys.SIGXCPU’ is deprecated; please use ‘OS.POSIX.SIGXCPU’ instead

const SIGXFSZ: c_int

Warning

‘Sys.SIGXFSZ’ is deprecated; please use ‘OS.POSIX.SIGXFSZ’ instead

const AF_UNIX: c_int
const AF_LOCAL: c_int
const AF_IPX: c_int
const AF_X25: c_int
const AF_AX25: c_int
const AF_ATMPVC: c_int
const AF_APPLETALK: c_int
const AF_PACKET: c_int
const AF_INET: c_int

Warning

‘Sys.AF_INET’ is deprecated; please use ‘Socket.AF_INET’ instead

const AF_INET6: c_int

Warning

‘Sys.AF_INET6’ is deprecated; please use ‘Socket.AF_INET6’ instead

const SOCK_STREAM: c_int
const SOCK_DGRAM: c_int
const SOCK_SEQPACKET: c_int
const SOCK_RAW: c_int
const SOCK_RDM: c_int
const SOCK_NONBLOCK: c_int
const SOCK_CLOEXEC: c_int
const MSG_CONFIRM: c_int
const MSG_DONTROUTE: c_int
const MSG_DONTWAIT: c_int
const MSG_EOR: c_int
const MSG_MORE: c_int
const MSG_NOSIGNAL: c_int
const MSG_OOB: c_int
const MSG_CMSG_CLOEXEC: c_int
const MSG_ERRQUEUE: c_int
const MSG_PEEK: c_int
const MSG_TRUNC: c_int
const MSG_WAITALL: c_int
const MSG_CTRUNC: c_int
const SHUT_RD: c_int
const SHUT_WR: c_int
const SHUT_RDWR: c_int
const SOL_SOCKET: c_int
const IPPROTO_IP: c_int
const IPPROTO_IPV6: c_int
const IPPROTO_TCP: c_int
const IPPROTO_UDP: c_int
const SO_ACCEPTCONN: c_int

Warning

‘Sys.SO_ACCEPTCONN’ is deprecated; please use ‘Socket.SO_ACCEPTCONN’ instead

const SO_BROADCAST: c_int

Warning

‘Sys.SO_BROADCAST’ is deprecated; please use ‘Socket.SO_BROADCAST’ instead

const SO_DEBUG: c_int

Warning

‘Sys.SO_DEBUG’ is deprecated; please use ‘Socket.SO_DEBUG’ instead

const SO_ERROR: c_int

Warning

‘Sys.SO_ERROR’ is deprecated; please use ‘Socket.SO_ERROR’ instead

const SO_KEEPALIVE: c_int

Warning

‘Sys.SO_KEEPALIVE’ is deprecated; please use ‘Socket.SO_KEEPALIVE’ instead

const SO_LINGER: c_int

Warning

‘Sys.SO_LINGER’ is deprecated; please use ‘Socket.SO_LINGER’ instead

const SO_OOBINLINE: c_int

Warning

‘Sys.SO_OOBINLINE’ is deprecated; please use ‘Socket.SO_OOBINLINE’ instead

const SO_RCVBUF: c_int

Warning

‘Sys.SO_RCVBUF’ is deprecated; please use ‘Socket.SO_RCVBUF’ instead

const SO_RCVTIMEO: c_int

Warning

‘Sys.SO_RCVTIMEO’ is deprecated; please use ‘Socket.SO_RCVTIMEO’ instead

const SO_REUSEADDR: c_int

Warning

‘Sys.SO_REUSEADDR’ is deprecated; please use ‘Socket.SO_REUSEADDR’ instead

const SO_SNDBUF: c_int

Warning

‘Sys.SO_SNDBUF’ is deprecated; please use ‘Socket.SO_SNDBUF’ instead

const SO_SNDTIMEO: c_int

Warning

‘Sys.SO_SNDTIMEO’ is deprecated; please use ‘Socket.SO_SNDTIMEO’ instead

const SO_SECINFO: c_int

Warning

‘Sys.SO_SECINFO’ is deprecated; please use ‘Socket.SO_SECINFO’ instead

const IP_ADD_MEMBERSHIP: c_int
const IP_DROP_MEMBERSHIP: c_int
const IP_HDRINCL: c_int
const IP_MTU: c_int
const IP_MTU_DISCOVER: c_int
const IP_MULTICAST_IF: c_int
const IP_MULTICAST_LOOP: c_int
const IP_MULTICAST_TTL: c_int
const IP_OPTIONS: c_int
const IP_PKTINFO: c_int
const IP_RECVERR: c_int
const IP_RECVOPTS: c_int
const IP_RECVTOS: c_int
const IP_RECVTTL: c_int
const IP_RETOPTS: c_int
const IP_ROUTER_ALERT: c_int
const IP_TOS: c_int
const IP_TTL: c_int
const IPV6_ADDRFORM: c_int
const IPV6_ADD_MEMBERSHIP: c_int
const IPV6_DROP_MEMBERSHIP: c_int
const IPV6_MTU: c_int
const IPV6_MTU_DISCOVER: c_int
const IPV6_MULTICAST_HOPS: c_int
const IPV6_MULTICAST_IF: c_int
const IPV6_MULTICAST_LOOP: c_int
const IPV6_PKTINFO: c_int
const IPV6_RTHDR: c_int
const IPV6_AUTHHDR: c_int
const IPV6_DSTOPTS: c_int
const IPV6_HOPOPTS: c_int
const IPV6_HOPLIMIT: c_int
const IPV6_RECVERR: c_int
const IPV6_ROUTER_ALERT: c_int
const IPV6_UNICAST_HOPS: c_int
const IPV6_V6ONLY: c_int
const TCP_CORK: c_int
const TCP_DEFER_ACCEPT: c_int
const TCP_INFO: c_int
const TCP_KEEPCNT: c_int
const TCP_KEEPIDLE: c_int
const TCP_KEEPINTVL: c_int
const TCP_LINGER2: c_int
const TCP_MAXSEG: c_int
const TCP_NODELAY: c_int
const TCP_QUICKACK: c_int
const TCP_SYNCNT: c_int
const TCP_WINDOW_CLAMP: c_int
const INET_ADDRSTRLEN: c_int
const INET6_ADDRSTRLEN: c_int
const NI_MAXHOST: c_int
const NI_MAXSERV: c_int
const INADDR_ANY: sys_in_addr_t

Warning

‘Sys.INADDR_ANY’ is deprecated; please use ‘Socket.INADDR_ANY’ instead

const INADDR_BROADCAST: sys_in_addr_t

Warning

‘Sys.INADDR_BROADCAST’ is deprecated; please use ‘Socket.INADDR_BROADCAST’ instead

const INADDR_LOOPBACK: sys_in_addr_t

Warning

‘Sys.INADDR_LOOPBACK’ is deprecated; please use ‘Socket.INADDR_LOOPBACK’ instead

const in6addr_any: sys_in6_addr_t

Warning

‘Sys.in6addr_any’ is deprecated; please use ‘Socket.in6addr_any’ instead

const in6addr_loopback: sys_in6_addr_t

Warning

‘Sys.in6addr_loopback’ is deprecated; please use ‘Socket.in6addr_loopback’ instead

type sys_in_addr_t

Warning

‘Sys.sys_in_addr_t’ is deprecated; please use ‘Socket.sys_in_addr_t’ instead

type sys_in6_addr_t

Warning

‘Sys.sys_in6_addr_t’ is deprecated; please use ‘Socket.sys_in6_addr_t’ instead

type sys_sockaddr_storage_t
type socklen_t = int(32)

The type corresponding to C’s socklen_t

record sys_sockaddr_t
var addr: sys_sockaddr_storage_t
var len: socklen_t
proc init()
proc sys_sockaddr_t.family: c_int

Returns socket family.

Returns

a socket family

Return type

c_int

record sys_addrinfo_t
var ai_flags: c_int
var ai_family: c_int
var ai_socktype: c_int
var ai_protocol: c_int
var ai_addrlen: socklen_t
var ai_next: c_ptr(sys_addrinfo_t)
type sys_addrinfo_ptr_t = c_ptr(sys_addrinfo_t)
proc sys_addrinfo_ptr_t.flags: c_int
proc sys_addrinfo_ptr_t.family: c_int
proc sys_addrinfo_ptr_t.socktype: c_int
proc sys_addrinfo_ptr_t.addr: sys_sockaddr_t
proc sys_addrinfo_ptr_t.next: sys_addrinfo_ptr_t
proc sys_init_sys_sockaddr_t(ref addr: sys_sockaddr_t)
proc sys_getsockaddr_family(const ref addr: sys_sockaddr_t): c_int
proc sys_set_sys_sockaddr_t(ref addr: sys_sockaddr_t, host: c_string, port: c_uint, family: c_int): c_int
proc sys_set_sys_sockaddr_in_t(ref addr: sys_sockaddr_t, host: sys_in_addr_t, port: c_uint)
proc sys_set_sys_sockaddr_in6_t(ref addr: sys_sockaddr_t, host: sys_in6_addr_t, port: c_uint)
proc sys_host_sys_sockaddr_t(const ref addr: sys_sockaddr_t, host: c_ptr(c_char), hostlen: socklen_t, ref length: c_int): c_int
proc sys_port_sys_sockaddr_t(const ref addr: sys_sockaddr_t, ref port: c_uint): c_int
proc sys_strerror(error: qio_err_t, ref string_out: c_string): qio_err_t
proc sys_getenv(name: c_string, ref string_out: c_string): c_int

Check whether or not the environment variable name is defined. If name is defined then return 1 and update string_out to store the value of the environment variable otherwise the function returns 0.

Arguments
  • name : c_string – name of the environment variable

  • string_out : c_string – store the value of name environment variable if defined

Returns

1 if name is defined and 0 if not

Return type

c_int

Warning

‘Sys.sys_getenv’ is deprecated; please use ‘OS.sys_getenv’ instead

type mode_t = uint(32)
proc sys_open(pathname: c_string, flags: c_int, mode: mode_t, ref fd_out: fd_t): qio_err_t
proc sys_close(fd: fd_t): qio_err_t
type off_t = int(64)
proc sys_mmap(addr: c_void_ptr, length: c_size_t, prot: c_int, flags: c_int, fd: fd_t, offset: off_t, ref ret_out: c_void_ptr): qio_err_t
proc sys_munmap(addr: c_void_ptr, length: c_size_t): qio_err_t
proc sys_fcntl_ptr(fd: fd_t, cmd: c_int, arg: c_void_ptr, ref ret_out: c_int): qio_err_t
proc sys_dup(oldfd: fd_t, ref fd_out: fd_t): qio_err_t
proc sys_dup2(oldfd: fd_t, newfd: fd_t, ref fd_out: fd_t): qio_err_t
proc sys_pipe(ref read_fd_out: fd_t, ref write_fd_out: fd_t): qio_err_t
proc sys_getaddrinfo_protocol(res: sys_addrinfo_ptr_t): c_int
proc sys_getnameinfo(ref addr: sys_sockaddr_t, ref host_out: c_string, ref serv_outc_: c_string, flags: c_int): qio_err_t
proc sys_socketpair(_domain: c_int, _type: c_int, protocol: c_int, ref sockfd_out_a: fd_t, ref sockfd_out_b: fd_t): qio_err_t
proc sys_shutdown(sockfd: fd_t, how: c_int): qio_err_t
proc sys_fcntl(fd: fd_t, cmd: c_int, ref ret_out: c_int): qio_err_t
proc sys_fcntl_long(fd: fd_t, cmd: c_int, arg: c_long, ref ret_out: c_int): qio_err_t
proc sys_accept(sockfd: fd_t, ref add_out: sys_sockaddr_t, ref fd_out: fd_t): qio_err_t
proc sys_bind(sockfd: fd_t, const ref addr: sys_sockaddr_t): qio_err_t
proc sys_connect(sockfd: fd_t, const ref addr: sys_sockaddr_t): qio_err_t
proc getaddrinfo(node: c_string, service: c_string, ref hints: sys_addrinfo_t, ref res_out: sys_addrinfo_ptr_t): qio_err_t
proc sys_freeaddrinfo(res: sys_addrinfo_ptr_t)
proc sys_getpeername(sockfd: fd_t, ref addr: sys_sockaddr_t): qio_err_t
proc sys_getsockname(sockfd: fd_t, ref addr: sys_sockaddr_t): qio_err_t
proc sys_getsockopt(sockfd: fd_t, level: c_int, optname: c_int, optval: c_void_ptr, ref optlen: socklen_t): qio_err_t
proc sys_setsockopt(sockfd: fd_t, level: c_int, optname: c_int, optval: c_void_ptr, optlen: socklen_t): qio_err_t
proc sys_listen(sockfd: fd_t, backlog: c_int): qio_err_t
proc sys_socket(_domain: c_int, _type: c_int, protocol: c_int, ref sockfd_out: fd_t): qio_err_t
proc sys_getaddrinfo_addr(res: sys_addrinfo_ptr_t): sys_sockaddr_t
proc sys_getaddrinfo_next(res: sys_addrinfo_ptr_t): sys_addrinfo_ptr_t
proc sys_getaddrinfo_flags(res: sys_addrinfo_ptr_t): c_int
proc sys_getaddrinfo_family(res: sys_addrinfo_ptr_t): c_int
proc sys_getaddrinfo_socktype(res: sys_addrinfo_ptr_t): c_int
type time_t = c_long
type suseconds_t = c_long
record timeval
var tv_sec: time_t
var tv_usec: suseconds_t
proc sys_select(nfds: c_int, readfds: c_ptr(fd_set), writefds: c_ptr(fd_set), exceptfds: c_ptr(fd_set), timeout: c_ptr(timeval), ref nset: c_int): qio_err_t