about summary refs log tree commit diff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/mblen.c30
-rw-r--r--stdlib/mbtowc.c24
2 files changed, 34 insertions, 20 deletions
diff --git a/stdlib/mblen.c b/stdlib/mblen.c
index e43b076371..d60a1fb160 100644
--- a/stdlib/mblen.c
+++ b/stdlib/mblen.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -37,17 +37,23 @@ mblen (const char *s, size_t n)
      restartable functions.  We simply say here all encodings have a
      state.  */
   if (s == NULL)
-    return 1;
-
-  state.count = 0;
-  state.value = 0;
-
-  result = __mbrtowc (NULL, s, n, &state);
-
-  /* The `mbrtowc' functions tell us more than we need.  Fold the -1
-     and -2 result into -1.  */
-  if (result < 0)
-    result = -1;
+    result = 1;
+  else if (*s == '\0')
+    /* According to the ISO C 89 standard this is the expected behaviour.
+       Idiotic, but true.  */
+    result = 0;
+  else
+    {
+      state.count = 0;
+      state.value = 0;
+
+      result = __mbrtowc (NULL, s, n, &state);
+
+      /* The `mbrtowc' functions tell us more than we need.  Fold the -1
+	 and -2 result into -1.  */
+      if (result < 0)
+	result = -1;
+    }
 
   return result;
 }
diff --git a/stdlib/mbtowc.c b/stdlib/mbtowc.c
index 61b46f882e..50e7c09834 100644
--- a/stdlib/mbtowc.c
+++ b/stdlib/mbtowc.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 92, 95, 96, 97, 98 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -43,14 +43,22 @@ mbtowc (wchar_t *pwc, const char *s, size_t n)
      restartable functions.  We simply say here all encodings have a
      state.  */
   if (s == NULL)
-    return 1;
+    result = 1;
+  else if (*s == '\0')
+    {
+      if (pwc != NULL)
+	*pwc = L'\0';
+      result = 0;
+    }
+  else
+    {
+      result = __mbrtowc (pwc, s, n, &__no_r_state);
 
-  result = __mbrtowc (pwc, s, n, &__no_r_state);
-
-  /* The `mbrtowc' functions tell us more than we need.  Fold the -1
-     and -2 result into -1.  */
-  if (result < 0)
-    result = -1;
+      /* The `mbrtowc' functions tell us more than we need.  Fold the -1
+	 and -2 result into -1.  */
+      if (result < 0)
+	result = -1;
+    }
 
   return result;
 }