about summary refs log tree commit diff
path: root/stdlib/mblen.c
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/mblen.c')
-rw-r--r--stdlib/mblen.c30
1 files changed, 18 insertions, 12 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;
 }