The function virDoubleToStr() is defined in virutil.* and virStrToDouble() is
defined in virstring.*. Joining both functions into the same file makes more
sense.

Signed-off-by: Julio Faracco <jcfara...@gmail.com>
---
 src/util/virstring.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virstring.h |  3 +++
 src/util/virutil.c   | 63 --------------------------------------------------
 src/util/virutil.h   |  3 ---
 4 files changed, 68 insertions(+), 66 deletions(-)

diff --git a/src/util/virstring.c b/src/util/virstring.c
index 089b539..9c12f7b 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -28,6 +28,7 @@
 #include "base64.h"
 #include "c-ctype.h"
 #include "virstring.h"
+#include "virthread.h"
 #include "viralloc.h"
 #include "virbuffer.h"
 #include "virerror.h"
@@ -516,6 +517,24 @@ virStrToLong_ullp(char const *s, char **end_ptr, int base,
     return 0;
 }
 
+/* In case thread-safe locales are available */
+#if HAVE_NEWLOCALE
+
+static locale_t virLocale;
+
+static int
+virLocaleOnceInit(void)
+{
+    virLocale = newlocale(LC_ALL_MASK, "C", (locale_t)0);
+    if (!virLocale)
+        return -1;
+    return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virLocale);
+#endif
+
+
 int
 virStrToDouble(char const *s,
                char **end_ptr,
@@ -536,6 +555,52 @@ virStrToDouble(char const *s,
     return 0;
 }
 
+/**
+ * virDoubleToStr
+ *
+ * converts double to string with C locale (thread-safe).
+ *
+ * Returns -1 on error, size of the string otherwise.
+ */
+int
+virDoubleToStr(char **strp, double number)
+{
+    int ret = -1;
+
+#if HAVE_NEWLOCALE
+
+    locale_t old_loc;
+
+    if (virLocaleInitialize() < 0)
+        goto error;
+
+    old_loc = uselocale(virLocale);
+    ret = virAsprintf(strp, "%lf", number);
+    uselocale(old_loc);
+
+#else
+
+    char *radix, *tmp;
+    struct lconv *lc;
+
+    if ((ret = virAsprintf(strp, "%lf", number) < 0))
+        goto error;
+
+    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 /* HAVE_NEWLOCALE */
+ error:
+    return ret;
+}
+
+
 int
 virVasprintfInternal(bool report,
                      int domcode,
diff --git a/src/util/virstring.h b/src/util/virstring.h
index 0038a40..5eaaaea 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -109,6 +109,9 @@ int virStrToDouble(char const *s,
                    double *result)
     ATTRIBUTE_RETURN_CHECK;
 
+int virDoubleToStr(char **strp, double number)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+
 void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1);
 void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1);
 void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1);
diff --git a/src/util/virutil.c b/src/util/virutil.c
index aba7c6d..d7e01d4 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -75,7 +75,6 @@
 #include "virlog.h"
 #include "virbuffer.h"
 #include "viralloc.h"
-#include "virthread.h"
 #include "verify.h"
 #include "virfile.h"
 #include "vircommand.h"
@@ -437,68 +436,6 @@ int virEnumFromString(const char *const*types,
     return -1;
 }
 
-/* In case thread-safe locales are available */
-#if HAVE_NEWLOCALE
-
-static locale_t virLocale;
-
-static int
-virLocaleOnceInit(void)
-{
-    virLocale = newlocale(LC_ALL_MASK, "C", (locale_t)0);
-    if (!virLocale)
-        return -1;
-    return 0;
-}
-
-VIR_ONCE_GLOBAL_INIT(virLocale)
-#endif
-
-/**
- * virDoubleToStr
- *
- * converts double to string with C locale (thread-safe).
- *
- * Returns -1 on error, size of the string otherwise.
- */
-int
-virDoubleToStr(char **strp, double number)
-{
-    int ret = -1;
-
-#if HAVE_NEWLOCALE
-
-    locale_t old_loc;
-
-    if (virLocaleInitialize() < 0)
-        goto error;
-
-    old_loc = uselocale(virLocale);
-    ret = virAsprintf(strp, "%lf", number);
-    uselocale(old_loc);
-
-#else
-
-    char *radix, *tmp;
-    struct lconv *lc;
-
-    if ((ret = virAsprintf(strp, "%lf", number) < 0))
-        goto error;
-
-    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 /* HAVE_NEWLOCALE */
- error:
-    return ret;
-}
-
 
 /**
  * Format @val as a base-10 decimal number, in the
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 86e9051..4938255 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -63,9 +63,6 @@ int virParseNumber(const char **str);
 int virParseVersionString(const char *str, unsigned long *version,
                           bool allowMissing);
 
-int virDoubleToStr(char **strp, double number)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
-
 char *virFormatIntDecimal(char *buf, size_t buflen, int val)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
 
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to