[Previous] [Contents] [Next]

strxfrm()

Transform one string into another, to a given length

Synopsis:

#include <string.h>

size_t strxfrm( char* dst,
                const char* src,
                size_t n );

Library:

libc

Description:

The strxfrm() function transforms, for no more than n characters, the string pointed to by src to the buffer pointed to by dst. The transformation uses the collating sequence selected by setlocale() so that two transformed strings compare identically (using the strncmp() function) to a comparison of the original two strings using strcoll().

The function is equivalent to the strncpy() function (except there's no padding of the dst argument with null characters when the argument src is shorter than n characters) when the collating sequence is selected from the "C" locale.

Returns:

The length of the transformed string. If this length is more than n, the contents of the array pointed to by dst are indeterminate.

Examples:

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

char src[] = { "A sample STRING" };
char dst[20];

int main( void )
  {
    size_t len;

    setlocale( LC_ALL, "C" );
    printf( "%s\n", src );
    len = strxfrm( dst, src, 20 );
    printf( "%s (%u)\n", dst, len );
    return EXIT_SUCCESS;
  }

produces the output:

A sample STRING
A sample STRING (15)

Classification:

ANSI

Safety:
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes

See also:

setlocale(), strcoll()


[Previous] [Contents] [Next]