Thu Mar 28 18:32:34 1996 Roland McGrath <roland@whiz-bang.gnu.ai.mit.edu>
[glibc.git] / wcsmbs / mbscmp.c
blob04f6f473b92aa5aeba56272df1da7c918689eef2
1 /* Copyright (C) 1995 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #include <mbstr.h>
20 #include <stdlib.h>
22 #define __need_wchar_t
23 /* FIXME: should be defined in stddef.h.
24 !!! #define __need_uwchar_t */
25 typedef unsigned int uwchar_t;
26 #include <stddef.h>
29 /* Compare MBS1 and MBS2. */
30 int
31 mbscmp (mbs1, mbs2)
32 const char *mbs1;
33 const char *mbs2;
35 int len1 = 0;
36 int len2 = 0;
37 uwchar_t c1;
38 uwchar_t c2;
40 /* Reset multibyte characters to their initial state. */
41 (void) mblen ((char *) NULL, 0);
45 len1 = mbtowc ((wchar_t *) &c1, mbs1, MB_CUR_MAX);
46 len2 = mbtowc ((wchar_t *) &c2, mbs2, MB_CUR_MAX);
48 if (len1 == 0)
49 return len2 == 0 ? 0 : -1;
50 if (len2 == 0)
51 return 1;
52 if (len1 < 0 || len2 < 0)
53 /* FIXME: an illegal character appears. What to do? */
54 return c1 - c2;
56 mbs1 += len1;
57 mbs2 += len2;
59 while (c1 == c2);
61 return c1 - c2;