diff options
Diffstat (limited to 'stdlib/mblen.c')
-rw-r--r-- | stdlib/mblen.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/stdlib/mblen.c b/stdlib/mblen.c index e43b076..d60a1fb 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; } |