Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Mar 1997 15:37:12 -0500
From:      Chet Ramey <chet@odin.INS.CWRU.Edu>
To:        freebsd-hackers@freebsd.org
Cc:        chet@odin.INS.CWRU.Edu
Subject:   Problem with strcoll in FreeBSD 2.1.7
Message-ID:  <9703172037.AA28815.SM@odin.INS.CWRU.Edu>

next in thread | raw e-mail | index | archive | help
Hi.  I'm puzzled by the following results, and I'm wondering if there's a
bug in strcoll(3) or if I'm misunderstanding things.

Given the following program:

#include <stdio.h>
#include <locale.h>
#include <string.h>

void
testcoll(s1, s2)
char    *s1, *s2;
{
        int r1, r2;

        r1 = strcoll(s1, s2);
        r2 = strcmp(s1, s2);

        printf ("strcoll(%s, %s) -> %d\n", s1, s2, r1);
        printf ("strcmp(%s, %s) -> %d\n", s1, s2, r2);
}

main(c, v)
int     c;
char    *v[];
{
        char    *deflocale, *defcoll;
        char    xf1[16], xf2[16];

        deflocale = setlocale(LC_ALL, (char *)NULL);
        defcoll = setlocale(LC_COLLATE, (char *)NULL);

        printf ("default locale: %s\n", deflocale);
        printf ("default collation order: %s\n", defcoll);
        testcoll (v[1], v[2]);

        strxfrm(xf1, v[1], 16);
        strxfrm(xf2, v[2], 16);

        printf ("%s locale, after strxfrm:\n", deflocale);
        testcoll(xf1, xf2);

        setlocale (LC_ALL, "POSIX");
        setlocale (LC_COLLATE, "POSIX");

        printf ("POSIX locale:\n");
        printf ("POSIX collation order:\n");
        testcoll(v[1], v[2]);

        strxfrm(xf1, v[1], 16);
        strxfrm(xf2, v[2], 16);

        printf ("POSIX locale, after strxfrm:\n");
        testcoll(xf1, xf2);

        exit (0);
}

I get the following output, which seems strange:

bash$ ./x1 abd aXd
default locale: C
default collation order: C
strcoll(abd, aXd) -> -22
strcmp(abd, aXd) -> 10
C locale, after strxfrm:
strcoll(abd, aXd) -> -22
strcmp(abd, aXd) -> 10
POSIX locale:
POSIX collation order:
strcoll(abd, aXd) -> -22
strcmp(abd, aXd) -> 10
POSIX locale, after strxfrm:
strcoll(abd, aXd) -> -22
strcmp(abd, aXd) -> 10

Shouldn't both strcoll(3) and strcmp(3) return values > 0?

Thanks for any help.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, Case Western Reserve University	Internet: chet@po.CWRU.Edu



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9703172037.AA28815.SM>