lib: Enable locale dependent output to a terminal

If we are in an interactive session, enable the locale. This allows for
features like setting thousand separators for printing large values. By
only enabling it for interactive terminals, we avoid changing outputs
for the test scripts (leaving them as the "C" locale).

Note this mainly affects the testcases, or binaries built using libigt.
Other binaries need to be localised separately.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Michel Thierry <michel.thierry@intel.com>
This commit is contained in:
Chris Wilson 2015-06-24 11:26:33 +01:00
parent 7eb5f07949
commit 453792c501

View File

@ -55,6 +55,7 @@
#include <time.h>
#include <ctype.h>
#include <limits.h>
#include <locale.h>
#include "drmtest.h"
#include "intel_chipset.h"
@ -522,6 +523,9 @@ static int common_init(int *argc, char **argv,
int ret = 0;
char *env = getenv("IGT_LOG_LEVEL");
if (isatty(STDOUT_FILENO))
setlocale(LC_ALL, "");
if (env) {
if (strcmp(env, "debug") == 0)
igt_log_level = IGT_LOG_DEBUG;