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
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <limits>
|
||||
#include <set>
|
||||
|
||||
#include "check.hxx"
|
||||
#include "plugin.hxx"
|
||||
|
||||
namespace {
|
||||
@@ -128,6 +129,11 @@ bool Nullptr::VisitImplicitCastExpr(CastExpr const * expr) {
|
||||
case Expr::NPCK_CXX11_nullptr:
|
||||
break;
|
||||
default:
|
||||
if (loplugin::TypeCheck(expr->getType()).Typedef("locale_t")
|
||||
.GlobalNamespace())
|
||||
{
|
||||
break; // POSIX locale_t is left unspecified
|
||||
}
|
||||
handleNull(expr->getSubExpr(), expr->getCastKindName(), k);
|
||||
break;
|
||||
}
|
||||
|
@@ -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);
|
||||
|
||||
//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;
|
||||
freelocale(loc);
|
||||
|
||||
if (width == w.word/100 && height == h.word/100)
|
||||
//glibc stores sizes as integer mm units
|
||||
w.word *= 100;
|
||||
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;
|
||||
|
||||
aInstance = PaperInfo(w.word, h.word);
|
||||
bInitialized = true;
|
||||
return aInstance;
|
||||
//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;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user