From: Richard Russon Date: Sat, 31 Mar 2018 18:07:28 +0000 (+0100) Subject: refactor: separate get from set Charset X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=refs%2Fpull%2F1120%2Fhead;p=neomutt refactor: separate get from set Charset --- diff --git a/init.c b/init.c index fac1ac7b0..af04193ce 100644 --- a/init.c +++ b/init.c @@ -3780,7 +3780,7 @@ int mutt_init(int skip_sys_rc, struct ListHead *commands) if (p) From = mutt_addr_parse_list(NULL, p); - mutt_ch_set_langinfo_charset(); + Charset = mutt_ch_get_langinfo_charset(); mutt_ch_set_charset(Charset); Matches = mutt_mem_calloc(MatchesListsize, sizeof(char *)); diff --git a/mutt/charset.c b/mutt/charset.c index 730834e21..657827cf7 100644 --- a/mutt/charset.c +++ b/mutt/charset.c @@ -409,22 +409,22 @@ char *mutt_ch_get_default_charset(void) } /** - * mutt_ch_set_langinfo_charset - Set the user's choice of character set + * mutt_ch_get_langinfo_charset - Get the user's choice of character set + * @retval ptr Charset string * - * Lookup the character map used by the user's locale and store it in Charset. + * Get the canonical character set used by the user's locale. + * The caller must free the returned string. */ -void mutt_ch_set_langinfo_charset(void) +char *mutt_ch_get_langinfo_charset(void) { - char buf[LONG_STRING]; - char buf2[LONG_STRING]; + char buf[LONG_STRING] = ""; - mutt_str_strfcpy(buf, nl_langinfo(CODESET), sizeof(buf)); - mutt_ch_canonical_charset(buf2, sizeof(buf2), buf); + mutt_ch_canonical_charset(buf, sizeof(buf), nl_langinfo(CODESET)); - /* finally, set $charset */ - Charset = mutt_str_strdup(buf2); - if (!Charset) - Charset = mutt_str_strdup("iso-8859-1"); + if (buf[0] != '\0') + return mutt_str_strdup(buf); + + return mutt_str_strdup("iso-8859-1"); } /** diff --git a/mutt/charset.h b/mutt/charset.h index 13c44a8c6..1c585d19e 100644 --- a/mutt/charset.h +++ b/mutt/charset.h @@ -85,7 +85,7 @@ extern const struct MimeNames PreferredMIMENames[]; void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name); int mutt_ch_chscmp(const char *cs1, const char *cs2); char * mutt_ch_get_default_charset(void); -void mutt_ch_set_langinfo_charset(void); +char * mutt_ch_get_langinfo_charset(void); void mutt_ch_set_charset(char *charset); bool mutt_ch_lookup_add(enum LookupType type, const char *pat, const char *replace, struct Buffer *err);