]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/LibC/Locale/multibyte_sb.c
Add Socket Libraries.
[mirror_edk2.git] / StdLib / LibC / Locale / multibyte_sb.c
index 6d57cd6c0972390fb88bc644878d8a2955b420f2..0a73898e6190aca8674efd093918709cb6fc08e0 100644 (file)
@@ -137,7 +137,7 @@ wcrtomb(
   /* ps appears to be unused */\r
 \r
   if (s == NULL)\r
-    return 0;\r
+    return 1;     /* Spec. says this should be 1. */\r
 \r
   *s = (char) wchar;\r
   return 1;\r
@@ -150,7 +150,12 @@ wctomb(
   )\r
 {\r
 \r
-  /* s may be NULL */\r
+  /*\r
+    If s is NULL just return if MB Characters have state\r
+    dependent encodings.\r
+  */\r
+  if (s == NULL)\r
+    return 0;\r
 \r
   return (int)wcrtomb(s, wchar, NULL);\r
 }\r
@@ -176,8 +181,10 @@ mbsrtowcs(
   if (n != 0) {\r
     if (pwcs != NULL) {\r
       do {\r
-        if ((*pwcs++ = (wchar_t) *(*s)++) == 0)\r
+        if ((*pwcs++ = (wchar_t) *(*s)++) == 0) {\r
+          *s = NULL;\r
           break;\r
+        }\r
         count++;\r
       } while (--n != 0);\r
     } else {\r
@@ -232,8 +239,10 @@ wcsrtombs(
 \r
   if (n != 0) {\r
     do {\r
-      if ((*s++ = (char) *(*pwcs)++) == 0)\r
+      if ((*s++ = (char) *(*pwcs)++) == 0) {\r
+        *pwcs = NULL;\r
         break;\r
+      }\r
       count++;\r
     } while (--n != 0);\r
   }\r
@@ -266,7 +275,13 @@ btowc(int c)
 int\r
 wctob(wint_t c)\r
 {\r
-  if (c == WEOF || c & ~0xFF)\r
+  /*  wctob needs to be consistent with wcrtomb.\r
+      if wcrtomb says that a character is representable in 1 byte,\r
+      which this implementation always says, then wctob needs to\r
+      also represent the character as 1 byte.\r
+  */\r
+  if (c == WEOF) {\r
     return EOF;\r
-  return (int)c;\r
+  }\r
+  return (int)(c & 0xFF);\r
 }\r