From d543ef00f4a532aa1a2e423d85f59e93f95b2f4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?=
 <grubba@grubba.org>
Date: Fri, 7 Feb 2020 11:20:47 +0100
Subject: [PATCH] I/O [NT]: Added low_dwim_utf8_to_utf16().

This is needed when converting strings containing NUL characters
(eg the environment block).
---
 src/fdlib.c | 8 ++++++--
 src/fdlib.h | 1 +
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/fdlib.c b/src/fdlib.c
index 10c3af68ca..6e34aceb77 100644
--- a/src/fdlib.c
+++ b/src/fdlib.c
@@ -906,7 +906,7 @@ static int IsUncRoot(const p_wchar1 *path)
   return 0 ;
 }
 
-PMOD_EXPORT p_wchar1 *pike_dwim_utf8_to_utf16(const p_wchar0 *str)
+p_wchar1 *low_dwim_utf8_to_utf16(const p_wchar0 *str, size_t len)
 {
   /* NB: Maximum expansion factor is 2.
    *
@@ -919,7 +919,6 @@ PMOD_EXPORT p_wchar1 *pike_dwim_utf8_to_utf16(const p_wchar0 *str)
    * NB: Some extra padding at the end for NUL and adding
    *     of terminating slashes, etc.
    */
-  size_t len = strlen(str);
   p_wchar1 *res = malloc((len + 4) * sizeof(p_wchar1));
   size_t i = 0, j = 0;
 
@@ -979,6 +978,11 @@ PMOD_EXPORT p_wchar1 *pike_dwim_utf8_to_utf16(const p_wchar0 *str)
   return res;
 }
 
+PMOD_EXPORT p_wchar1 *pike_dwim_utf8_to_utf16(const p_wchar0 *str)
+{
+  return low_dwim_utf8_to_utf16(str, strlen(str));
+}
+
 PMOD_EXPORT p_wchar0 *pike_utf16_to_utf8(const p_wchar1 *str)
 {
   /* NB: Maximum expansion factor is 1.5.
diff --git a/src/fdlib.h b/src/fdlib.h
index 2d04cde6cd..39a1a29017 100644
--- a/src/fdlib.h
+++ b/src/fdlib.h
@@ -169,6 +169,7 @@ PMOD_EXPORT char *debug_fd_info(int fd);
 PMOD_EXPORT int debug_fd_query_properties(int fd, int guess);
 void fd_init(void);
 void fd_exit(void);
+p_wchar1 *low_dwim_utf8_to_utf16(const p_wchar0 *str, size_t len);
 PMOD_EXPORT p_wchar1 *pike_dwim_utf8_to_utf16(const p_wchar0 *str);
 PMOD_EXPORT p_wchar0 *pike_utf16_to_utf8(const p_wchar1 *str);
 PMOD_EXPORT int debug_fd_stat(const char *file, PIKE_STAT_T *buf);
-- 
GitLab