From 935072fed354c9ddd0704a552be1f6996bfccc10 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Mon, 2 Sep 2019 13:00:40 +0200 Subject: libdpkg: Add new versiondescribe_c() to force a C locale In some contexts we need output in the C locale, such as log files. We add a new versiondescribe_c() that wraps the locale-dependant versiondescribe() function and switches to the C locale and back to the previous one before returning. --- debian/changelog | 1 + lib/dpkg/dpkg-db.h | 2 ++ lib/dpkg/libdpkg.map | 1 + lib/dpkg/parsehelp.c | 14 ++++++++++++++ 4 files changed, 18 insertions(+) diff --git a/debian/changelog b/debian/changelog index 904ce31d3..e89b28849 100644 --- a/debian/changelog +++ b/debian/changelog @@ -50,6 +50,7 @@ dpkg (1.20.0) UNRELEASED; urgency=medium - 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. + - libdpkg: Add new versiondescribe_c() to force a C locale. * Build system: - Bump minimal Perl version to 5.24.1. - Add a serial versioning to the m4 files. diff --git a/lib/dpkg/dpkg-db.h b/lib/dpkg/dpkg-db.h index 3e9158def..10de6d3e2 100644 --- a/lib/dpkg/dpkg-db.h +++ b/lib/dpkg/dpkg-db.h @@ -392,6 +392,8 @@ int parseversion(struct dpkg_version *version, const char *, struct dpkg_error *err); const char *versiondescribe(const struct dpkg_version *, enum versiondisplayepochwhen); +const char *versiondescribe_c(const struct dpkg_version *version, + enum versiondisplayepochwhen vdew); enum pkg_name_arch_when { /** Never display arch. */ diff --git a/lib/dpkg/libdpkg.map b/lib/dpkg/libdpkg.map index 9dd699358..953944752 100644 --- a/lib/dpkg/libdpkg.map +++ b/lib/dpkg/libdpkg.map @@ -256,6 +256,7 @@ LIBDPKG_PRIVATE { dpkg_version_compare; dpkg_version_relate; versiondescribe; + versiondescribe_c; parseversion; # Architecture database diff --git a/lib/dpkg/parsehelp.c b/lib/dpkg/parsehelp.c index a9095f1f4..34247269e 100644 --- a/lib/dpkg/parsehelp.c +++ b/lib/dpkg/parsehelp.c @@ -188,6 +188,20 @@ const char *versiondescribe return vb->buf; } +const char * +versiondescribe_c(const struct dpkg_version *version, + enum versiondisplayepochwhen vdew) +{ + struct dpkg_locale oldloc; + const char *str; + + oldloc = dpkg_locale_switch_C(); + str = versiondescribe(version, vdew); + dpkg_locale_switch_back(oldloc); + + return str; +} + /** * Parse a version string and check for invalid syntax. * -- cgit v1.2.3