strxfrm and man

Nikita Shulga shulga@jscc.ru
Wed Nov 8 08:36:00 GMT 2006


Hi,

strxfrm man page said that return value are number of bytes required  
to store transformed string excluding terminating \0’ character.
But this is not always true - if third argument is less then number  
of bytes required  to store results and locale is,for example,  
"en_US.utf8"
than return value is length of transformed string including  
terminating character, but if locale is C or POSIX it behaves as  
described in man-page.
For example, strxfrm(NULL,"a",0)<>strxfrm(buf,"a",10) for  
"en_US.utf8" locale, but return values are equal if locale is "C".

Do you think it's OK? Or bug report should be filed to glibc bugzilla?

Program listed below demonstrates this peculiar behavior of stfxrm:

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

void chkxfrmlen(char *str) {
         int len,newlen;
         char *buf;

         len = strxfrm( NULL,str,0 );
         buf = ( char * ) malloc ( 2*len );
         newlen = strxfrm( buf,str,2*len );
         if ( len != newlen ) {
                 printf ( "strxfrm(NULL,\"%s\",0)\t=%d\n", str, len );
                 printf ( "strxfrm(buf,\"%s\",%d)\t=%d\n", str,  
2*len, newlen );
         }
	free ( buf );
}

int main ( void ) {
         printf ( "For C locale\n" );
         setlocale( LC_COLLATE, "C" );
         chkxfrmlen( "ab" );
         printf ( "For en_US.utf8 locale\n" );
         setlocale ( LC_COLLATE, "en_US.utf8" );
         chkxfrmlen( "ab" );
         printf ( "For en_US.iso8859 locale\n" );
         setlocale( LC_COLLATE, "en_US.iso88591" );
         chkxfrmlen( "ab" );
         return 0;
}



Best,
    Nikita
P.S. I checked that against glibc 2.5, 2.4 and 2.3.5



More information about the Libc-alpha mailing list