This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=15af35e78ad21a4a52a0ea22a689da93ccbf1e0a commit 15af35e78ad21a4a52a0ea22a689da93ccbf1e0a Author: Guillem Jover <[email protected]> AuthorDate: Mon Sep 2 13:00:40 2019 +0200 libdpkg: Add new C locale switch over support This will make it possible to select either the current locale or a specified one, currently only C is selectable. We use this because the uselocale(3) POSIX API is recent, and the system might not have it available, so we might need to fallback to use setlocale(3) instead, which even though is not thread-safe, it's better than nothing. --- configure.ac | 1 + debian/changelog | 1 + dpkg-deb/main.c | 1 + dpkg-split/main.c | 1 + dselect/main.cc | 1 + lib/dpkg/i18n.c | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/dpkg/i18n.h | 8 ++++++++ lib/dpkg/libdpkg.map | 1 + src/divertcmd.c | 1 + src/main.c | 1 + src/querycmd.c | 1 + src/statcmd.c | 1 + src/trigcmd.c | 1 + 13 files changed, 61 insertions(+) diff --git a/configure.ac b/configure.ac index 171a85e58..bb51ed0e7 100644 --- a/configure.ac +++ b/configure.ac @@ -182,6 +182,7 @@ AC_CHECK_FUNCS([\ fallocate \ posix_fallocate \ posix_fadvise \ + uselocale \ ]) AS_IF([test "x$build_dselect" = "xyes"], [ diff --git a/debian/changelog b/debian/changelog index eb0f4da81..904ce31d3 100644 --- a/debian/changelog +++ b/debian/changelog @@ -49,6 +49,7 @@ dpkg (1.20.0) UNRELEASED; urgency=medium - dselect: Reduce scope of variable, to avoid it being unused in a branch. - dpkg-deb: Fold two adjacent if conditionals into a single one. - dpkg: Initialize flagdeppossi in check_conflict(). + - libdpkg: Add new C locale switch over support. * Build system: - Bump minimal Perl version to 5.24.1. - Add a serial versioning to the m4 files. diff --git a/dpkg-deb/main.c b/dpkg-deb/main.c index 52e9ce67d..3420e44b7 100644 --- a/dpkg-deb/main.c +++ b/dpkg-deb/main.c @@ -252,6 +252,7 @@ int main(int argc, const char *const *argv) { ret = cipaction->action(argv); dpkg_program_done(); + dpkg_locales_done(); return ret; } diff --git a/dpkg-split/main.c b/dpkg-split/main.c index bcc1dc7b6..e807329a3 100644 --- a/dpkg-split/main.c +++ b/dpkg-split/main.c @@ -173,6 +173,7 @@ int main(int argc, const char *const *argv) { m_output(stderr, _("<standard error>")); dpkg_program_done(); + dpkg_locales_done(); return ret; } diff --git a/dselect/main.cc b/dselect/main.cc index e634e7447..32b53cbb0 100644 --- a/dselect/main.cc +++ b/dselect/main.cc @@ -532,6 +532,7 @@ main(int, const char *const *argv) cursesoff(); dpkg_program_done(); + dpkg_locales_done(); return(0); } diff --git a/lib/dpkg/i18n.c b/lib/dpkg/i18n.c index 147c5756e..495270003 100644 --- a/lib/dpkg/i18n.c +++ b/lib/dpkg/i18n.c @@ -23,6 +23,10 @@ #include <dpkg/i18n.h> +#ifdef HAVE_USELOCALE +static locale_t dpkg_C_locale; +#endif + void dpkg_locales_init(const char *package) { @@ -30,6 +34,10 @@ dpkg_locales_init(const char *package) bindtextdomain(package, LOCALEDIR); textdomain(package); +#ifdef HAVE_USELOCALE + dpkg_C_locale = newlocale(LC_ALL_MASK, "C", (locale_t)0); +#endif + #if defined(__APPLE__) && defined(__MACH__) /* * On Mac OS X, the libintl code needs to call into the CoreFoundation @@ -44,3 +52,37 @@ dpkg_locales_init(const char *package) gettext(""); #endif } + +void +dpkg_locales_done(void) +{ +#ifdef HAVE_USELOCALE + freelocale(dpkg_C_locale); + dpkg_C_locale = (locale_t)0; +#endif +} + +struct dpkg_locale +dpkg_locale_switch_C(void) +{ + struct dpkg_locale loc; + +#ifdef HAVE_USELOCALE + loc.oldloc = uselocale(dpkg_C_locale); +#else + loc.oldloc = setlocale(LC_ALL, NULL); + setlocale(LC_ALL, "C"); +#endif + + return loc; +} + +void +dpkg_locale_switch_back(struct dpkg_locale loc) +{ +#ifdef HAVE_USELOCALE + uselocale(loc.oldloc); +#else + setlocale(LC_ALL, loc.oldloc); +#endif +} diff --git a/lib/dpkg/i18n.h b/lib/dpkg/i18n.h index e92158f15..f574433a2 100644 --- a/lib/dpkg/i18n.h +++ b/lib/dpkg/i18n.h @@ -43,6 +43,14 @@ DPKG_BEGIN_DECLS #define C_(ctxt, str) pgettext(ctxt, str) void dpkg_locales_init(const char *package); +void dpkg_locales_done(void); + +struct dpkg_locale { + void *oldloc; +}; + +struct dpkg_locale dpkg_locale_switch_C(void); +void dpkg_locale_switch_back(struct dpkg_locale loc); /** @} */ diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index e30052b0d..9dd699358 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -11,6 +11,7 @@ global: # Charset and string functions dpkg_locales_init; + dpkg_locales_done; # Program name dpkg_set_progname; diff --git a/src/divertcmd.c b/src/divertcmd.c index 61b382f0e..dfc1c9033 100644 --- a/src/divertcmd.c +++ b/src/divertcmd.c @@ -855,6 +855,7 @@ main(int argc, const char * const *argv) modstatdb_shutdown(); dpkg_program_done(); + dpkg_locales_done(); return ret; } diff --git a/src/main.c b/src/main.c index 2bb0a22ae..0cc8759af 100644 --- a/src/main.c +++ b/src/main.c @@ -783,6 +783,7 @@ int main(int argc, const char *const *argv) { free_invoke_hooks(&post_invoke_hooks); dpkg_program_done(); + dpkg_locales_done(); return reportbroken_retexitstatus(ret); } diff --git a/src/querycmd.c b/src/querycmd.c index 6ee555e4e..472d87f79 100644 --- a/src/querycmd.c +++ b/src/querycmd.c @@ -862,6 +862,7 @@ int main(int argc, const char *const *argv) { ret = cipaction->action(argv); dpkg_program_done(); + dpkg_locales_done(); return !!ret; } diff --git a/src/statcmd.c b/src/statcmd.c index 33a426abb..2507b31be 100644 --- a/src/statcmd.c +++ b/src/statcmd.c @@ -422,6 +422,7 @@ main(int argc, const char *const *argv) ret = cipaction->action(argv); dpkg_program_done(); + dpkg_locales_done(); return ret; } diff --git a/src/trigcmd.c b/src/trigcmd.c index af8119c87..7c547a3bf 100644 --- a/src/trigcmd.c +++ b/src/trigcmd.c @@ -251,6 +251,7 @@ main(int argc, const char *const *argv) } dpkg_program_done(); + dpkg_locales_done(); return 0; } -- Dpkg.Org's dpkg

