xref: /reactos/sdk/lib/crt/string/strxfrm.c (revision 40462c92)
1 #include <precomp.h>
2 
3 #include <locale.h>
4 #include <internal/wine/msvcrt.h>
5 
6 size_t CDECL _strxfrm_l( char *dest, const char *src,
7         size_t len, _locale_t locale )
8 {
9     MSVCRT_pthreadlocinfo locinfo;
10     int ret;
11 
12     if(!MSVCRT_CHECK_PMT(src)) return INT_MAX;
13     if(!MSVCRT_CHECK_PMT(dest || !len)) return INT_MAX;
14 
15     if(len > INT_MAX) {
16         FIXME("len > INT_MAX not supported\n");
17         len = INT_MAX;
18     }
19 
20     if(!locale)
21         locinfo = get_locinfo();
22     else
23         locinfo = ((MSVCRT__locale_t)locale)->locinfo;
24 
25     if(!locinfo->lc_handle[MSVCRT_LC_COLLATE]) {
26         strncpy(dest, src, len);
27         return strlen(src);
28     }
29 
30     ret = LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE],
31             LCMAP_SORTKEY, src, -1, NULL, 0);
32     if(!ret) {
33         if(len) dest[0] = 0;
34         *_errno() = EILSEQ;
35         return INT_MAX;
36     }
37     if(!len) return ret-1;
38 
39     if(ret > len) {
40         dest[0] = 0;
41         *_errno() = ERANGE;
42         return ret-1;
43     }
44 
45     return LCMapStringA(locinfo->lc_handle[MSVCRT_LC_COLLATE],
46             LCMAP_SORTKEY, src, -1, dest, len) - 1;
47 }
48 
49 /*********************************************************************
50  *		strxfrm (MSVCRT.@)
51  */
52 size_t CDECL strxfrm( char *dest, const char *src, size_t len )
53 {
54     return _strxfrm_l(dest, src, len, NULL);
55 }
56