annotate lib/mbslen.c @ 8967:5963f8c7f555

Include <stdlib.h>.
author Bruno Haible <bruno@clisp.org>
date Mon, 11 Jun 2007 00:20:36 +0000
parents c534d48f4224
children bbbbbf4cd1c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8126
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Counting the multibyte characters in a string.
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2007.
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 any later version.
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program; if not, write to the Free Software Foundation,
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 /* Specification. */
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <string.h>
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
8967
5963f8c7f555 Include <stdlib.h>.
Bruno Haible <bruno@clisp.org>
parents: 8126
diff changeset
24 #include <stdlib.h>
5963f8c7f555 Include <stdlib.h>.
Bruno Haible <bruno@clisp.org>
parents: 8126
diff changeset
25
8126
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #if HAVE_MBRTOWC
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 # include "mbuiter.h"
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #endif
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* Return the number of multibyte characters in the character string STRING. */
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 size_t
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 mbslen (const char *string)
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 {
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #if HAVE_MBRTOWC
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 if (MB_CUR_MAX > 1)
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 {
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 size_t count;
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 mbui_iterator_t iter;
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 count = 0;
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter))
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 count++;
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 return count;
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 }
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 else
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #endif
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 return strlen (string);
c534d48f4224 New module 'mbslen'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 }