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 err_t) 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.

const F_GETFL: c_int
const F_SETFL: c_int
const F_GETFD: c_int
const F_SETFD: c_int
const O_RDONLY: c_int
const O_WRONLY: c_int
const O_RDWR: c_int
const O_APPEND: c_int
const O_CREAT: c_int
const O_DSYNC: c_int
const O_EXCL: c_int
const O_NOCTTY: c_int
const O_NONBLOCK: c_int
const O_RSYNC: c_int
const O_SYNC: c_int
const O_TRUNC: c_int
const AF_UNIX: c_int
const AF_LOCAL: c_int
const AF_INET: c_int
const AF_INET6: 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 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
const SO_BROADCAST: c_int
const SO_DEBUG: c_int
const SO_ERROR: c_int
const SO_KEEPALIVE: c_int
const SO_LINGER: c_int
const SO_OOBINLINE: c_int
const SO_RCVBUF: c_int
const SO_RCVTIMEO: c_int
const SO_REUSEADDR: c_int
const SO_SNDBUF: c_int
const SO_SNDTIMEO: c_int
const SO_SECINFO: c_int
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
const INADDR_BROADCAST: sys_in_addr_t
const INADDR_LOOPBACK: sys_in_addr_t
const in6addr_any: sys_in6_addr_t
const in6addr_loopback: sys_in6_addr_t
type sys_in_addr_t

SOCKET STRUCTURE TYPES

type sys_in6_addr_t
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: err_t, ref string_out: c_string): 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

type mode_t = uint(32)

The type corresponding to C’s mode_t

proc sys_open(pathname: c_string, flags: c_int, mode: mode_t, ref fd_out: fd_t): err_t
proc sys_close(fd: fd_t): err_t
type off_t = int(64)

The type corresponding to C’s off_t

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): err_t
proc sys_munmap(addr: c_void_ptr, length: c_size_t): err_t
proc sys_fcntl(fd: fd_t, cmd: c_int, ref ret_out: c_int): err_t
proc sys_fcntl_long(fd: fd_t, cmd: c_int, arg: c_long, ref ret_out: c_int): err_t
proc sys_fcntl_ptr(fd: fd_t, cmd: c_int, arg: c_void_ptr, ref ret_out: c_int): err_t
proc sys_dup(oldfd: fd_t, ref fd_out: fd_t): err_t
proc sys_dup2(oldfd: fd_t, newfd: fd_t, ref fd_out: fd_t): err_t
proc sys_pipe(ref read_fd_out: fd_t, ref write_fd_out: fd_t): err_t
proc sys_accept(sockfd: fd_t, ref add_out: sys_sockaddr_t, ref fd_out: fd_t): err_t
proc sys_bind(sockfd: fd_t, const ref addr: sys_sockaddr_t): err_t
proc sys_connect(sockfd: fd_t, const ref addr: sys_sockaddr_t): err_t
proc getaddrinfo(node: c_string, service: c_string, ref hints: sys_addrinfo_t, ref res_out: sys_addrinfo_ptr_t): err_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
proc sys_getaddrinfo_protocol(res: sys_addrinfo_ptr_t): c_int
proc sys_getaddrinfo_addrlen(res: sys_addrinfo_ptr_t): socklen_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_freeaddrinfo(res: sys_addrinfo_ptr_t)
proc sys_getnameinfo(ref addr: sys_sockaddr_t, ref host_out: c_string, ref serv_outc_: c_string, flags: c_int): err_t
proc sys_getpeername(sockfd: fd_t, ref addr: sys_sockaddr_t): err_t
proc sys_getsockname(sockfd: fd_t, ref addr: sys_sockaddr_t): err_t
proc sys_getsockopt(sockfd: fd_t, level: c_int, optname: c_int, optval: c_void_ptr, ref optlen: socklen_t): err_t
proc sys_setsockopt(sockfd: fd_t, level: c_int, optname: c_int, optval: c_void_ptr, optlen: socklen_t): err_t
proc sys_listen(sockfd: fd_t, backlog: c_int): err_t
proc sys_shutdown(sockfd: fd_t, how: c_int): err_t
proc sys_socket(_domain: c_int, _type: c_int, protocol: c_int, ref sockfd_out: fd_t): 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): err_t
type fd_set
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): err_t
proc sys_fd_clr(fd: c_int, ref set: fd_set)
proc sys_fd_isset(fd: c_int, ref set: fd_set): c_int
proc sys_fd_set(fd: c_int, ref set: fd_set)
proc sys_fd_zero(ref set: fd_set)