text stringlengths 0 601k |
|---|
let getppid ( ) = Unix . getppid ( ) |
let getppid_exn ( ) = Unix . getppid_exn ( ) |
let this_process_became_child_of_init ( ? poll_delay = sec 1 . ) ( ) = Deferred . create ( fun i -> Clock . every poll_delay ~ stop ( : Ivar . read i ) ( fun ( ) -> if Pid . equal ( getppid_exn ( ) ) Pid . init then Ivar . fill i ( ) ) ) ; ; |
let nice i = Unix . nice i |
let cores = Or_error . map Linux_ext . cores ~ f ( : fun cores ( ) -> In_thread . syscall_exn ~ name " : cores " cores ) ; ; |
let convert_open_flag : _ -> Unix . open_flag = function | ` Rdonly -> O_RDONLY | ` Wronly -> O_WRONLY | ` Rdwr -> O_RDWR | ` Nonblock -> O_NONBLOCK | ` Append -> O_APPEND | ` Creat -> O_CREAT | ` Trunc -> O_TRUNC | ` Excl -> O_EXCL | ` Noctty -> O_NOCTTY | ` Dsync -> O_DSYNC | ` Sync -> O_SYNC | ` Rsync -> O_RSYNC ; ; |
type open_flag = [ ` Rdonly | ` Wronly | ` Rdwr | ` Nonblock | ` Append | ` Creat | ` Trunc | ` Excl | ` Noctty | ` Dsync | ` Sync | ` Rsync ] |
type file_perm = int [ @@ deriving sexp , bin_io , compare ] |
let openfile ? perm file ~ mode = let mode = List . map mode ~ f : convert_open_flag @ [ O_CLOEXEC ] in let % bind file_descr = In_thread . syscall_exn ~ name " : openfile " ( fun ( ) -> Unix . openfile ? perm file ~ mode ) in let % map kind = Fd . Kind . infer_using_stat file_descr in Fd . create kind file_descr ( Inf... |
let fcntl_getfl fd = Fd . syscall_in_thread_exn fd ~ name " : fcntl_getfl " ( fun file_descr -> Unix . fcntl_getfl file_descr ) ; ; |
let fcntl_setfl fd flags = Fd . syscall_in_thread_exn fd ~ name " : fcntl_setfl " ( fun file_descr -> Unix . fcntl_setfl file_descr flags ) ; ; |
let lseek fd pos ~ mode = let mode : Unix . seek_command = match mode with | ` Set -> SEEK_SET | ` Cur -> SEEK_CUR | ` End -> SEEK_END in Fd . syscall_in_thread_exn fd ~ name " : lseek " ( fun file_descr -> Unix . lseek file_descr pos ~ mode ) ; ; |
let truncate filename ~ len = In_thread . syscall_exn ~ name " : truncate " ( fun ( ) -> Unix . truncate filename ~ len ) ; ; |
let ftruncate fd ~ len = Fd . syscall_in_thread_exn fd ~ name " : ftruncate " ( fun file_descr -> Unix . ftruncate file_descr ~ len ) ; ; |
let fsync fd = Fd . syscall_in_thread_exn fd ~ name " : fsync " Unix . fsync |
let fdatasync fd = Fd . syscall_in_thread_exn fd ~ name " : fdatasync " Unix . fdatasync |
let sync ( ) = In_thread . syscall_exn ~ name " : sync " Unix . sync |
module Lock_mode = struct type t = | Shared | Exclusive [ @@ deriving sexp_of ] let flock_command : t -> _ = function | Shared -> Unix . Flock_command . lock_shared | Exclusive -> Unix . Flock_command . lock_exclusive ; ; end |
let lockf ( ? len = 0L ) fd ( lock_mode : Lock_mode . t ) = let mode : Unix . lock_command = match lock_mode with | Shared -> F_RLOCK | Exclusive -> F_LOCK in Fd . syscall_in_thread_exn fd ~ name " : lockf " ( fun file_descr -> Unix . lockf file_descr ~ mode ~ len ) ; ; |
let try_lockf ( ? len = 0L ) fd ( lock_mode : Lock_mode . t ) = let mode : Unix . lock_command = match lock_mode with | Shared -> F_TRLOCK | Exclusive -> F_TLOCK in Fd . syscall_exn fd ( fun file_descr -> try Unix . lockf file_descr ~ mode ~ len ; true with | Unix_error ( ( EACCES | EAGAIN ) , _ , _ ) -> false ) ; ; |
let test_lockf ( ? len = 0L ) fd = Fd . syscall_exn fd ( fun file_descr -> try Unix . lockf file_descr ~ mode : F_TEST ~ len ; true with | Unix_error ( ( EACCES | EAGAIN ) , _ , _ ) -> false ) ; ; |
let unlockf ( ? len = 0L ) fd = Fd . syscall_exn fd ( fun file_descr -> Unix . lockf file_descr ~ mode : F_ULOCK ~ len ) ; ; |
let flock fd lock_mode = let mode = Lock_mode . flock_command lock_mode in Fd . syscall_in_thread_exn fd ~ name " : flock " ( fun file_descr -> Unix . flock_blocking file_descr mode ) ; ; |
let try_flock fd lock_mode = let mode = Lock_mode . flock_command lock_mode in Fd . syscall_exn fd ( fun file_descr -> Unix . flock file_descr mode ) ; ; |
let funlock fd = Fd . syscall_exn fd ( fun file_descr -> ignore ( Unix . flock file_descr Unix . Flock_command . unlock : bool ) ) ; ; |
module Lock_mechanism = struct module T = struct type t = | Lockf | Flock [ @@ deriving compare , enumerate , sexp , variants ] end let lock ( t : T . t ) = match t with | Lockf -> lockf ? len : None | Flock -> flock ; ; include T include Sexpable . To_stringable ( T ) let arg_type = Command . Param . Arg_type . Export... |
module Lock = struct type t = { mode : Lock_mode . t ; mechanism : Lock_mechanism . t } [ @@ deriving sexp_of ] end |
let with_file ? lock ? perm file ~ mode ~ f = let doit f = let % bind fd = openfile file ~ mode ? perm in Fd . with_close fd ~ f in match lock with | None -> doit f | Some { Lock . mode ; mechanism } -> doit ( fun fd -> let % bind ( ) = Lock_mechanism . lock mechanism fd mode in f fd ) ; ; |
module File_kind = struct module T = struct type t = [ ` File | ` Directory | ` Char | ` Block | ` Link | ` Fifo | ` Socket ] [ @@ deriving compare , sexp , bin_io ] end include T include Comparable . Make ( T ) let of_unix : Unix . file_kind -> _ = function | S_REG -> ` File | S_DIR -> ` Directory | S_CHR -> ` Char | ... |
module Stats = struct type t = { dev : int ; ino : int ; kind : File_kind . t ; perm : file_perm ; nlink : int ; uid : int ; gid : int ; rdev : int ; size : int64 ; atime : Time . t ; mtime : Time . t ; ctime : Time . t } [ @@ deriving fields , sexp , bin_io , compare ] let of_unix ( u : Unix . stats ) = let of_float_s... |
let fstat fd = Fd . syscall_in_thread_exn fd ~ name " : fstat " Unix . fstat >>| Stats . of_unix |
let stat filename = In_thread . syscall_exn ~ name " : stat " ( fun ( ) -> Unix . stat filename ) >>| Stats . of_unix ; ; |
let lstat filename = In_thread . syscall_exn ~ name " : lstat " ( fun ( ) -> Unix . lstat filename ) >>| Stats . of_unix ; ; |
let isatty fd = Fd . syscall_in_thread_exn fd ~ name " : isatty " Unix . isatty |
let unlink filename = In_thread . syscall_exn ~ name " : unlink " ( fun ( ) -> Unix . unlink filename ) ; ; |
let remove filename = In_thread . syscall_exn ~ name " : remove " ( fun ( ) -> Unix . remove filename ) ; ; |
let rename ~ src ~ dst = In_thread . syscall_exn ~ name " : rename " ( fun ( ) -> Unix . rename ~ src ~ dst ) ; ; |
let link ? force ~ target ~ link_name ( ) = In_thread . syscall_exn ~ name " : link " ( fun ( ) -> Unix . link ? force ~ target ~ link_name ( ) ) ; ; |
let chmod filename ~ perm = In_thread . syscall_exn ~ name " : chmod " ( fun ( ) -> Unix . chmod filename ~ perm ) ; ; |
let fchmod fd ~ perm = Fd . syscall_in_thread_exn fd ~ name " : fchmod " ( fun file_descr -> Unix . fchmod file_descr ~ perm ) ; ; |
let chown filename ~ uid ~ gid = In_thread . syscall_exn ~ name " : chown " ( fun ( ) -> Unix . chown filename ~ uid ~ gid ) ; ; |
let fchown fd ~ uid ~ gid = Fd . syscall_in_thread_exn fd ~ name " : fchown " ( fun file_descr -> Unix . fchown file_descr ~ uid ~ gid ) ; ; |
let access filename perm = match % map Monitor . try_with ( fun ( ) -> In_thread . syscall_exn ~ name " : access " ( fun ( ) -> Unix . access filename perm ) ) with | Ok res -> res | Error exn -> Error ( Monitor . extract_exn exn ) ; ; |
let access_exn filename perm = In_thread . syscall_exn ~ name " : access " ( fun ( ) -> Unix . access_exn filename perm ) ; ; |
let set_close_on_exec fd = Fd . with_file_descr_exn fd Unix . set_close_on_exec |
let clear_close_on_exec fd = Fd . with_file_descr_exn fd Unix . clear_close_on_exec |
let mkdir ? p ( ? perm = 0o777 ) dirname = match p with | None -> In_thread . syscall_exn ~ name " : mkdir " ( fun ( ) -> Unix . mkdir dirname ~ perm ) | Some ( ) -> In_thread . syscall_exn ~ name " : mkdir " ( fun ( ) -> Unix . mkdir_p dirname ~ perm ) ; ; |
let rmdir dirname = In_thread . syscall_exn ~ name " : rmdir " ( fun ( ) -> Unix . rmdir dirname ) |
let chdir dirname = In_thread . syscall_exn ~ name " : chdir " ( fun ( ) -> Unix . chdir dirname ) |
let chroot dirname = In_thread . syscall_exn ~ name " : chroot " ( fun ( ) -> Unix . chroot dirname ) |
let getcwd ( ) = In_thread . syscall_exn ~ name " : getcwd " ( fun ( ) -> Unix . getcwd ( ) ) |
let opendir dirname = In_thread . syscall_exn ~ name " : opendir " ( fun ( ) -> Unix . opendir dirname ) ; ; |
let readdir_opt handle = In_thread . syscall_exn ~ name " : readdir " ( fun ( ) -> Unix . readdir_opt handle ) ; ; |
let rewinddir handle = In_thread . syscall_exn ~ name " : rewinddir " ( fun ( ) -> Unix . rewinddir handle ) ; ; |
let closedir handle = In_thread . syscall_exn ~ name " : closedir " ( fun ( ) -> Unix . closedir handle ) ; ; |
let pipe info = let % map reader , writer = In_thread . syscall_exn ~ name " : pipe " ( fun ( ) -> Unix . pipe ~ close_on_exec : true ( ) ) in let create file_descr kind = Fd . create Fifo file_descr ( Info . tag info ~ tag : kind ) in ` Reader ( create reader " reader " ) , ` Writer ( create writer " writer " ) ; ; |
let mkfifo ( ? perm = 0o666 ) name = In_thread . syscall_exn ~ name " : mkfifo " ( fun ( ) -> Unix . mkfifo name ~ perm ) ; ; |
let symlink ~ target ~ link_name = In_thread . syscall_exn ~ name " : symlink " ( fun ( ) -> Unix . symlink ~ target ~ link_name ) ; ; |
let readlink filename = In_thread . syscall_exn ~ name " : readlink " ( fun ( ) -> Unix . readlink filename ) ; ; |
let mkdtemp filename = In_thread . syscall_exn ~ name " : mkdtemp " ( fun ( ) -> Unix . mkdtemp filename ) ; ; |
let mkstemp filename = let % map name , file_descr = In_thread . syscall_exn ~ name " : mkstemp " ( fun ( ) -> Unix . mkstemp filename ) in name , Fd . create File file_descr ( Info . of_string name ) ; ; |
let getgrouplist username gid = In_thread . syscall_exn ~ name " : getgrouplist " ( fun ( ) -> Unix . getgrouplist username gid ) ; ; |
type process_times = Unix . process_times = { tms_utime : float ; tms_stime : float ; tms_cutime : float ; tms_cstime : float } |
type tm = Unix . tm = { tm_sec : int ; tm_min : int ; tm_hour : int ; tm_mday : int ; tm_mon : int ; tm_year : int ; tm_wday : int ; tm_yday : int ; tm_isdst : bool } |
let utimes name ~ access ~ modif = In_thread . syscall_exn ~ name " : utimes " ( fun ( ) -> Unix . utimes name ~ access ~ modif ) ; ; |
type env = Unix . env [ @@ deriving sexp ] |
let fork_exec ~ prog ~ argv ? use_path ? env ( ) = In_thread . run ( fun ( ) -> Unix . fork_exec ~ prog ~ argv ? use_path ? env ( ) ) ; ; |
type wait_on = Unix . wait_on [ @@ deriving sexp_poly ] |
module Wait : sig val check_all : unit -> unit val do_not_handle_sigchld : unit -> unit val waitpid : Pid . t -> Exit_or_signal . t Deferred . t val wait : wait_on -> ( Pid . t * Exit_or_signal . t ) Deferred . t val wait_untraced : wait_on -> ( Pid . t * Exit_or_signal_or_stop . t ) Deferred . t module Kind = struct t... |
let waitpid_exn pid = let % map exit_or_signal = waitpid pid in if Result . is_error exit_or_signal then raise_s [ % message " child process didn ' t exit with status 0 " ~ child_pid ( : pid : Pid . t ) ( exit_or_signal : Exit_or_signal . t ) ] ; ; |
module Inet_addr = struct include Unix . Inet_addr let of_string_or_getbyname s = match of_string s with | t -> Deferred . return t | exception _ -> In_thread . run ( fun ( ) -> of_string_or_getbyname s ) ; ; end |
let bind_to_interface_exn = Or_error . map Linux_ext . bind_to_interface ~ f ( : fun bind_to_interface fd spec -> Fd . with_file_descr_exn fd ( fun file_descr -> bind_to_interface file_descr spec ) ) ; ; |
module Socket = struct module Address = struct module Inet = struct type t = [ ` Inet of Inet_addr . t * int ] [ @@ deriving bin_io , compare , hash ] let to_string_internal ~ show_port_in_test ( ` Inet ( a , p ) ) = sprintf " % s :% s " ( Inet_addr . to_string a ) ( if am_running_inline_test && not show_port_in_test t... |
let socketpair ( ) = let s1 , s2 = Unix . socketpair ~ domain : PF_UNIX ~ kind : SOCK_STREAM ~ protocol : 0 ~ close_on_exec : true ( ) in let make_fd s = Fd . create ( Fd . Kind . Socket ` Active ) s ( Info . of_string " < socketpair " ) > in make_fd s1 , make_fd s2 ; ; |
module Host = struct type t = Unix . Host . t = { name : string ; aliases : string array ; family : Protocol_family . t ; addresses : Inet_addr . t array } let getbyname n = In_thread . syscall_exn ~ name " : gethostbyname " ( fun ( ) -> Unix . Host . getbyname n ) ; ; let getbyname_exn n = In_thread . syscall_exn ~ na... |
type socket_domain = Unix . socket_domain = | PF_UNIX | PF_INET | PF_INET6 |
type socket_type = Unix . socket_type = | SOCK_STREAM | SOCK_DGRAM | SOCK_RAW | SOCK_SEQPACKET |
type sockaddr = Unix . sockaddr = | ADDR_UNIX of string | ADDR_INET of Inet_addr . t * int |
type sockaddr_blocking_sexp = Unix . sockaddr = | ADDR_UNIX of string | ADDR_INET of Inet_addr . Blocking_sexp . t * int |
module Addr_info = struct type t = Unix . addr_info = { ai_family : socket_domain ; ai_socktype : socket_type ; ai_protocol : int ; ai_addr : sockaddr ; ai_canonname : string } [ @@ deriving bin_io , sexp_of ] module Blocking_sexp = struct type t = Unix . addr_info = { ai_family : socket_domain ; ai_socktype : socket_t... |
module Name_info = struct type t = Unix . name_info = { ni_hostname : string ; ni_service : string } [ @@ deriving bin_io , sexp ] type getnameinfo_option = Unix . getnameinfo_option = | NI_NOFQDN | NI_NUMERICHOST | NI_NAMEREQD | NI_NUMERICSERV | NI_DGRAM [ @@ deriving sexp , bin_io ] let get addr options = In_thread .... |
let gethostname ( ) = Unix . gethostname ( ) |
let setuid uid = Unix . setuid uid |
let getuid ( ) = Unix . getuid ( ) |
let getgid ( ) = Unix . getgid ( ) |
let getegid ( ) = Unix . getegid ( ) |
let geteuid ( ) = Unix . geteuid ( ) |
module Terminal_io = struct include Unix . Terminal_io let tcgetattr fd = Fd . syscall_in_thread_exn fd ~ name " : tcgetattr " ( fun file_descr -> tcgetattr file_descr ) ; ; let tcsetattr t fd ~ mode = Fd . syscall_in_thread_exn fd ~ name " : tcsetattr " ( fun file_descr -> tcsetattr t file_descr ~ mode ) ; ; end |
module Passwd = struct type t = Unix . Passwd . t = { name : string ; passwd : string ; uid : int ; gid : int ; gecos : string ; dir : string ; shell : string } [ @@ deriving fields , sexp ] let getbyname n = In_thread . run ( fun ( ) -> Unix . Passwd . getbyname n ) let getbyname_exn n = In_thread . run ( fun ( ) -> U... |
module Group = struct type t = Unix . Group . t = { name : string ; passwd : string ; gid : int ; mem : string array } [ @@ deriving fields , sexp ] let getbyname n = In_thread . run ( fun ( ) -> Unix . Group . getbyname n ) let getbyname_exn n = In_thread . run ( fun ( ) -> Unix . Group . getbyname_exn n ) let getbygi... |
let getlogin ( ) = In_thread . syscall_exn ~ name " : getlogin " ( fun ( ) -> Unix . getlogin ( ) ) |
let getifaddrs ( ) = In_thread . run Unix . getifaddrs |
let wordexp = Or_error . map Unix . wordexp ~ f ( : fun wordexp ? flags glob -> In_thread . syscall_exn ~ name " : wordexp " ( fun ( ) -> wordexp ? flags glob ) ) ; ; |
module Private = struct module Wait = Wait end |
let convert_address address = try let n = String . index address ' ' : in let host = String . sub address 0 n and port = String . sub address ( n + 1 ) ( String . length address - n - 1 ) in ( PF_INET , ADDR_INET ( ( try inet_addr_of_string host with Failure _ -> try ( gethostbyname host ) . h_addr_list . ( 0 ) with No... |
let report_error = function | Unix_error ( err , fun_name , arg ) -> prerr_string " Unix error : ' " ; prerr_string fun_name ; prerr_string " ' failed " ; if String . length arg > 0 then ( prerr_string " on ' " ; prerr_string arg ; prerr_string " ' " ) ; prerr_string " : " ; prerr_endline ( error_message err ) | _ -> f... |
let search_in_path name = Printf . fprintf Real_stdlib . stderr " search_in_path [ % s ] \ n " %! name ; let check name = try access name [ X_OK ] ; name with Unix_error _ -> raise Not_found in if not ( Filename . is_implicit name ) then check name else let path = Sys . getenv " PATH " in let length = String . length p... |
let rec expand_path ch = let rec subst_variable ch = try let pos = String . index ch ' ' $ in if ( pos + 1 < String . length ch ) && ( ch . [ pos + 1 ] = ' ' ) $ then ( String . sub ch 0 ( pos + 1 ) ) ^ ( subst_variable ( String . sub ch ( pos + 2 ) ( String . length ch - pos - 2 ) ) ) else ( String . sub ch 0 pos ) ^ ... |
let make_absolute name = if Filename . is_relative name then Filename . concat ( getcwd ( ) ) name else name ; ; |
let ( ) = Sys . ( set_signal sigpipe Signal_ignore ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.