Fixed locale defaulting to English

Changed get_datetime() a bit so it respects the user-configured locale (to use time formats with strings for days, months etc.)

Same commit as last time, except it merges.
This commit is contained in:
Vincent Loupmon 2016-03-10 16:50:32 +01:00
parent d4d2646f63
commit 552ba7fd94
1 changed files with 4 additions and 0 deletions

View File

@ -3,6 +3,7 @@
/* global libraries */ /* global libraries */
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include <fcntl.h> #include <fcntl.h>
#include <locale.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -191,11 +192,14 @@ get_datetime()
/* get time in format */ /* get time in format */
time(&tm); time(&tm);
setlocale(LC_TIME, "");
if(!strftime(buf, bufsize, timeformat, localtime(&tm))) { if(!strftime(buf, bufsize, timeformat, localtime(&tm))) {
setlocale(LC_TIME, "C");
fprintf(stderr, "Strftime failed.\n"); fprintf(stderr, "Strftime failed.\n");
return smprintf("n/a"); return smprintf("n/a");
} }
setlocale(LC_TIME, "C");
/* return time */ /* return time */
return smprintf("%s", buf); return smprintf("%s", buf);
} }