[newlib-cygwin] Cygwin: path_conv: add serialization/deserialization facility

Corinna Vinschen corinna@sourceware.org
Sun Jan 6 19:42:00 GMT 2019


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

commit 91b264c76c34290a31b14844e59bac0deeb62afd
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Sat Jan 5 21:50:48 2019 +0100

    Cygwin: path_conv: add serialization/deserialization facility
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/path.cc | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++
 winsup/cygwin/path.h  |  3 +++
 2 files changed, 67 insertions(+)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 563ba0e..df11d53 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -1258,6 +1258,70 @@ path_conv::check (const char *src, unsigned opt,
   __endtry
 }
 
+struct pc_flat
+{
+  path_conv pc;
+  HANDLE hdl;
+  size_t name_len;
+  size_t posix_len;
+  char data[0];
+};
+
+void *
+path_conv::serialize (HANDLE h, unsigned int &n) const
+{
+  pc_flat *pcf;
+  size_t nlen = 0, plen = 0;
+  char *p;
+
+  if (path)
+    nlen = strlen (path) + 1;
+  if (posix_path)
+    plen = strlen (posix_path) + 1;
+  n = sizeof (pc_flat) + nlen + plen;
+  pcf = (pc_flat *) cmalloc (HEAP_COMMUNE, n);
+  if (!pcf)
+    {
+      n = 0;
+      return NULL;
+    }
+  memcpy (&pcf->pc, this, sizeof *this);
+  pcf->hdl = h;
+  pcf->name_len = nlen;
+  pcf->posix_len = plen;
+  p = pcf->data;
+  if (nlen)
+    p = stpcpy (p, path) + 1;
+  if (plen)
+    stpcpy (p, posix_path);
+  return pcf;
+}
+
+HANDLE
+path_conv::deserialize (void *bufp)
+{
+  pc_flat *pcf = (pc_flat *) bufp;
+  char *p;
+  HANDLE ret;
+
+  memcpy (this, &pcf->pc, sizeof *this);
+  wide_path = uni_path.Buffer = NULL;
+  uni_path.MaximumLength = uni_path.Length = 0;
+  path = posix_path = NULL;
+  p = pcf->data;
+  if (pcf->name_len)
+    {
+      set_path (p);
+      p += pcf->name_len;
+    }
+  if (pcf->posix_len)
+    set_posix (p);
+  dev.parse (pcf->pc.dev);
+  ret = pcf->hdl;
+  cfree (bufp);
+  return ret;
+}
+
 path_conv::~path_conv ()
 {
   if (posix_path)
diff --git a/winsup/cygwin/path.h b/winsup/cygwin/path.h
index b244b57..1e3095e 100644
--- a/winsup/cygwin/path.h
+++ b/winsup/cygwin/path.h
@@ -160,6 +160,9 @@ class path_conv
   int error;
   device dev;
 
+  void *serialize (HANDLE, unsigned int &) const;
+  HANDLE deserialize (void *);
+
   const char *known_suffix () { return suffix; }
   bool isremote () const {return fs.is_remote_drive ();}
   ULONG objcaseinsensitive () const {return caseinsensitive;}



More information about the Cygwin-cvs mailing list