summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/strfuncs.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2012-07-02 20:17:27 +0000
committerCorinna Vinschen <corinna@vinschen.de>2012-07-02 20:17:27 +0000
commit8fd8f9e72b5732296f54c3dda3fe90d9e0d813e2 (patch)
treeba00f6a89b25654d9d2a827734de7743464b7bba /winsup/cygwin/strfuncs.cc
parentceec584ad39bca6caa6704bde22af58551bb139f (diff)
downloadcygnal-8fd8f9e72b5732296f54c3dda3fe90d9e0d813e2.tar.gz
cygnal-8fd8f9e72b5732296f54c3dda3fe90d9e0d813e2.tar.bz2
cygnal-8fd8f9e72b5732296f54c3dda3fe90d9e0d813e2.zip
* fhandler.h (class fhandler_dev_clipboard): Remove member eof.
* fhandler_clipboard.cc: Throughout remove handling of eof member. (fhandler_dev_clipboard::write): Handle EOF condition immediately, rather than pushing it erroneously to the next read call. Rearrange code. Fix bug in CF_UNICODETEXT case which potentially dropped single bytes at the end of the buffer. Add comment. * strfuncs.cc (sys_cp_wcstombs): Allow returning non-NUL-terminated buffer if dst != NULL and len == (size_t) -1. Extend leading comment to explain what's returned in more detail.
Diffstat (limited to 'winsup/cygwin/strfuncs.cc')
-rw-r--r--winsup/cygwin/strfuncs.cc22
1 files changed, 18 insertions, 4 deletions
diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc
index 467f54e87..22ba4d619 100644
--- a/winsup/cygwin/strfuncs.cc
+++ b/winsup/cygwin/strfuncs.cc
@@ -393,9 +393,23 @@ __big5_mbtowc (struct _reent *r, wchar_t *pwc, const char *s, size_t n,
sequence in by treating it as an UTF-8 char. If that fails, the ASCII
CAN was probably standalone and it gets just copied over as ASCII CAN.
- - The functions always create 0-terminated results, no matter what.
- If the result is truncated due to buffer size, it's a bug in Cygwin
- and the buffer in the calling function should be raised. */
+ - Three cases have to be distinguished for the return value:
+
+ - dst == NULL; len is ignored, the return value is the number of bytes
+ required for the string without the trailing NUL, just like the return
+ value of the wcstombs function.
+
+ - dst != NULL, len == (size_t) -1; the return value is the size in bytes
+ of the destination string without the trailing NUL. If the incoming
+ wide char string was not NUL-terminated, the target string won't be
+ NUL-terminated either.
+
+ - dst != NULL; len != (size_t) -1; the return value is the size in bytes
+ of the destination string without the trailing NUL. The target string
+ will be NUL-terminated, no matter what. If the result is truncated due
+ to buffer size, it's a bug in Cygwin and the buffer in the calling
+ function should be raised.
+*/
size_t __stdcall
sys_cp_wcstombs (wctomb_p f_wctomb, const char *charset, char *dst, size_t len,
const wchar_t *src, size_t nwc)
@@ -473,7 +487,7 @@ sys_cp_wcstombs (wctomb_p f_wctomb, const char *charset, char *dst, size_t len,
else
break;
}
- if (n && dst)
+ if (n && dst && len != (size_t) -1)
{
n = (n < len) ? n : len - 1;
dst[n] = '\0';