This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin] Cygwin: add transform_chars_af_unix helper


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7d260cfac42db6af3a1c8dd5f1f27491d3963371

commit 7d260cfac42db6af3a1c8dd5f1f27491d3963371
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Fri Mar 2 18:11:57 2018 +0100

    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 <corinna@vinschen.de>

Diff:
---
 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 3960b54..8ad9643 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 e0e5703..e0a4c71 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]