*)
open ExtString
+open CamomileLibrary
+open Default.Camomile
open Printf
let mklabel text =
(GMisc.label ~text () :> GObj.widget)
-(* XXX No binding for g_markup_escape in lablgtk2. *)
+(* g_markup_escape is not bound by lablgtk2, but we want to provide
+ * extra protection for \0 characters appearing in the string
+ * anyway.
+ *)
let markup_escape name =
let f = function
| '&' -> "&" | '<' -> "<" | '>' -> ">"
+ | '\000' -> "\\0"
| c -> String.make 1 c
in
String.replace_chars f name
and is_xo mode = test_bit 0o001L mode
and test_bit mask mode = Int64.logand mode mask = mask
+
+let tmpdir () =
+ let chan = open_in "/dev/urandom" in
+ let data = String.create 16 in
+ really_input chan data 0 (String.length data);
+ close_in chan;
+ let data = Digest.to_hex (Digest.string data) in
+ (* Note this is secure, because if the name already exists, even as a
+ * symlink, mkdir(2) will fail.
+ *)
+ let tmpdir = Filename.temp_dir_name // sprintf "febootstrap%s.tmp" data in
+ Unix.mkdir tmpdir 0o700;
+ at_exit
+ (fun () ->
+ let cmd = sprintf "rm -rf %s" (Filename.quote tmpdir) in
+ ignore (Sys.command cmd));
+ tmpdir
+
+let utf16le = CharEncoding.utf16le
+let utf8 = CharEncoding.utf8
+let recode = CharEncoding.recode_string ~in_enc:utf16le ~out_enc:utf8
+
+let windows_string_to_utf8 str =
+ let str = recode str in
+
+ (* Windows strings include the final \0 so remove this if present. *)
+ let len = UTF8.length str in
+ if len > 0 && UChar.code (UTF8.get str (len-1)) = 0 then
+ String.sub str 0 (UTF8.last str)
+ else
+ str