diff options
| author | Eli Zaretskii | 2018-08-06 17:50:55 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2018-08-06 17:50:55 +0300 |
| commit | bedf905dd37ef8ad45d5912dd230bfe63a1721b3 (patch) | |
| tree | a17e858edbdcd4cd33f72a34f2f0d4064bfd3d5d /lib-src | |
| parent | 9c022a488bd462b85895ef84313fe84c5bc2bb4d (diff) | |
| download | emacs-bedf905dd37ef8ad45d5912dd230bfe63a1721b3.tar.gz emacs-bedf905dd37ef8ad45d5912dd230bfe63a1721b3.zip | |
Fix the MS-Windows build as followup to Gnulib regex import
* lib-src/ntlib.c (nl_langinfo): New function. (Bug#32194)
Diffstat (limited to 'lib-src')
| -rw-r--r-- | lib-src/ntlib.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c index 95512854839..4ca521d2775 100644 --- a/lib-src/ntlib.c +++ b/lib-src/ntlib.c | |||
| @@ -31,6 +31,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 31 | #include <ctype.h> | 31 | #include <ctype.h> |
| 32 | #include <sys/timeb.h> | 32 | #include <sys/timeb.h> |
| 33 | #include <mbstring.h> | 33 | #include <mbstring.h> |
| 34 | #include <locale.h> | ||
| 35 | |||
| 36 | #include <nl_types.h> | ||
| 37 | #include <langinfo.h> | ||
| 34 | 38 | ||
| 35 | #include "ntlib.h" | 39 | #include "ntlib.h" |
| 36 | 40 | ||
| @@ -423,3 +427,66 @@ sys_open (const char * path, int oflag, int mode) | |||
| 423 | { | 427 | { |
| 424 | return _open (path, oflag, mode); | 428 | return _open (path, oflag, mode); |
| 425 | } | 429 | } |
| 430 | |||
| 431 | /* Emulation of nl_langinfo that supports only CODESET. | ||
| 432 | Used in Gnulib regex.c. */ | ||
| 433 | char * | ||
| 434 | nl_langinfo (nl_item item) | ||
| 435 | { | ||
| 436 | switch (item) | ||
| 437 | { | ||
| 438 | case CODESET: | ||
| 439 | { | ||
| 440 | /* Shamelessly stolen from Gnulib's nl_langinfo.c, modulo | ||
| 441 | CPP directives. */ | ||
| 442 | static char buf[2 + 10 + 1]; | ||
| 443 | char const *locale = setlocale (LC_CTYPE, NULL); | ||
| 444 | char *codeset = buf; | ||
| 445 | size_t codesetlen; | ||
| 446 | codeset[0] = '\0'; | ||
| 447 | |||
| 448 | if (locale && locale[0]) | ||
| 449 | { | ||
| 450 | /* If the locale name contains an encoding after the | ||
| 451 | dot, return it. */ | ||
| 452 | char *dot = strchr (locale, '.'); | ||
| 453 | |||
| 454 | if (dot) | ||
| 455 | { | ||
| 456 | /* Look for the possible @... trailer and remove it, | ||
| 457 | if any. */ | ||
| 458 | char *codeset_start = dot + 1; | ||
| 459 | char const *modifier = strchr (codeset_start, '@'); | ||
| 460 | |||
| 461 | if (! modifier) | ||
| 462 | codeset = codeset_start; | ||
| 463 | else | ||
| 464 | { | ||
| 465 | codesetlen = modifier - codeset_start; | ||
| 466 | if (codesetlen < sizeof buf) | ||
| 467 | { | ||
| 468 | codeset = memcpy (buf, codeset_start, codesetlen); | ||
| 469 | codeset[codesetlen] = '\0'; | ||
| 470 | } | ||
| 471 | } | ||
| 472 | } | ||
| 473 | } | ||
| 474 | /* If setlocale is successful, it returns the number of the | ||
| 475 | codepage, as a string. Otherwise, fall back on Windows | ||
| 476 | API GetACP, which returns the locale's codepage as a | ||
| 477 | number (although this doesn't change according to what | ||
| 478 | the 'setlocale' call specified). Either way, prepend | ||
| 479 | "CP" to make it a valid codeset name. */ | ||
| 480 | codesetlen = strlen (codeset); | ||
| 481 | if (0 < codesetlen && codesetlen < sizeof buf - 2) | ||
| 482 | memmove (buf + 2, codeset, codesetlen + 1); | ||
| 483 | else | ||
| 484 | sprintf (buf + 2, "%u", GetACP ()); | ||
| 485 | codeset = memcpy (buf, "CP", 2); | ||
| 486 | |||
| 487 | return codeset; | ||
| 488 | } | ||
| 489 | default: | ||
| 490 | return (char *) ""; | ||
| 491 | } | ||
| 492 | } | ||