diff options
author | Jan Kara <jack@suse.cz> | 2012-11-06 12:12:19 +0100 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2012-11-06 12:12:19 +0100 |
commit | d8bb9ec3cef26cd3fb62534d896bf9c8feea67f9 (patch) | |
tree | c29c757277b2d64d8997d29495a407b093eeb2c5 | |
parent | aebb8189069f24e6f4e59cf79f179bcbafe7a098 (diff) | |
download | linuxquota-d8bb9ec3cef26cd3fb62534d896bf9c8feea67f9.tar.gz |
warnquota: Use current locale as default charset
If charset in warnquota.conf is not specified, use charset from current
locale as the charset of the warning email. This is to accomodate possible
translations of messages via gettext.
Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r-- | warnquota.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/warnquota.c b/warnquota.c index 80f528c..5c5a1b9 100644 --- a/warnquota.c +++ b/warnquota.c @@ -29,6 +29,8 @@ #include <grp.h> #include <time.h> #include <getopt.h> +#include <locale.h> +#include <langinfo.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/utsname.h> @@ -707,6 +709,7 @@ static int readconfigfile(const char *filename, struct configparams *config) char *value; char *pos; int line, len, bufpos; + char *locale; /* set default values */ sstrncpy(config->mail_cmd, MAIL_CMD, CNF_BUFFER); @@ -716,6 +719,12 @@ static int readconfigfile(const char *filename, struct configparams *config) sstrncpy(config->support, SUPPORT, CNF_BUFFER); sstrncpy(config->phone, PHONE, CNF_BUFFER); (config->charset)[0] = '\0'; + setlocale(LC_ALL, NULL); + locale = setlocale(LC_MESSAGES, NULL); + if (locale && strcasecmp(locale, "posix") && strcasecmp(locale, "c")) { + locale = nl_langinfo(CODESET); + sstrncpy(config->charset, locale, CNF_BUFFER); + } maildev[0] = 0; config->user_signature = config->user_message = config->group_signature = config->group_message = NULL; config->use_ldap_mail = 0; |