aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin/wchar.h
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2022-08-05 11:45:49 +0200
committerCorinna Vinschen <corinna@vinschen.de>2022-08-05 11:45:49 +0200
commitd097a96e6e5319ab622d5d737c70b21e4a231bec (patch)
tree9cb5ad3d5af57c4114a8ffa314f9f98f329b2004 /winsup/cygwin/wchar.h
parent249f42d07a447ceb6fe22db5a2570f913cb5b4e5 (diff)
downloadnewlib-d097a96e6e5319ab622d5d737c70b21e4a231bec.zip
newlib-d097a96e6e5319ab622d5d737c70b21e4a231bec.tar.gz
newlib-d097a96e6e5319ab622d5d737c70b21e4a231bec.tar.bz2
Cygwin: drop last usage of RtlCreateUnicodeStringFromAsciiz
This function is just bad. It really only works for ASCII chars, everything else is broken after the conversion. Introduce new helper function sys_mbstouni to replace RtlCreateUnicodeStringFromAsciiz in hash_path_name. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'winsup/cygwin/wchar.h')
-rw-r--r--winsup/cygwin/wchar.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/winsup/cygwin/wchar.h b/winsup/cygwin/wchar.h
index ff1d4f1..0484b27 100644
--- a/winsup/cygwin/wchar.h
+++ b/winsup/cygwin/wchar.h
@@ -92,9 +92,21 @@ sys_mbstowcs (wchar_t * dst, size_t dlen, const char *src,
size_t sys_mbstowcs_alloc (wchar_t **, int, const char *, size_t = (size_t) -1);
static inline size_t
+sys_mbstouni (PUNICODE_STRING dst, int type, const char *src,
+ size_t nms = (size_t) -1)
+{
+ /* sys_mbstowcs returns length *excluding* trailing \0 */
+ size_t len = sys_mbstowcs (dst->Buffer, type, src, nms);
+ dst->Length = len * sizeof (WCHAR);
+ dst->MaximumLength = dst->Length + sizeof (WCHAR);
+ return dst->Length;
+}
+
+static inline size_t
sys_mbstouni_alloc (PUNICODE_STRING dst, int type, const char *src,
size_t nms = (size_t) -1)
{
+ /* sys_mbstowcs returns length *including* trailing \0 */
size_t len = sys_mbstowcs_alloc (&dst->Buffer, type, src, nms);
dst->MaximumLength = len * sizeof (WCHAR);
dst->Length = dst->MaximumLength - sizeof (WCHAR);