From 7d260cfac42db6af3a1c8dd5f1f27491d3963371 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 2 Mar 2018 18:11:57 +0100 Subject: [PATCH] Cygwin: add transform_chars_af_unix helper This function is going to be used for transposing sun_path of abstract sockets. This also adds a transposition of the NUL character to tfx_chars since NUL-bytes in abstract socket names are perfectly valid. Signed-off-by: Corinna Vinschen --- winsup/cygwin/miscfuncs.h | 2 ++ winsup/cygwin/strfuncs.cc | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/winsup/cygwin/miscfuncs.h b/winsup/cygwin/miscfuncs.h index 3960b5429..8ad9643a3 100644 --- a/winsup/cygwin/miscfuncs.h +++ b/winsup/cygwin/miscfuncs.h @@ -96,6 +96,8 @@ transform_chars (PUNICODE_STRING upath, USHORT start_idx) upath->Buffer + upath->Length / sizeof (WCHAR) - 1); } +PWCHAR transform_chars_af_unix (PWCHAR, const char *, __socklen_t); + /* Memory checking */ int __reg2 check_invalid_virtual_addr (const void *s, unsigned sz); diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc index e0e5703d3..e0a4c7182 100644 --- a/winsup/cygwin/strfuncs.cc +++ b/winsup/cygwin/strfuncs.cc @@ -22,7 +22,7 @@ details. */ is affected as well, but we can't transform it as long as we accept Win32 paths as input. */ static const WCHAR tfx_chars[] = { - 0, 0xf000 | 1, 0xf000 | 2, 0xf000 | 3, + 0xf000 | 0, 0xf000 | 1, 0xf000 | 2, 0xf000 | 3, 0xf000 | 4, 0xf000 | 5, 0xf000 | 6, 0xf000 | 7, 0xf000 | 8, 0xf000 | 9, 0xf000 | 10, 0xf000 | 11, 0xf000 | 12, 0xf000 | 13, 0xf000 | 14, 0xf000 | 15, @@ -61,7 +61,7 @@ static const WCHAR tfx_chars[] = { converting back space and dot on filesystems only supporting DOS filenames. */ static const WCHAR tfx_rev_chars[] = { - 0, 0xf000 | 1, 0xf000 | 2, 0xf000 | 3, + 0xf000 | 0, 0xf000 | 1, 0xf000 | 2, 0xf000 | 3, 0xf000 | 4, 0xf000 | 5, 0xf000 | 6, 0xf000 | 7, 0xf000 | 8, 0xf000 | 9, 0xf000 | 10, 0xf000 | 11, 0xf000 | 12, 0xf000 | 13, 0xf000 | 14, 0xf000 | 15, @@ -103,6 +103,15 @@ transform_chars (PWCHAR path, PWCHAR path_end) *path = tfx_chars[*path]; } +PWCHAR +transform_chars_af_unix (PWCHAR out, const char *path, __socklen_t len) +{ + len -= sizeof (__sa_family_t); + for (const unsigned char *p = (const unsigned char *) path; len-- > 0; ++p) + *out++ = (*p <= 0x7f) ? tfx_chars[*p] : *p; + return out; +} + /* The SJIS, JIS and eucJP conversion in newlib does not use UTF as wchar_t character representation. That's unfortunate for us since we require UTF for the OS. What we do here is to have our own