Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert setlocale() effect as soon as possible. Closes #12.
The Xlib and ncurses libraries query the LC_CTYPE locale value to guess the usable character set. If the calling program did not call setlocale(), that character set will be severely limited. Extensive Unicode support is a reasonable libcaca user expectation. The locale is restored as soon as possible, once the window or terminal have been initialised. Unfortunately, the effect of setlocale() is process- wide, and may affect other threads. This is now documented. Note also that both Xlib and ncurses ignore the effects of uselocale() which would have been the thread-safe solution to this problem.
- Loading branch information
1 parent
f7afe3f
commit cdfba01
Showing
7 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* bug-setlocale: unit test for wrong setlocale() calls | ||
* Copyright (c) 2016 Sam Hocevar <sam@hocevar.net> | ||
* All Rights Reserved | ||
* | ||
* This program is free software. It comes without any warranty, to | ||
* the extent permitted by applicable law. You can redistribute it | ||
* and/or modify it under the terms of the Do What the Fuck You Want | ||
* to Public License, Version 2, as published by Sam Hocevar. See | ||
* http://www.wtfpl.net/ for more details. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#if !defined(__KERNEL__) | ||
# include <stdio.h> | ||
# include <stdlib.h> | ||
# include <string.h> | ||
#endif | ||
|
||
#include "caca.h" | ||
|
||
#define TEST(x) \ | ||
do \ | ||
{ \ | ||
tests++; \ | ||
if((x)) \ | ||
passed++; \ | ||
else \ | ||
fprintf(stderr, "test #%i failed: %s\n", (tests), #x); \ | ||
} \ | ||
while(0) | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
char buf[10]; | ||
char const * const * list; | ||
|
||
list = caca_get_display_driver_list(); | ||
|
||
int i, tests = 0, passed = 0; | ||
|
||
snprintf(buf, 10, "%.1f", 0.0f); | ||
TEST(buf[1] == '.'); | ||
|
||
for (i = 0; list[i]; i += 2) | ||
{ | ||
if (!strcmp(list[i], "x11") || !strcmp(list[i], "ncurses")) | ||
{ | ||
caca_display_t *dp = caca_create_display_with_driver(NULL, list[i]); | ||
|
||
snprintf(buf, 10, "%.1f", 0.0f); | ||
TEST(buf[1] == '.'); | ||
|
||
caca_free_display(dp); | ||
} | ||
} | ||
|
||
fprintf(stderr, "%i tests, %i errors\n", tests, tests - passed); | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters