7 | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
8 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
11 let tempfailureretry f
a =
13 try f
a with Unix.Unix_error
(Unix.EINTR
, _
, _
) -> g ()
17 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
18 external hasdata
: Unix.file_descr
-> bool = "ml_hasdata";;
19 external toutf8
: int -> string = "ml_keysymtoutf8";;
20 external mbtoutf8
: string -> string = "ml_mbtoutf8";;
21 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
22 external platform
: unit -> platform
= "ml_platform";;
24 let now = Unix.gettimeofday
;;
25 let platform = platform ();;
26 let dolog fmt
= Format.kprintf prerr_endline fmt
;;
29 | Unix.Unix_error
(e
, s, a) -> Printf.sprintf
"%s(%s) : %s (%d)"
30 s a (Unix.error_message e
) (Obj.magic e
)
31 | exn
-> Printexc.to_string exn
;
34 let error fmt
= Printf.kprintf failwith fmt
;;
36 module IntSet
= Set.Make
(struct type t
= int let compare = (-) end);;
38 let emptystr s = String.length
s = 0;;
39 let nonemptystr s = String.length
s > 0;;
40 let bound v minv maxv
= max minv
(min maxv v
);;
46 let args = [|sh; "-c"; cmd
|] in
47 let rec std si so se
= function
49 | (fd
, 0) :: rest
-> std fd so se rest
51 Unix.set_close_on_exec fd
;
54 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
56 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
57 ignore
(Unix.create_process
sh args si so se
)
64 type t
= private string
65 val of_string
: string -> t
66 val to_string
: t
-> string
76 let (~
<) = Opaque.of_string;;
77 let (~
>) = Opaque.to_string;;
79 let int_of_string_with_suffix s =
80 let l = String.length
s in
84 let suffix = Char.lowercase
s.[l-1] in
86 | 'k'
-> String.sub
s 0 (l-1), 10
87 | 'm'
-> String.sub
s 0 (l-1), 20
88 | '
g'
-> String.sub
s 0 (l-1), 30
92 let n = int_of_string
s1 in
93 let m = n lsl shift
in
95 then raise
(Failure
"value too large")
99 let string_with_suffix_of_int n =
103 let units = [(30, "G"); (20, "M"); (10, "K")] in
106 let h = n mod 1000 in
109 then string_of_int
h ^
s
111 let s = Printf.sprintf
"_%03d%s" h s in
117 let rec find = function
119 | (shift
, suffix) :: rest
->
120 if (n land ((1 lsl shift
) - 1)) = 0
121 then prettyint (n lsr shift
) ^
suffix
127 let color_of_string s =
128 Scanf.sscanf
s "%d/%d/%d" (fun r
g b
->
129 (float r
/. 256.0, float g /. 256.0, float b
/. 256.0)
133 let color_to_string (r
, g, b
) =
134 let r = truncate
(r *. 256.0)
135 and g = truncate
(g *. 256.0)
136 and b
= truncate
(b
*. 256.0) in
137 Printf.sprintf
"%d/%d/%d" r g b
141 if Filename.is_relative path
143 let cwd = Sys.getcwd
() in
144 if Filename.is_implicit path
145 then Filename.concat
cwd path
146 else Filename.concat
cwd (Filename.basename path
)
157 type '
a t
= | Res
of '
a | Exn
of exn
;;
165 try tempfailureretry Unix.close fd
166 with exn
-> f
(exntos exn
)
170 try Res
(tempfailureretry Unix.dup fd
)
175 try Res
(tempfailureretry (Unix.dup2 fd1
) fd2
)
180 let getenvwithdef name def
=
183 with Not_found
-> def