Skip to content

Commit

Permalink
Add umask get/set. Fixes: #2840
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Feb 23, 2023
1 parent 275b265 commit 6557ff5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/core/builtins/builtins_files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,29 @@ let _ =
with exn ->
let bt = Printexc.get_raw_backtrace () in
Lang.raise_as_runtime ~bt ~kind:"file" exn)

let () =
if not Sys.win32 then (
let umask_m = Mutex.create () in
let get_umask =
Tutils.mutexify umask_m (fun () ->
let umask = Unix.umask 0 in
ignore (Unix.umask umask);
umask)
in
let set_umask =
Tutils.mutexify umask_m (fun umask -> ignore (Unix.umask umask))
in
let umask =
Lang.add_builtin ~base:file "umask" ~category:`File
~descr:"Get the process's file mode creation mask." [] Lang.int_t
(fun _ -> Lang.int (get_umask ()))
in
ignore
(Lang.add_builtin ~base:umask "set" ~category:`File
~descr:"Set process's file mode creation mask."
[("", Lang.int_t, None, None)]
Lang.unit_t
(fun p ->
set_umask (Lang.to_int (List.assoc "" p));
Lang.unit)))

0 comments on commit 6557ff5

Please sign in to comment.