]> pd.if.org Git - pdclib/blobdiff - functions/uchar/c16rtomb.c
PDCLib includes with quotes, not <>.
[pdclib] / functions / uchar / c16rtomb.c
index e8f1de780597eb44d4e0b3c6a4356e9bd89f5ba6..bce172bd00ff070a5095d33747ff273d56b8021b 100644 (file)
@@ -1,7 +1,4 @@
-/* c16rtomb(\r
-    char        *restrict   s, \r
-    char16_t                c16,\r
-    mbstate_t   *restrict   ps);\r
+/* c16rtomb( char *, char16_t, mbstate_t * )\r
 \r
    This file is part of the Public Domain C Library (PDCLib).\r
    Permission is granted to use, modify, and / or redistribute at will.\r
@@ -13,8 +10,8 @@
 #include <stdint.h>\r
 #include <assert.h>\r
 #include <stdlib.h>\r
-#include <_PDCLIB_encoding.h>\r
-#include <_PDCLIB_locale.h>\r
+#include "_PDCLIB_encoding.h"\r
+#include "_PDCLIB_locale.h"\r
 \r
 size_t c16rtomb_l(\r
     char        *restrict   s, \r
@@ -24,6 +21,8 @@ size_t c16rtomb_l(
 )\r
 {\r
     const char16_t *restrict psrc = &c16;\r
+    char buf[s ? 0 : MB_CUR_MAX];\r
+    s =      s ? s : buf;\r
 \r
     if(!l->_Codec->__c16stombs) {\r
         // Codec doesn't support direct conversion - translate via UCS-4\r
@@ -58,6 +57,7 @@ size_t c16rtomb_l(
             if((c16 & 0xFC00) == 0xDC00) {\r
                 // Trailing surrogate\r
                 char32_t c32 = (ps->_Surrogate & 0x3FF) << 10 | (c16 & 0x3FF);\r
+                ps->_Surrogate = 0;\r
                 return c32rtomb_l(s, c32, ps, l);\r
             } else {\r
                 // Not a trailing surrogate - encoding error\r
@@ -94,7 +94,7 @@ size_t c16rtomb(
 #endif\r
 \r
 #ifdef TEST\r
-#include <_PDCLIB_test.h>\r
+#include "_PDCLIB_test.h"\r
 \r
 int main( void )\r
 {\r