MyNixOS website logo
Description

Straightforward bindings to the posix API.

A straightforward wrapping of unix APIs for Haskell.

I wrote this package because state of posix API support in Haskell is somewhat unsatisfactory in a few ways:

  • There are many syscalls not covered by the unix package
  • The unix package needlessly renames syscalls, making them harder to find for people familiar with the posix API. For example, lstat has been renamed to getSymbolicLinkStatus
  • There are a large number of packages that fill in various holes, but you have to scrape them together.

The goal of this package then, is to provide a one-stop-shop for unix API bindings, with a straightforward mapping to the underlying C API. At the time of writing there are many syscalls missing, but in theory most things belong here. Patches welcome; see the section below re: how to add a syscall.

General Conventions

  • Function names are the same as the underlying system calls, so there is no guesswork.
  • Wrappers automatically retry on EINTR where appropriate (this is safe for most system calls, but not all, e.g. close on Linux).
  • The basic versions of the syscalls return IO (Either Errno a), rather than raising an exception.
    • Each system call also has a variant suffixed with Exn that throws exceptions.
    • We define a type alias type EIO a = IO (Either Errno a) for convenience.
  • For flags, we add newtype wrappers, and they can be combined with their SemiGroup instances, e.g.
    • open "hello.txt" (o_CREAT <> o_RDWR) 0o600
  • Flags are named the same as the C constant, but with the first character lower-cased.
  • For functions that take a buffer, we instead accept a ByteString when the buffer is read, or return one when it is written, e.g.
    • read :: Fd -> Int -> EIO BS.ByteString
    • write :: Fd -> BS.ByteString -> EIO CSsize
  • We also provide variants suffixed with Buf, that take a pointer and size:
    • readBuf :: Fd -> Ptr Word8 -> CSize -> EIO CSsize
  • We provide a CString type for functions which accept strings as arguments. This type is an instance of IsString, so you can use string literals if you enable OverloadedStrings, or use the fromString function to convert. The conversion uses utf-8 encoding.
  • For some calls we also add obvious convenience helpers, e.g. readFull and writeFull, which wrap read and write and handle short reads and writes for the caller.

Contributing

Adding a syscall

To add a new system call:

  • Add the appropriate declaration to Unix.C, following conventions established by the examples in that file.
  • Add a wrapper following the general conventions in Unix.
Metadata

Version

0.1.0.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows