diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-03-22 08:44:14 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-03-22 08:48:00 +0100 |
commit | a7cdba3a0e48360e2ed549e9d8996fe41460df70 (patch) | |
tree | df48882124a4fc28a93e24e34a96be3b2d4efd2a /i18nutil | |
parent | 7299481834b15c920f996f4b0f3b5f821a82a10d (diff) |
Use nl_langinfo_l with an explicitly created locale
(where empty string arg to newlocale, per SUSv4, means "an implementation-
defined native environment. This correspons to the value of the associated
environment variables, LC_* and LANG") instead of relying on whatever setlocale
would be in effect here.
Also, nl_langinfo_l is less of an MT nightmare than nl_langinfo, which is of
benefit once the last remaining use of nl_langinfo in sal/osl/unx/nlsupport.cxx
will also have been changed to nl_langinfo_l.
loplugin:nullptr needs a little hack, as SUSv4 locale_t could be anything from
an integer type to a pointer type.
Change-Id: Ic35dcbc2e0a4f650694b48df12470dd89476dff5
Diffstat (limited to 'i18nutil')
-rw-r--r-- | i18nutil/source/utility/paper.cxx | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/i18nutil/source/utility/paper.cxx b/i18nutil/source/utility/paper.cxx index 09440f46be6d..3a6e98a28d4f 100644 --- a/i18nutil/source/utility/paper.cxx +++ b/i18nutil/source/utility/paper.cxx @@ -290,39 +290,43 @@ PaperInfo PaperInfo::getSystemDefaultPaper() } #if defined(LC_PAPER) && defined(_GNU_SOURCE) - - union paperword { char *string; int word; }; - // try LC_PAPER - paperword w, h; - w.string = nl_langinfo(_NL_PAPER_WIDTH); - h.string = nl_langinfo(_NL_PAPER_HEIGHT); - - //glibc stores sizes as integer mm units - w.word *= 100; - h.word *= 100; - - for ( size_t i = 0; i < nTabSize; ++i ) + locale_t loc = newlocale(LC_PAPER_MASK, "", static_cast<locale_t>(0)); + if (loc != static_cast<locale_t>(0)) { - if (i == PAPER_USER) continue; + union paperword { char *string; int word; }; + paperword w, h; + w.string = nl_langinfo_l(_NL_PAPER_WIDTH, loc); + h.string = nl_langinfo_l(_NL_PAPER_HEIGHT, loc); + + freelocale(loc); - //glibc stores sizes as integer mm units, and so is inaccurate. To - //find a standard paper size we calculate the standard paper sizes - //into equally inaccurate mm and compare - long width = (aDinTab[i].m_nWidth + 50) / 100; - long height = (aDinTab[i].m_nHeight + 50) / 100; + //glibc stores sizes as integer mm units + w.word *= 100; + h.word *= 100; - if (width == w.word/100 && height == h.word/100) + for ( size_t i = 0; i < nTabSize; ++i ) { - w.word = aDinTab[i].m_nWidth; - h.word = aDinTab[i].m_nHeight; - break; + if (i == PAPER_USER) continue; + + //glibc stores sizes as integer mm units, and so is inaccurate. + //To find a standard paper size we calculate the standard paper + //sizes into equally inaccurate mm and compare + long width = (aDinTab[i].m_nWidth + 50) / 100; + long height = (aDinTab[i].m_nHeight + 50) / 100; + + if (width == w.word/100 && height == h.word/100) + { + w.word = aDinTab[i].m_nWidth; + h.word = aDinTab[i].m_nHeight; + break; + } } - } - aInstance = PaperInfo(w.word, h.word); - bInitialized = true; - return aInstance; + aInstance = PaperInfo(w.word, h.word); + bInitialized = true; + return aInstance; + } #endif } #endif |