Page
Library
Module
Module type
Parameter
Class
Class type
Source
OCaml bindings to POSIX APIs.
ocaml-posix provides comprehensive bindings to POSIX system interfaces for OCaml. Each module offers:
This project consolidates and extends various existing POSIX binding libraries into a single, consistent collection.
API documentation is available at: http://www.liquidsoap.info/ocaml-posix/
opam install posix-base posix-types posix-errno posix-socket posix-time2git clone https://github.com/savonet/ocaml-posix.git
cd ocaml-posix
opam install .(* Using posix-time2 for clock operations *)
open Posix_time2
let () =
let ts = clock_gettime `Realtime in
Printf.printf "Current time: %Ld.%09ld seconds\n"
ts.Timespec.tv_sec ts.Timespec.tv_nsec(* Using posix-uname for system information *)
open Posix_uname
let () =
let info = uname () in
Printf.printf "System: %s %s (%s)\n"
info.sysname info.release info.machine(* Using posix-socket for DNS resolution *)
open Ctypes
open Posix_socket
let () =
(* Resolve hostname to socket addresses *)
let addresses = getaddrinfo ~port:(`Int 443) "example.com" in
List.iter (fun sockaddr ->
(* Convert back to human-readable form *)
let host, port = getnameinfo sockaddr in
Printf.printf "Resolved: %s:%d\n" host port
) addresses
(* Convert between Unix and POSIX socket addresses *)
let unix_to_posix addr =
let posix_addr = from_unix_sockaddr addr in
let host, port = getnameinfo posix_addr in
Printf.printf "Address: %s:%d\n" host portPackage | Description | Replaces |
|---|---|---|
| Base tools for generating POSIX bindings | - |
| POSIX type definitions | |
| Error number handling and Unix error conversion | |
| Socket operations ( | |
| Unix domain socket extensions | - |
| Time and clock functions | |
| Command-line option parsing | |
| System identification | - |
| Miscellaneous POSIX functions ( | - |
| Resource limits and usage ( | |
| Signal handling | - |
| File status ( | |
| Mathematical functions | - |
ocaml-posix supports cross-compilation (e.g., building for Windows from Linux/macOS using mingw). The build system automatically detects cross-compilation scenarios and uses appropriate tooling.
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.