This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Compare apples to apples
[perl5.git] / locale.c
CommitLineData
98994639
HS
1/* locale.c
2 *
1129b882
NC
3 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
4 * 2002, 2003, 2005, 2006, 2007, 2008 by Larry Wall and others
98994639
HS
5 *
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
8 *
9 */
10
11/*
4ac71550 12 * A Elbereth Gilthoniel,
cdad3b53 13 * silivren penna míriel
4ac71550 14 * o menel aglar elenath!
cdad3b53 15 * Na-chaered palan-díriel
4ac71550
TC
16 * o galadhremmin ennorath,
17 * Fanuilos, le linnathon
18 * nef aear, si nef aearon!
19 *
20 * [p.238 of _The Lord of the Rings_, II/i: "Many Meetings"]
98994639
HS
21 */
22
166f8a29
DM
23/* utility functions for handling locale-specific stuff like what
24 * character represents the decimal point.
25 */
26
98994639
HS
27#include "EXTERN.h"
28#define PERL_IN_LOCALE_C
29#include "perl.h"
30
b310b053
JH
31#ifdef I_LANGINFO
32# include <langinfo.h>
33#endif
34
a4af207c
JH
35#include "reentr.h"
36
27da23d5 37#if defined(USE_LOCALE_NUMERIC) || defined(USE_LOCALE_COLLATE)
98994639
HS
38/*
39 * Standardize the locale name from a string returned by 'setlocale'.
40 *
0ef2a2b2 41 * The typical return value of setlocale() is either
98994639
HS
42 * (1) "xx_YY" if the first argument of setlocale() is not LC_ALL
43 * (2) "xa_YY xb_YY ..." if the first argument of setlocale() is LC_ALL
44 * (the space-separated values represent the various sublocales,
0ef2a2b2 45 * in some unspecified order). This is not handled by this function.
98994639
HS
46 *
47 * In some platforms it has a form like "LC_SOMETHING=Lang_Country.866\n",
0ef2a2b2
KW
48 * which is harmful for further use of the string in setlocale(). This
49 * function removes the trailing new line and everything up through the '='
98994639
HS
50 *
51 */
52STATIC char *
53S_stdize_locale(pTHX_ char *locs)
54{
7452cf6a 55 const char * const s = strchr(locs, '=');
98994639
HS
56 bool okay = TRUE;
57
7918f24d
NC
58 PERL_ARGS_ASSERT_STDIZE_LOCALE;
59
8772537c
AL
60 if (s) {
61 const char * const t = strchr(s, '.');
98994639 62 okay = FALSE;
8772537c
AL
63 if (t) {
64 const char * const u = strchr(t, '\n');
65 if (u && (u[1] == 0)) {
66 const STRLEN len = u - s;
67 Move(s + 1, locs, len, char);
68 locs[len] = 0;
69 okay = TRUE;
98994639
HS
70 }
71 }
72 }
73
74 if (!okay)
75 Perl_croak(aTHX_ "Can't fix broken locale name \"%s\"", locs);
76
77 return locs;
78}
27da23d5 79#endif
98994639
HS
80
81void
82Perl_set_numeric_radix(pTHX)
83{
84#ifdef USE_LOCALE_NUMERIC
97aff369 85 dVAR;
98994639 86# ifdef HAS_LOCALECONV
7452cf6a 87 const struct lconv* const lc = localeconv();
98994639 88
98994639
HS
89 if (lc && lc->decimal_point) {
90 if (lc->decimal_point[0] == '.' && lc->decimal_point[1] == 0) {
91 SvREFCNT_dec(PL_numeric_radix_sv);
a0714e2c 92 PL_numeric_radix_sv = NULL;
98994639
HS
93 }
94 else {
95 if (PL_numeric_radix_sv)
96 sv_setpv(PL_numeric_radix_sv, lc->decimal_point);
97 else
98 PL_numeric_radix_sv = newSVpv(lc->decimal_point, 0);
99 }
100 }
101 else
a0714e2c 102 PL_numeric_radix_sv = NULL;
98994639
HS
103# endif /* HAS_LOCALECONV */
104#endif /* USE_LOCALE_NUMERIC */
105}
106
107/*
108 * Set up for a new numeric locale.
109 */
110void
8772537c 111Perl_new_numeric(pTHX_ const char *newnum)
98994639
HS
112{
113#ifdef USE_LOCALE_NUMERIC
b03f34cf 114 char *save_newnum;
97aff369 115 dVAR;
98994639
HS
116
117 if (! newnum) {
43c5f42d
NC
118 Safefree(PL_numeric_name);
119 PL_numeric_name = NULL;
98994639
HS
120 PL_numeric_standard = TRUE;
121 PL_numeric_local = TRUE;
122 return;
123 }
124
b03f34cf
KW
125 save_newnum = stdize_locale(savepv(newnum));
126 if (! PL_numeric_name || strNE(PL_numeric_name, save_newnum)) {
98994639 127 Safefree(PL_numeric_name);
b03f34cf
KW
128 PL_numeric_name = save_newnum;
129 PL_numeric_standard = ((*save_newnum == 'C' && save_newnum[1] == '\0')
130 || strEQ(save_newnum, "POSIX"));
98994639
HS
131 PL_numeric_local = TRUE;
132 set_numeric_radix();
133 }
b03f34cf
KW
134 else {
135 Safefree(save_newnum);
136 }
98994639
HS
137
138#endif /* USE_LOCALE_NUMERIC */
139}
140
141void
142Perl_set_numeric_standard(pTHX)
143{
144#ifdef USE_LOCALE_NUMERIC
97aff369 145 dVAR;
98994639
HS
146
147 if (! PL_numeric_standard) {
148 setlocale(LC_NUMERIC, "C");
149 PL_numeric_standard = TRUE;
150 PL_numeric_local = FALSE;
151 set_numeric_radix();
152 }
153
154#endif /* USE_LOCALE_NUMERIC */
155}
156
157void
158Perl_set_numeric_local(pTHX)
159{
160#ifdef USE_LOCALE_NUMERIC
97aff369 161 dVAR;
98994639
HS
162
163 if (! PL_numeric_local) {
164 setlocale(LC_NUMERIC, PL_numeric_name);
165 PL_numeric_standard = FALSE;
166 PL_numeric_local = TRUE;
167 set_numeric_radix();
168 }
169
170#endif /* USE_LOCALE_NUMERIC */
171}
172
173/*
174 * Set up for a new ctype locale.
175 */
176void
8772537c 177Perl_new_ctype(pTHX_ const char *newctype)
98994639
HS
178{
179#ifdef USE_LOCALE_CTYPE
27da23d5 180 dVAR;
98994639
HS
181 int i;
182
7918f24d
NC
183 PERL_ARGS_ASSERT_NEW_CTYPE;
184
98994639
HS
185 for (i = 0; i < 256; i++) {
186 if (isUPPER_LC(i))
187 PL_fold_locale[i] = toLOWER_LC(i);
188 else if (isLOWER_LC(i))
189 PL_fold_locale[i] = toUPPER_LC(i);
190 else
191 PL_fold_locale[i] = i;
192 }
193
194#endif /* USE_LOCALE_CTYPE */
7918f24d 195 PERL_ARGS_ASSERT_NEW_CTYPE;
8772537c 196 PERL_UNUSED_ARG(newctype);
96a5add6 197 PERL_UNUSED_CONTEXT;
98994639
HS
198}
199
200/*
201 * Set up for a new collation locale.
202 */
203void
8772537c 204Perl_new_collate(pTHX_ const char *newcoll)
98994639
HS
205{
206#ifdef USE_LOCALE_COLLATE
97aff369 207 dVAR;
98994639
HS
208
209 if (! newcoll) {
210 if (PL_collation_name) {
211 ++PL_collation_ix;
212 Safefree(PL_collation_name);
213 PL_collation_name = NULL;
214 }
215 PL_collation_standard = TRUE;
216 PL_collxfrm_base = 0;
217 PL_collxfrm_mult = 2;
218 return;
219 }
220
221 if (! PL_collation_name || strNE(PL_collation_name, newcoll)) {
222 ++PL_collation_ix;
223 Safefree(PL_collation_name);
224 PL_collation_name = stdize_locale(savepv(newcoll));
770526c1
NC
225 PL_collation_standard = ((*newcoll == 'C' && newcoll[1] == '\0')
226 || strEQ(newcoll, "POSIX"));
98994639
HS
227
228 {
229 /* 2: at most so many chars ('a', 'b'). */
230 /* 50: surely no system expands a char more. */
231#define XFRMBUFSIZE (2 * 50)
232 char xbuf[XFRMBUFSIZE];
8772537c
AL
233 const Size_t fa = strxfrm(xbuf, "a", XFRMBUFSIZE);
234 const Size_t fb = strxfrm(xbuf, "ab", XFRMBUFSIZE);
235 const SSize_t mult = fb - fa;
e0601d3c 236 if (mult < 1 && !(fa == 0 && fb == 0))
ad49ad39
NC
237 Perl_croak(aTHX_ "panic: strxfrm() gets absurd - a => %"UVuf", ab => %"UVuf,
238 (UV) fa, (UV) fb);
eb160463 239 PL_collxfrm_base = (fa > (Size_t)mult) ? (fa - mult) : 0;
98994639
HS
240 PL_collxfrm_mult = mult;
241 }
242 }
243
244#endif /* USE_LOCALE_COLLATE */
245}
246
247/*
248 * Initialize locale awareness.
249 */
250int
251Perl_init_i18nl10n(pTHX_ int printwarn)
252{
253 int ok = 1;
254 /* returns
255 * 1 = set ok or not applicable,
256 * 0 = fallback to C locale,
257 * -1 = fallback to C locale failed
258 */
259
260#if defined(USE_LOCALE)
97aff369 261 dVAR;
98994639
HS
262
263#ifdef USE_LOCALE_CTYPE
264 char *curctype = NULL;
265#endif /* USE_LOCALE_CTYPE */
266#ifdef USE_LOCALE_COLLATE
267 char *curcoll = NULL;
268#endif /* USE_LOCALE_COLLATE */
269#ifdef USE_LOCALE_NUMERIC
270 char *curnum = NULL;
271#endif /* USE_LOCALE_NUMERIC */
272#ifdef __GLIBC__
7452cf6a 273 char * const language = PerlEnv_getenv("LANGUAGE");
98994639 274#endif
7452cf6a
AL
275 char * const lc_all = PerlEnv_getenv("LC_ALL");
276 char * const lang = PerlEnv_getenv("LANG");
98994639
HS
277 bool setlocale_failure = FALSE;
278
279#ifdef LOCALE_ENVIRON_REQUIRED
280
281 /*
282 * Ultrix setlocale(..., "") fails if there are no environment
283 * variables from which to get a locale name.
284 */
285
286 bool done = FALSE;
287
b3e384bf 288# ifdef LC_ALL
98994639
HS
289 if (lang) {
290 if (setlocale(LC_ALL, ""))
291 done = TRUE;
292 else
293 setlocale_failure = TRUE;
294 }
295 if (!setlocale_failure) {
b3e384bf 296# ifdef USE_LOCALE_CTYPE
56279a21 297 Safefree(curctype);
98994639
HS
298 if (! (curctype =
299 setlocale(LC_CTYPE,
300 (!done && (lang || PerlEnv_getenv("LC_CTYPE")))
bd61b366 301 ? "" : NULL)))
98994639
HS
302 setlocale_failure = TRUE;
303 else
304 curctype = savepv(curctype);
b3e384bf
KW
305# endif /* USE_LOCALE_CTYPE */
306# ifdef USE_LOCALE_COLLATE
56279a21 307 Safefree(curcoll);
98994639
HS
308 if (! (curcoll =
309 setlocale(LC_COLLATE,
310 (!done && (lang || PerlEnv_getenv("LC_COLLATE")))
bd61b366 311 ? "" : NULL)))
98994639
HS
312 setlocale_failure = TRUE;
313 else
314 curcoll = savepv(curcoll);
b3e384bf
KW
315# endif /* USE_LOCALE_COLLATE */
316# ifdef USE_LOCALE_NUMERIC
56279a21 317 Safefree(curnum);
98994639
HS
318 if (! (curnum =
319 setlocale(LC_NUMERIC,
320 (!done && (lang || PerlEnv_getenv("LC_NUMERIC")))
bd61b366 321 ? "" : NULL)))
98994639
HS
322 setlocale_failure = TRUE;
323 else
324 curnum = savepv(curnum);
b3e384bf 325# endif /* USE_LOCALE_NUMERIC */
98994639
HS
326 }
327
b3e384bf 328# endif /* LC_ALL */
98994639
HS
329
330#endif /* !LOCALE_ENVIRON_REQUIRED */
331
332#ifdef LC_ALL
333 if (! setlocale(LC_ALL, ""))
334 setlocale_failure = TRUE;
335#endif /* LC_ALL */
336
337 if (!setlocale_failure) {
338#ifdef USE_LOCALE_CTYPE
6cb43dbf 339 Safefree(curctype);
98994639
HS
340 if (! (curctype = setlocale(LC_CTYPE, "")))
341 setlocale_failure = TRUE;
342 else
343 curctype = savepv(curctype);
344#endif /* USE_LOCALE_CTYPE */
345#ifdef USE_LOCALE_COLLATE
6cb43dbf 346 Safefree(curcoll);
98994639
HS
347 if (! (curcoll = setlocale(LC_COLLATE, "")))
348 setlocale_failure = TRUE;
349 else
350 curcoll = savepv(curcoll);
351#endif /* USE_LOCALE_COLLATE */
352#ifdef USE_LOCALE_NUMERIC
6cb43dbf 353 Safefree(curnum);
98994639
HS
354 if (! (curnum = setlocale(LC_NUMERIC, "")))
355 setlocale_failure = TRUE;
356 else
357 curnum = savepv(curnum);
358#endif /* USE_LOCALE_NUMERIC */
359 }
360
361 if (setlocale_failure) {
362 char *p;
0bd48802 363 const bool locwarn = (printwarn > 1 ||
98994639
HS
364 (printwarn &&
365 (!(p = PerlEnv_getenv("PERL_BADLANG")) || atoi(p))));
366
367 if (locwarn) {
368#ifdef LC_ALL
369
370 PerlIO_printf(Perl_error_log,
371 "perl: warning: Setting locale failed.\n");
372
373#else /* !LC_ALL */
374
375 PerlIO_printf(Perl_error_log,
376 "perl: warning: Setting locale failed for the categories:\n\t");
377#ifdef USE_LOCALE_CTYPE
378 if (! curctype)
379 PerlIO_printf(Perl_error_log, "LC_CTYPE ");
380#endif /* USE_LOCALE_CTYPE */
381#ifdef USE_LOCALE_COLLATE
382 if (! curcoll)
383 PerlIO_printf(Perl_error_log, "LC_COLLATE ");
384#endif /* USE_LOCALE_COLLATE */
385#ifdef USE_LOCALE_NUMERIC
386 if (! curnum)
387 PerlIO_printf(Perl_error_log, "LC_NUMERIC ");
388#endif /* USE_LOCALE_NUMERIC */
389 PerlIO_printf(Perl_error_log, "\n");
390
391#endif /* LC_ALL */
392
393 PerlIO_printf(Perl_error_log,
394 "perl: warning: Please check that your locale settings:\n");
395
396#ifdef __GLIBC__
397 PerlIO_printf(Perl_error_log,
398 "\tLANGUAGE = %c%s%c,\n",
399 language ? '"' : '(',
400 language ? language : "unset",
401 language ? '"' : ')');
402#endif
403
404 PerlIO_printf(Perl_error_log,
405 "\tLC_ALL = %c%s%c,\n",
406 lc_all ? '"' : '(',
407 lc_all ? lc_all : "unset",
408 lc_all ? '"' : ')');
409
410#if defined(USE_ENVIRON_ARRAY)
411 {
412 char **e;
413 for (e = environ; *e; e++) {
414 if (strnEQ(*e, "LC_", 3)
415 && strnNE(*e, "LC_ALL=", 7)
416 && (p = strchr(*e, '=')))
417 PerlIO_printf(Perl_error_log, "\t%.*s = \"%s\",\n",
418 (int)(p - *e), *e, p + 1);
419 }
420 }
421#else
422 PerlIO_printf(Perl_error_log,
423 "\t(possibly more locale environment variables)\n");
424#endif
425
426 PerlIO_printf(Perl_error_log,
427 "\tLANG = %c%s%c\n",
428 lang ? '"' : '(',
429 lang ? lang : "unset",
430 lang ? '"' : ')');
431
432 PerlIO_printf(Perl_error_log,
433 " are supported and installed on your system.\n");
434 }
435
436#ifdef LC_ALL
437
438 if (setlocale(LC_ALL, "C")) {
439 if (locwarn)
440 PerlIO_printf(Perl_error_log,
441 "perl: warning: Falling back to the standard locale (\"C\").\n");
442 ok = 0;
443 }
444 else {
445 if (locwarn)
446 PerlIO_printf(Perl_error_log,
447 "perl: warning: Failed to fall back to the standard locale (\"C\").\n");
448 ok = -1;
449 }
450
451#else /* ! LC_ALL */
452
453 if (0
454#ifdef USE_LOCALE_CTYPE
455 || !(curctype || setlocale(LC_CTYPE, "C"))
456#endif /* USE_LOCALE_CTYPE */
457#ifdef USE_LOCALE_COLLATE
458 || !(curcoll || setlocale(LC_COLLATE, "C"))
459#endif /* USE_LOCALE_COLLATE */
460#ifdef USE_LOCALE_NUMERIC
461 || !(curnum || setlocale(LC_NUMERIC, "C"))
462#endif /* USE_LOCALE_NUMERIC */
463 )
464 {
465 if (locwarn)
466 PerlIO_printf(Perl_error_log,
467 "perl: warning: Cannot fall back to the standard locale (\"C\").\n");
468 ok = -1;
469 }
470
471#endif /* ! LC_ALL */
472
473#ifdef USE_LOCALE_CTYPE
56279a21 474 Safefree(curctype);
bd61b366 475 curctype = savepv(setlocale(LC_CTYPE, NULL));
98994639
HS
476#endif /* USE_LOCALE_CTYPE */
477#ifdef USE_LOCALE_COLLATE
56279a21 478 Safefree(curcoll);
bd61b366 479 curcoll = savepv(setlocale(LC_COLLATE, NULL));
98994639
HS
480#endif /* USE_LOCALE_COLLATE */
481#ifdef USE_LOCALE_NUMERIC
56279a21 482 Safefree(curnum);
bd61b366 483 curnum = savepv(setlocale(LC_NUMERIC, NULL));
98994639
HS
484#endif /* USE_LOCALE_NUMERIC */
485 }
486 else {
487
488#ifdef USE_LOCALE_CTYPE
489 new_ctype(curctype);
490#endif /* USE_LOCALE_CTYPE */
491
492#ifdef USE_LOCALE_COLLATE
493 new_collate(curcoll);
494#endif /* USE_LOCALE_COLLATE */
495
496#ifdef USE_LOCALE_NUMERIC
497 new_numeric(curnum);
498#endif /* USE_LOCALE_NUMERIC */
b310b053 499
98994639
HS
500 }
501
502#endif /* USE_LOCALE */
503
ec71e770 504#ifdef USE_PERLIO
b310b053 505 {
fde18df1 506 /* Set PL_utf8locale to TRUE if using PerlIO _and_
ec71e770 507 any of the following are true:
085a54d9 508 - nl_langinfo(CODESET) contains /^utf-?8/i
61de9fb5 509 - $ENV{LC_ALL} contains /^utf-?8/i
085a54d9 510 - $ENV{LC_CTYPE} contains /^utf-?8/i
61de9fb5
JH
511 - $ENV{LANG} contains /^utf-?8/i
512 The LC_ALL, LC_CTYPE, LANG obey the usual override
513 hierarchy of locale environment variables. (LANGUAGE
514 affects only LC_MESSAGES only under glibc.) (If present,
515 it overrides LC_MESSAGES for GNU gettext, and it also
516 can have more than one locale, separated by spaces,
517 in case you need to know.)
8aa8f774 518 If PL_utf8locale and PL_unicode (set by -C or by $ENV{PERL_UNICODE})
a05d7ebb 519 are true, perl.c:S_parse_body() will turn on the PerlIO :utf8 layer
fde18df1 520 on STDIN, STDOUT, STDERR, _and_ the default open discipline.
085a54d9 521 */
fde18df1 522 bool utf8locale = FALSE;
b310b053
JH
523 char *codeset = NULL;
524#if defined(HAS_NL_LANGINFO) && defined(CODESET)
525 codeset = nl_langinfo(CODESET);
526#endif
61de9fb5 527 if (codeset)
e6226b18
KW
528 utf8locale = (foldEQ(codeset, STR_WITH_LEN("UTF-8"))
529 || foldEQ(codeset, STR_WITH_LEN("UTF8") ));
077a72a9 530#if defined(USE_LOCALE)
61de9fb5
JH
531 else { /* nl_langinfo(CODESET) is supposed to correctly
532 * interpret the locale environment variables,
533 * but just in case it fails, let's do this manually. */
534 if (lang)
e6226b18
KW
535 utf8locale = (foldEQ(lang, STR_WITH_LEN("UTF-8"))
536 || foldEQ(lang, STR_WITH_LEN("UTF8") ));
b310b053 537#ifdef USE_LOCALE_CTYPE
61de9fb5 538 if (curctype)
e6226b18
KW
539 utf8locale = (foldEQ(curctype, STR_WITH_LEN("UTF-8"))
540 || foldEQ(curctype, STR_WITH_LEN("UTF8") ));
b310b053 541#endif
61de9fb5 542 if (lc_all)
e6226b18
KW
543 utf8locale = (foldEQ(lc_all, STR_WITH_LEN("UTF-8"))
544 || foldEQ(lc_all, STR_WITH_LEN("UTF8") ));
61de9fb5 545 }
fde18df1
JH
546#endif /* USE_LOCALE */
547 if (utf8locale)
548 PL_utf8locale = TRUE;
549 }
a05d7ebb 550 /* Set PL_unicode to $ENV{PERL_UNICODE} if using PerlIO.
fde18df1
JH
551 This is an alternative to using the -C command line switch
552 (the -C if present will override this). */
553 {
dd374669 554 const char *p = PerlEnv_getenv("PERL_UNICODE");
a05d7ebb 555 PL_unicode = p ? parse_unicode_opts(&p) : 0;
5a22a2bb
NC
556 if (PL_unicode & PERL_UNICODE_UTF8CACHEASSERT_FLAG)
557 PL_utf8cache = -1;
b310b053 558 }
ec71e770 559#endif
b310b053 560
98994639 561#ifdef USE_LOCALE_CTYPE
43c5f42d 562 Safefree(curctype);
98994639
HS
563#endif /* USE_LOCALE_CTYPE */
564#ifdef USE_LOCALE_COLLATE
43c5f42d 565 Safefree(curcoll);
98994639
HS
566#endif /* USE_LOCALE_COLLATE */
567#ifdef USE_LOCALE_NUMERIC
43c5f42d 568 Safefree(curnum);
98994639
HS
569#endif /* USE_LOCALE_NUMERIC */
570 return ok;
571}
572
98994639
HS
573#ifdef USE_LOCALE_COLLATE
574
575/*
576 * mem_collxfrm() is a bit like strxfrm() but with two important
577 * differences. First, it handles embedded NULs. Second, it allocates
578 * a bit more memory than needed for the transformed data itself.
579 * The real transformed data begins at offset sizeof(collationix).
580 * Please see sv_collxfrm() to see how this is used.
581 */
166f8a29 582
98994639
HS
583char *
584Perl_mem_collxfrm(pTHX_ const char *s, STRLEN len, STRLEN *xlen)
585{
97aff369 586 dVAR;
98994639
HS
587 char *xbuf;
588 STRLEN xAlloc, xin, xout; /* xalloc is a reserved word in VC */
589
7918f24d
NC
590 PERL_ARGS_ASSERT_MEM_COLLXFRM;
591
98994639
HS
592 /* the first sizeof(collationix) bytes are used by sv_collxfrm(). */
593 /* the +1 is for the terminating NUL. */
594
595 xAlloc = sizeof(PL_collation_ix) + PL_collxfrm_base + (PL_collxfrm_mult * len) + 1;
a02a5408 596 Newx(xbuf, xAlloc, char);
98994639
HS
597 if (! xbuf)
598 goto bad;
599
600 *(U32*)xbuf = PL_collation_ix;
601 xout = sizeof(PL_collation_ix);
602 for (xin = 0; xin < len; ) {
224e8ef5 603 Size_t xused;
98994639
HS
604
605 for (;;) {
606 xused = strxfrm(xbuf + xout, s + xin, xAlloc - xout);
224e8ef5 607 if (xused >= PERL_INT_MAX)
98994639 608 goto bad;
eb160463 609 if ((STRLEN)xused < xAlloc - xout)
98994639
HS
610 break;
611 xAlloc = (2 * xAlloc) + 1;
612 Renew(xbuf, xAlloc, char);
613 if (! xbuf)
614 goto bad;
615 }
616
617 xin += strlen(s + xin) + 1;
618 xout += xused;
619
620 /* Embedded NULs are understood but silently skipped
621 * because they make no sense in locale collation. */
622 }
623
624 xbuf[xout] = '\0';
625 *xlen = xout - sizeof(PL_collation_ix);
626 return xbuf;
627
628 bad:
629 Safefree(xbuf);
630 *xlen = 0;
631 return NULL;
632}
633
634#endif /* USE_LOCALE_COLLATE */
635
66610fdd
RGS
636/*
637 * Local variables:
638 * c-indentation-style: bsd
639 * c-basic-offset: 4
14d04a33 640 * indent-tabs-mode: nil
66610fdd
RGS
641 * End:
642 *
14d04a33 643 * ex: set ts=8 sts=4 sw=4 et:
37442d52 644 */