From bdbddd2c25687c1bf658be6835f8b12b0c99704d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Thu, 17 Aug 2023 13:27:56 +0200 Subject: [PATCH] expose procedure for copying environment --- otherlibs/unix/createprocess.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/otherlibs/unix/createprocess.c b/otherlibs/unix/createprocess.c index 132944b37ec0..167196b4e9d7 100644 --- a/otherlibs/unix/createprocess.c +++ b/otherlibs/unix/createprocess.c @@ -99,6 +99,22 @@ static DWORD do_create_process_native(wchar_t * exefile, wchar_t * cmdline, return err; } +void copy_env(value env, wchar_t * wenv) +{ + if (Is_some(env)) { + env = Some_val(env); + size = + caml_win32_multi_byte_to_wide_char(String_val(env), + caml_string_length(env), NULL, 0); + wenv = caml_stat_alloc((size + 1)*sizeof(wchar_t)); + caml_win32_multi_byte_to_wide_char(String_val(env), + caml_string_length(env), wenv, size); + wenv[size] = 0; + } else { + wenv = NULL; + } +} + value caml_unix_create_process_native(value cmd, value cmdline, value env, value fd1, value fd2, value fd3) { @@ -117,18 +133,7 @@ value caml_unix_create_process_native(value cmd, value cmdline, value env, caml_stat_free(wcmd); wcmdline = caml_stat_strdup_to_utf16(String_val(cmdline)); - if (Is_some(env)) { - env = Some_val(env); - size = - caml_win32_multi_byte_to_wide_char(String_val(env), - caml_string_length(env), NULL, 0); - wenv = caml_stat_alloc((size + 1)*sizeof(wchar_t)); - caml_win32_multi_byte_to_wide_char(String_val(env), - caml_string_length(env), wenv, size); - wenv[size] = 0; - } else { - wenv = NULL; - } + copy_env(env, wenv); err = do_create_process_native(exefile, wcmdline, wenv, Handle_val(fd1),