Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2010-05-26 20:58:44 +0400
committerCorinna Vinschen <corinna@vinschen.de>2010-05-26 20:58:44 +0400
commit88addc64769772c3468fd23787068a5147513fa2 (patch)
tree47f158f3674de337ab085efca60526059baab289 /winsup/cygwin/fhandler_registry.cc
parentfca8f35f1133a9442f3301aef613e7d79ee3a343 (diff)
* fhandler_registry.cc (multi_wcstombs): New function.
(fhandler_registry::fstat): Call multi_wcstombs for strings of type REG_MULTI_SZ. (fhandler_registry::fill_filebuf): Ditto.
Diffstat (limited to 'winsup/cygwin/fhandler_registry.cc')
-rw-r--r--winsup/cygwin/fhandler_registry.cc50
1 files changed, 45 insertions, 5 deletions
diff --git a/winsup/cygwin/fhandler_registry.cc b/winsup/cygwin/fhandler_registry.cc
index 9f8e9af97..9c68b2cdd 100644
--- a/winsup/cygwin/fhandler_registry.cc
+++ b/winsup/cygwin/fhandler_registry.cc
@@ -230,6 +230,37 @@ key_exists (HKEY parent, const wchar_t *name, DWORD wow64)
return (error == ERROR_SUCCESS || error == ERROR_ACCESS_DENIED);
}
+static size_t
+multi_wcstombs (char *dst, size_t len, const wchar_t *src, size_t nwc)
+{
+ size_t siz, sum = 0;
+ const wchar_t *nsrc;
+
+ while (nwc)
+ {
+ siz = sys_wcstombs (dst, len, src, nwc);
+ sum += siz;
+ if (dst)
+ {
+ dst += siz;
+ len -= siz;
+ }
+ nsrc = wcschr (src, L'\0') + 1;
+ if ((size_t) (nsrc - src) >= nwc)
+ break;
+ nwc -= nsrc - src;
+ src = nsrc;
+ if (*src == L'\0')
+ {
+ if (dst)
+ *dst++ = '\0';
+ ++sum;
+ break;
+ }
+ }
+ return sum;
+}
+
/* Returns 0 if path doesn't exist, >0 if path is a directory,
* <0 if path is a file.
*
@@ -456,11 +487,16 @@ fhandler_registry::fstat (struct __stat64 *buf)
NULL, NULL, tmpbuf, &dwSize)
!= ERROR_SUCCESS)
buf->st_size = dwSize / sizeof (wchar_t);
+ else if (type == REG_MULTI_SZ)
+ buf->st_size = multi_wcstombs (NULL, 0,
+ (wchar_t *) tmpbuf,
+ dwSize / sizeof (wchar_t));
else
buf->st_size = sys_wcstombs (NULL, 0,
(wchar_t *) tmpbuf,
dwSize / sizeof (wchar_t));
- free (tmpbuf);
+ if (tmpbuf)
+ free (tmpbuf);
}
else
buf->st_size = dwSize;
@@ -848,17 +884,21 @@ fhandler_registry::fill_filebuf ()
seterrno_from_win_error (__FILE__, __LINE__, error);
return true;
}
- if (type == REG_SZ || type == REG_EXPAND_SZ || type == REG_MULTI_SZ
- || type == REG_LINK)
+ if (type == REG_SZ || type == REG_EXPAND_SZ || type == REG_LINK)
bufalloc = sys_wcstombs (NULL, 0, (wchar_t *) tmpbuf,
size / sizeof (wchar_t));
+ else if (type == REG_MULTI_SZ)
+ bufalloc = multi_wcstombs (NULL, 0, (wchar_t *) tmpbuf,
+ size / sizeof (wchar_t));
else
bufalloc = size;
filebuf = (char *) cmalloc_abort (HEAP_BUF, bufalloc);
- if (type == REG_SZ || type == REG_EXPAND_SZ || type == REG_MULTI_SZ
- || type == REG_LINK)
+ if (type == REG_SZ || type == REG_EXPAND_SZ || type == REG_LINK)
sys_wcstombs (filebuf, bufalloc, (wchar_t *) tmpbuf,
size / sizeof (wchar_t));
+ else if (type == REG_MULTI_SZ)
+ multi_wcstombs (filebuf, bufalloc, (wchar_t *) tmpbuf,
+ size / sizeof (wchar_t));
else
memcpy (filebuf, tmpbuf, bufalloc);
filesize = bufalloc;