This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Add comments
[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
97aff369 114 dVAR;
98994639
HS
115
116 if (! newnum) {
43c5f42d
NC
117 Safefree(PL_numeric_name);
118 PL_numeric_name = NULL;
98994639
HS
119 PL_numeric_standard = TRUE;
120 PL_numeric_local = TRUE;
121 return;
122 }
123
124 if (! PL_numeric_name || strNE(PL_numeric_name, newnum)) {
125 Safefree(PL_numeric_name);
126 PL_numeric_name = stdize_locale(savepv(newnum));
770526c1
NC
127 PL_numeric_standard = ((*newnum == 'C' && newnum[1] == '\0')
128 || strEQ(newnum, "POSIX"));
98994639
HS
129 PL_numeric_local = TRUE;
130 set_numeric_radix();
131 }
132
133#endif /* USE_LOCALE_NUMERIC */
134}
135
136void
137Perl_set_numeric_standard(pTHX)
138{
139#ifdef USE_LOCALE_NUMERIC
97aff369 140 dVAR;
98994639
HS
141
142 if (! PL_numeric_standard) {
143 setlocale(LC_NUMERIC, "C");
144 PL_numeric_standard = TRUE;
145 PL_numeric_local = FALSE;
146 set_numeric_radix();
147 }
148
149#endif /* USE_LOCALE_NUMERIC */
150}
151
152void
153Perl_set_numeric_local(pTHX)
154{
155#ifdef USE_LOCALE_NUMERIC
97aff369 156 dVAR;
98994639
HS
157
158 if (! PL_numeric_local) {
159 setlocale(LC_NUMERIC, PL_numeric_name);
160 PL_numeric_standard = FALSE;
161 PL_numeric_local = TRUE;
162 set_numeric_radix();
163 }
164
165#endif /* USE_LOCALE_NUMERIC */
166}
167
168/*
169 * Set up for a new ctype locale.
170 */
171void
8772537c 172Perl_new_ctype(pTHX_ const char *newctype)
98994639
HS
173{
174#ifdef USE_LOCALE_CTYPE
27da23d5 175 dVAR;
98994639
HS
176 int i;
177
7918f24d
NC
178 PERL_ARGS_ASSERT_NEW_CTYPE;
179
98994639
HS
180 for (i = 0; i < 256; i++) {
181 if (isUPPER_LC(i))
182 PL_fold_locale[i] = toLOWER_LC(i);
183 else if (isLOWER_LC(i))
184 PL_fold_locale[i] = toUPPER_LC(i);
185 else
186 PL_fold_locale[i] = i;
187 }
188
189#endif /* USE_LOCALE_CTYPE */
7918f24d 190 PERL_ARGS_ASSERT_NEW_CTYPE;
8772537c 191 PERL_UNUSED_ARG(newctype);
96a5add6 192 PERL_UNUSED_CONTEXT;
98994639
HS
193}
194
195/*
196 * Set up for a new collation locale.
197 */
198void
8772537c 199Perl_new_collate(pTHX_ const char *newcoll)
98994639
HS
200{
201#ifdef USE_LOCALE_COLLATE
97aff369 202 dVAR;
98994639
HS
203
204 if (! newcoll) {
205 if (PL_collation_name) {
206 ++PL_collation_ix;
207 Safefree(PL_collation_name);
208 PL_collation_name = NULL;
209 }
210 PL_collation_standard = TRUE;
211 PL_collxfrm_base = 0;
212 PL_collxfrm_mult = 2;
213 return;
214 }
215
216 if (! PL_collation_name || strNE(PL_collation_name, newcoll)) {
217 ++PL_collation_ix;
218 Safefree(PL_collation_name);
219 PL_collation_name = stdize_locale(savepv(newcoll));
770526c1
NC
220 PL_collation_standard = ((*newcoll == 'C' && newcoll[1] == '\0')
221 || strEQ(newcoll, "POSIX"));
98994639
HS
222
223 {
224 /* 2: at most so many chars ('a', 'b'). */
225 /* 50: surely no system expands a char more. */
226#define XFRMBUFSIZE (2 * 50)
227 char xbuf[XFRMBUFSIZE];
8772537c
AL
228 const Size_t fa = strxfrm(xbuf, "a", XFRMBUFSIZE);
229 const Size_t fb = strxfrm(xbuf, "ab", XFRMBUFSIZE);
230 const SSize_t mult = fb - fa;
e0601d3c 231 if (mult < 1 && !(fa == 0 && fb == 0))
ad49ad39
NC
232 Perl_croak(aTHX_ "panic: strxfrm() gets absurd - a => %"UVuf", ab => %"UVuf,
233 (UV) fa, (UV) fb);
eb160463 234 PL_collxfrm_base = (fa > (Size_t)mult) ? (fa - mult) : 0;
98994639
HS
235 PL_collxfrm_mult = mult;
236 }
237 }
238
239#endif /* USE_LOCALE_COLLATE */
240}
241
242/*
243 * Initialize locale awareness.
244 */
245int
246Perl_init_i18nl10n(pTHX_ int printwarn)
247{
248 int ok = 1;
249 /* returns
250 * 1 = set ok or not applicable,
251 * 0 = fallback to C locale,
252 * -1 = fallback to C locale failed
253 */
254
255#if defined(USE_LOCALE)
97aff369 256 dVAR;
98994639
HS
257
258#ifdef USE_LOCALE_CTYPE
259 char *curctype = NULL;
260#endif /* USE_LOCALE_CTYPE */
261#ifdef USE_LOCALE_COLLATE
262 char *curcoll = NULL;
263#endif /* USE_LOCALE_COLLATE */
264#ifdef USE_LOCALE_NUMERIC
265 char *curnum = NULL;
266#endif /* USE_LOCALE_NUMERIC */
267#ifdef __GLIBC__
7452cf6a 268 char * const language = PerlEnv_getenv("LANGUAGE");
98994639 269#endif
7452cf6a
AL
270 char * const lc_all = PerlEnv_getenv("LC_ALL");
271 char * const lang = PerlEnv_getenv("LANG");
98994639
HS
272 bool setlocale_failure = FALSE;
273
274#ifdef LOCALE_ENVIRON_REQUIRED
275
276 /*
277 * Ultrix setlocale(..., "") fails if there are no environment
278 * variables from which to get a locale name.
279 */
280
281 bool done = FALSE;
282
283#ifdef LC_ALL
284 if (lang) {
285 if (setlocale(LC_ALL, ""))
286 done = TRUE;
287 else
288 setlocale_failure = TRUE;
289 }
290 if (!setlocale_failure) {
291#ifdef USE_LOCALE_CTYPE
56279a21 292 Safefree(curctype);
98994639
HS
293 if (! (curctype =
294 setlocale(LC_CTYPE,
295 (!done && (lang || PerlEnv_getenv("LC_CTYPE")))
bd61b366 296 ? "" : NULL)))
98994639
HS
297 setlocale_failure = TRUE;
298 else
299 curctype = savepv(curctype);
300#endif /* USE_LOCALE_CTYPE */
301#ifdef USE_LOCALE_COLLATE
56279a21 302 Safefree(curcoll);
98994639
HS
303 if (! (curcoll =
304 setlocale(LC_COLLATE,
305 (!done && (lang || PerlEnv_getenv("LC_COLLATE")))
bd61b366 306 ? "" : NULL)))
98994639
HS
307 setlocale_failure = TRUE;
308 else
309 curcoll = savepv(curcoll);
310#endif /* USE_LOCALE_COLLATE */
311#ifdef USE_LOCALE_NUMERIC
56279a21 312 Safefree(curnum);
98994639
HS
313 if (! (curnum =
314 setlocale(LC_NUMERIC,
315 (!done && (lang || PerlEnv_getenv("LC_NUMERIC")))
bd61b366 316 ? "" : NULL)))
98994639
HS
317 setlocale_failure = TRUE;
318 else
319 curnum = savepv(curnum);
320#endif /* USE_LOCALE_NUMERIC */
321 }
322
323#endif /* LC_ALL */
324
325#endif /* !LOCALE_ENVIRON_REQUIRED */
326
327#ifdef LC_ALL
328 if (! setlocale(LC_ALL, ""))
329 setlocale_failure = TRUE;
330#endif /* LC_ALL */
331
332 if (!setlocale_failure) {
333#ifdef USE_LOCALE_CTYPE
6cb43dbf 334 Safefree(curctype);
98994639
HS
335 if (! (curctype = setlocale(LC_CTYPE, "")))
336 setlocale_failure = TRUE;
337 else
338 curctype = savepv(curctype);
339#endif /* USE_LOCALE_CTYPE */
340#ifdef USE_LOCALE_COLLATE
6cb43dbf 341 Safefree(curcoll);
98994639
HS
342 if (! (curcoll = setlocale(LC_COLLATE, "")))
343 setlocale_failure = TRUE;
344 else
345 curcoll = savepv(curcoll);
346#endif /* USE_LOCALE_COLLATE */
347#ifdef USE_LOCALE_NUMERIC
6cb43dbf 348 Safefree(curnum);
98994639
HS
349 if (! (curnum = setlocale(LC_NUMERIC, "")))
350 setlocale_failure = TRUE;
351 else
352 curnum = savepv(curnum);
353#endif /* USE_LOCALE_NUMERIC */
354 }
355
356 if (setlocale_failure) {
357 char *p;
0bd48802 358 const bool locwarn = (printwarn > 1 ||
98994639
HS
359 (printwarn &&
360 (!(p = PerlEnv_getenv("PERL_BADLANG")) || atoi(p))));
361
362 if (locwarn) {
363#ifdef LC_ALL
364
365 PerlIO_printf(Perl_error_log,
366 "perl: warning: Setting locale failed.\n");
367
368#else /* !LC_ALL */
369
370 PerlIO_printf(Perl_error_log,
371 "perl: warning: Setting locale failed for the categories:\n\t");
372#ifdef USE_LOCALE_CTYPE
373 if (! curctype)
374 PerlIO_printf(Perl_error_log, "LC_CTYPE ");
375#endif /* USE_LOCALE_CTYPE */
376#ifdef USE_LOCALE_COLLATE
377 if (! curcoll)
378 PerlIO_printf(Perl_error_log, "LC_COLLATE ");
379#endif /* USE_LOCALE_COLLATE */
380#ifdef USE_LOCALE_NUMERIC
381 if (! curnum)
382 PerlIO_printf(Perl_error_log, "LC_NUMERIC ");
383#endif /* USE_LOCALE_NUMERIC */
384 PerlIO_printf(Perl_error_log, "\n");
385
386#endif /* LC_ALL */
387
388 PerlIO_printf(Perl_error_log,
389 "perl: warning: Please check that your locale settings:\n");
390
391#ifdef __GLIBC__
392 PerlIO_printf(Perl_error_log,
393 "\tLANGUAGE = %c%s%c,\n",
394 language ? '"' : '(',
395 language ? language : "unset",
396 language ? '"' : ')');
397#endif
398
399 PerlIO_printf(Perl_error_log,
400 "\tLC_ALL = %c%s%c,\n",
401 lc_all ? '"' : '(',
402 lc_all ? lc_all : "unset",
403 lc_all ? '"' : ')');
404
405#if defined(USE_ENVIRON_ARRAY)
406 {
407 char **e;
408 for (e = environ; *e; e++) {
409 if (strnEQ(*e, "LC_", 3)
410 && strnNE(*e, "LC_ALL=", 7)
411 && (p = strchr(*e, '=')))
412 PerlIO_printf(Perl_error_log, "\t%.*s = \"%s\",\n",
413 (int)(p - *e), *e, p + 1);
414 }
415 }
416#else
417 PerlIO_printf(Perl_error_log,
418 "\t(possibly more locale environment variables)\n");
419#endif
420
421 PerlIO_printf(Perl_error_log,
422 "\tLANG = %c%s%c\n",
423 lang ? '"' : '(',
424 lang ? lang : "unset",
425 lang ? '"' : ')');
426
427 PerlIO_printf(Perl_error_log,
428 " are supported and installed on your system.\n");
429 }
430
431#ifdef LC_ALL
432
433 if (setlocale(LC_ALL, "C")) {
434 if (locwarn)
435 PerlIO_printf(Perl_error_log,
436 "perl: warning: Falling back to the standard locale (\"C\").\n");
437 ok = 0;
438 }
439 else {
440 if (locwarn)
441 PerlIO_printf(Perl_error_log,
442 "perl: warning: Failed to fall back to the standard locale (\"C\").\n");
443 ok = -1;
444 }
445
446#else /* ! LC_ALL */
447
448 if (0
449#ifdef USE_LOCALE_CTYPE
450 || !(curctype || setlocale(LC_CTYPE, "C"))
451#endif /* USE_LOCALE_CTYPE */
452#ifdef USE_LOCALE_COLLATE
453 || !(curcoll || setlocale(LC_COLLATE, "C"))
454#endif /* USE_LOCALE_COLLATE */
455#ifdef USE_LOCALE_NUMERIC
456 || !(curnum || setlocale(LC_NUMERIC, "C"))
457#endif /* USE_LOCALE_NUMERIC */
458 )
459 {
460 if (locwarn)
461 PerlIO_printf(Perl_error_log,
462 "perl: warning: Cannot fall back to the standard locale (\"C\").\n");
463 ok = -1;
464 }
465
466#endif /* ! LC_ALL */
467
468#ifdef USE_LOCALE_CTYPE
56279a21 469 Safefree(curctype);
bd61b366 470 curctype = savepv(setlocale(LC_CTYPE, NULL));
98994639
HS
471#endif /* USE_LOCALE_CTYPE */
472#ifdef USE_LOCALE_COLLATE
56279a21 473 Safefree(curcoll);
bd61b366 474 curcoll = savepv(setlocale(LC_COLLATE, NULL));
98994639
HS
475#endif /* USE_LOCALE_COLLATE */
476#ifdef USE_LOCALE_NUMERIC
56279a21 477 Safefree(curnum);
bd61b366 478 curnum = savepv(setlocale(LC_NUMERIC, NULL));
98994639
HS
479#endif /* USE_LOCALE_NUMERIC */
480 }
481 else {
482
483#ifdef USE_LOCALE_CTYPE
484 new_ctype(curctype);
485#endif /* USE_LOCALE_CTYPE */
486
487#ifdef USE_LOCALE_COLLATE
488 new_collate(curcoll);
489#endif /* USE_LOCALE_COLLATE */
490
491#ifdef USE_LOCALE_NUMERIC
492 new_numeric(curnum);
493#endif /* USE_LOCALE_NUMERIC */
b310b053 494
98994639
HS
495 }
496
497#endif /* USE_LOCALE */
498
ec71e770 499#ifdef USE_PERLIO
b310b053 500 {
fde18df1 501 /* Set PL_utf8locale to TRUE if using PerlIO _and_
ec71e770 502 any of the following are true:
085a54d9 503 - nl_langinfo(CODESET) contains /^utf-?8/i
61de9fb5 504 - $ENV{LC_ALL} contains /^utf-?8/i
085a54d9 505 - $ENV{LC_CTYPE} contains /^utf-?8/i
61de9fb5
JH
506 - $ENV{LANG} contains /^utf-?8/i
507 The LC_ALL, LC_CTYPE, LANG obey the usual override
508 hierarchy of locale environment variables. (LANGUAGE
509 affects only LC_MESSAGES only under glibc.) (If present,
510 it overrides LC_MESSAGES for GNU gettext, and it also
511 can have more than one locale, separated by spaces,
512 in case you need to know.)
8aa8f774 513 If PL_utf8locale and PL_unicode (set by -C or by $ENV{PERL_UNICODE})
a05d7ebb 514 are true, perl.c:S_parse_body() will turn on the PerlIO :utf8 layer
fde18df1 515 on STDIN, STDOUT, STDERR, _and_ the default open discipline.
085a54d9 516 */
fde18df1 517 bool utf8locale = FALSE;
b310b053
JH
518 char *codeset = NULL;
519#if defined(HAS_NL_LANGINFO) && defined(CODESET)
520 codeset = nl_langinfo(CODESET);
521#endif
61de9fb5 522 if (codeset)
e6226b18
KW
523 utf8locale = (foldEQ(codeset, STR_WITH_LEN("UTF-8"))
524 || foldEQ(codeset, STR_WITH_LEN("UTF8") ));
077a72a9 525#if defined(USE_LOCALE)
61de9fb5
JH
526 else { /* nl_langinfo(CODESET) is supposed to correctly
527 * interpret the locale environment variables,
528 * but just in case it fails, let's do this manually. */
529 if (lang)
e6226b18
KW
530 utf8locale = (foldEQ(lang, STR_WITH_LEN("UTF-8"))
531 || foldEQ(lang, STR_WITH_LEN("UTF8") ));
b310b053 532#ifdef USE_LOCALE_CTYPE
61de9fb5 533 if (curctype)
e6226b18
KW
534 utf8locale = (foldEQ(curctype, STR_WITH_LEN("UTF-8"))
535 || foldEQ(curctype, STR_WITH_LEN("UTF8") ));
b310b053 536#endif
61de9fb5 537 if (lc_all)
e6226b18
KW
538 utf8locale = (foldEQ(lc_all, STR_WITH_LEN("UTF-8"))
539 || foldEQ(lc_all, STR_WITH_LEN("UTF8") ));
61de9fb5 540 }
fde18df1
JH
541#endif /* USE_LOCALE */
542 if (utf8locale)
543 PL_utf8locale = TRUE;
544 }
a05d7ebb 545 /* Set PL_unicode to $ENV{PERL_UNICODE} if using PerlIO.
fde18df1
JH
546 This is an alternative to using the -C command line switch
547 (the -C if present will override this). */
548 {
dd374669 549 const char *p = PerlEnv_getenv("PERL_UNICODE");
a05d7ebb 550 PL_unicode = p ? parse_unicode_opts(&p) : 0;
5a22a2bb
NC
551 if (PL_unicode & PERL_UNICODE_UTF8CACHEASSERT_FLAG)
552 PL_utf8cache = -1;
b310b053 553 }
ec71e770 554#endif
b310b053 555
98994639 556#ifdef USE_LOCALE_CTYPE
43c5f42d 557 Safefree(curctype);
98994639
HS
558#endif /* USE_LOCALE_CTYPE */
559#ifdef USE_LOCALE_COLLATE
43c5f42d 560 Safefree(curcoll);
98994639
HS
561#endif /* USE_LOCALE_COLLATE */
562#ifdef USE_LOCALE_NUMERIC
43c5f42d 563 Safefree(curnum);
98994639
HS
564#endif /* USE_LOCALE_NUMERIC */
565 return ok;
566}
567
98994639
HS
568#ifdef USE_LOCALE_COLLATE
569
570/*
571 * mem_collxfrm() is a bit like strxfrm() but with two important
572 * differences. First, it handles embedded NULs. Second, it allocates
573 * a bit more memory than needed for the transformed data itself.
574 * The real transformed data begins at offset sizeof(collationix).
575 * Please see sv_collxfrm() to see how this is used.
576 */
166f8a29 577
98994639
HS
578char *
579Perl_mem_collxfrm(pTHX_ const char *s, STRLEN len, STRLEN *xlen)
580{
97aff369 581 dVAR;
98994639
HS
582 char *xbuf;
583 STRLEN xAlloc, xin, xout; /* xalloc is a reserved word in VC */
584
7918f24d
NC
585 PERL_ARGS_ASSERT_MEM_COLLXFRM;
586
98994639
HS
587 /* the first sizeof(collationix) bytes are used by sv_collxfrm(). */
588 /* the +1 is for the terminating NUL. */
589
590 xAlloc = sizeof(PL_collation_ix) + PL_collxfrm_base + (PL_collxfrm_mult * len) + 1;
a02a5408 591 Newx(xbuf, xAlloc, char);
98994639
HS
592 if (! xbuf)
593 goto bad;
594
595 *(U32*)xbuf = PL_collation_ix;
596 xout = sizeof(PL_collation_ix);
597 for (xin = 0; xin < len; ) {
224e8ef5 598 Size_t xused;
98994639
HS
599
600 for (;;) {
601 xused = strxfrm(xbuf + xout, s + xin, xAlloc - xout);
224e8ef5 602 if (xused >= PERL_INT_MAX)
98994639 603 goto bad;
eb160463 604 if ((STRLEN)xused < xAlloc - xout)
98994639
HS
605 break;
606 xAlloc = (2 * xAlloc) + 1;
607 Renew(xbuf, xAlloc, char);
608 if (! xbuf)
609 goto bad;
610 }
611
612 xin += strlen(s + xin) + 1;
613 xout += xused;
614
615 /* Embedded NULs are understood but silently skipped
616 * because they make no sense in locale collation. */
617 }
618
619 xbuf[xout] = '\0';
620 *xlen = xout - sizeof(PL_collation_ix);
621 return xbuf;
622
623 bad:
624 Safefree(xbuf);
625 *xlen = 0;
626 return NULL;
627}
628
629#endif /* USE_LOCALE_COLLATE */
630
66610fdd
RGS
631/*
632 * Local variables:
633 * c-indentation-style: bsd
634 * c-basic-offset: 4
14d04a33 635 * indent-tabs-mode: nil
66610fdd
RGS
636 * End:
637 *
14d04a33 638 * ex: set ts=8 sts=4 sw=4 et:
37442d52 639 */