[PATCH 1/2] virstring: Move locale wrappers at the beginning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We will soon need the virLocaleRaw variable. Move it and
functions around it at the beginning of the file, so that
later code doesn't need to introduce forward declarations.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/util/virstring.c | 157 ++++++++++++++++++++++---------------------
 1 file changed, 79 insertions(+), 78 deletions(-)

diff --git a/src/util/virstring.c b/src/util/virstring.c
index 6b728ff047..1a13570d30 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -35,6 +35,85 @@
 
 VIR_LOG_INIT("util.string");
 
+/* In case thread-safe locales are available */
+#if WITH_NEWLOCALE
+
+typedef locale_t virLocale;
+static virLocale virLocaleRaw;
+
+static int
+virLocaleOnceInit(void)
+{
+    virLocaleRaw = newlocale(LC_ALL_MASK, "C", (locale_t)0);
+    if (!virLocaleRaw)
+        return -1;
+    return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virLocale);
+
+/**
+ * virLocaleSetRaw:
+ *
+ * @oldlocale: set to old locale pointer
+ *
+ * Sets the locale to 'C' to allow operating on non-localized objects.
+ * Returns 0 on success -1 on error.
+ */
+static int
+virLocaleSetRaw(virLocale *oldlocale)
+{
+    if (virLocaleInitialize() < 0)
+        return -1;
+    *oldlocale = uselocale(virLocaleRaw);
+    return 0;
+}
+
+static void
+virLocaleRevert(virLocale *oldlocale)
+{
+    uselocale(*oldlocale);
+}
+
+static void
+virLocaleFixupRadix(char **strp G_GNUC_UNUSED)
+{
+}
+
+#else /* !WITH_NEWLOCALE */
+
+typedef int virLocale;
+
+static int
+virLocaleSetRaw(virLocale *oldlocale G_GNUC_UNUSED)
+{
+    return 0;
+}
+
+static void
+virLocaleRevert(virLocale *oldlocale G_GNUC_UNUSED)
+{
+}
+
+static void
+virLocaleFixupRadix(char **strp)
+{
+    char *radix, *tmp;
+    struct lconv *lc;
+
+    lc = localeconv();
+    radix = lc->decimal_point;
+    tmp = strstr(*strp, radix);
+    if (tmp) {
+        *tmp = '.';
+        if (strlen(radix) > 1)
+            memmove(tmp + 1, tmp + strlen(radix), strlen(*strp) - (tmp - *strp));
+    }
+}
+
+#endif /* !WITH_NEWLOCALE */
+
+
 /* Like strtol with C locale, but produce an "int" result, and check more carefully.
    Return 0 upon success;  return -1 to indicate failure.
    When END_PTR is NULL, the byte after the final valid digit must be NUL.
@@ -233,84 +312,6 @@ virStrToLong_ullp(char const *s, char **end_ptr, int base,
     return 0;
 }
 
-/* In case thread-safe locales are available */
-#if WITH_NEWLOCALE
-
-typedef locale_t virLocale;
-static virLocale virLocaleRaw;
-
-static int
-virLocaleOnceInit(void)
-{
-    virLocaleRaw = newlocale(LC_ALL_MASK, "C", (locale_t)0);
-    if (!virLocaleRaw)
-        return -1;
-    return 0;
-}
-
-VIR_ONCE_GLOBAL_INIT(virLocale);
-
-/**
- * virLocaleSetRaw:
- *
- * @oldlocale: set to old locale pointer
- *
- * Sets the locale to 'C' to allow operating on non-localized objects.
- * Returns 0 on success -1 on error.
- */
-static int
-virLocaleSetRaw(virLocale *oldlocale)
-{
-    if (virLocaleInitialize() < 0)
-        return -1;
-    *oldlocale = uselocale(virLocaleRaw);
-    return 0;
-}
-
-static void
-virLocaleRevert(virLocale *oldlocale)
-{
-    uselocale(*oldlocale);
-}
-
-static void
-virLocaleFixupRadix(char **strp G_GNUC_UNUSED)
-{
-}
-
-#else /* !WITH_NEWLOCALE */
-
-typedef int virLocale;
-
-static int
-virLocaleSetRaw(virLocale *oldlocale G_GNUC_UNUSED)
-{
-    return 0;
-}
-
-static void
-virLocaleRevert(virLocale *oldlocale G_GNUC_UNUSED)
-{
-}
-
-static void
-virLocaleFixupRadix(char **strp)
-{
-    char *radix, *tmp;
-    struct lconv *lc;
-
-    lc = localeconv();
-    radix = lc->decimal_point;
-    tmp = strstr(*strp, radix);
-    if (tmp) {
-        *tmp = '.';
-        if (strlen(radix) > 1)
-            memmove(tmp + 1, tmp + strlen(radix), strlen(*strp) - (tmp - *strp));
-    }
-}
-
-#endif /* !WITH_NEWLOCALE */
-
 
 /**
  * virStrToDouble
-- 
2.39.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux