[newlib-cygwin/main] Cygwin: add wcipcpy and wcipncpy helper functions

Corinna Vinschen corinna@sourceware.org
Wed Mar 1 09:55:26 GMT 2023


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

commit b81969345d807ec299d8afb3c55e27f732b7cb06
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Wed Mar 1 10:36:09 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Mar 1 10:54:52 2023 +0100

    Cygwin: add wcipcpy and wcipncpy helper functions
    
    wint_t replacements for wcpcpy and wcpncpy
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/glob.cc                |  9 +++------
 winsup/cygwin/local_includes/wchar.h | 30 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/glob.cc b/winsup/cygwin/glob.cc
index 0b85a147acb7..dadc67e4c10a 100644
--- a/winsup/cygwin/glob.cc
+++ b/winsup/cygwin/glob.cc
@@ -203,13 +203,10 @@ check_classes_expr(const Char *&cptr, wint_t *classbuf = NULL,
 		if (classbuf) {
 			const Char *class_p = ctype + 1;
 			size_t clen = cptr - class_p;
-			size_t idx;
 
-			if (clen < classbufsize) {
-				for (idx = 0; idx < clen; ++idx)
-				    classbuf[idx] = CHAR(class_p[idx]);
-				classbuf[idx] = '\0';
-			} else
+			if (clen < classbufsize)
+				*wcipncpy (classbuf, class_p, clen) = '\0';
+			else
 				ctype = NULL;
 		}
 		cptr++; /* Advance cptr to closing RBRACKET of class expr */
diff --git a/winsup/cygwin/local_includes/wchar.h b/winsup/cygwin/local_includes/wchar.h
index b09d014c04df..125e49ece15c 100644
--- a/winsup/cygwin/local_includes/wchar.h
+++ b/winsup/cygwin/local_includes/wchar.h
@@ -101,6 +101,36 @@ wcincmp (const wint_t *s1, const wint_t *s2, size_t n)
   return (0);
 }
 
+/* like wcpcpy, just for wint_t */
+static inline wint_t *
+wcipcpy (wint_t *s1, const wint_t *s2)
+{
+  while ((*s1++ = *s2++))
+    ;
+  return --s1;
+}
+
+/* like wcpncpy, just for wint_t */
+static inline wint_t *
+wcipncpy (wint_t *dst, const wint_t *src, size_t count)
+{
+  wint_t *ret = NULL;
+
+  while (count > 0)
+    {
+      --count;
+      if ((*dst++ = *src++) == L'\0')
+        {
+          ret = dst - 1;
+          break;
+        }
+    }
+  while (count-- > 0)
+    *dst++ = L'\0';
+
+  return ret ? ret : dst;
+}
+
 #ifdef __cplusplus
 }
 #endif


More information about the Cygwin-cvs mailing list