From nobody Wed May 1 22:25:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498065056993724.454843282035; Wed, 21 Jun 2017 10:10:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 170463D955; Wed, 21 Jun 2017 17:10:54 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB8AF171B9; Wed, 21 Jun 2017 17:10:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 602A1184383E; Wed, 21 Jun 2017 17:10:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5LHApYc003592 for ; Wed, 21 Jun 2017 13:10:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4F29D61F3C; Wed, 21 Jun 2017 17:10:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 49D2561F20 for ; Wed, 21 Jun 2017 17:10:49 +0000 (UTC) Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 18973BDD0 for ; Wed, 21 Jun 2017 17:10:48 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id x58so28181695qtc.2 for ; Wed, 21 Jun 2017 10:10:48 -0700 (PDT) Received: from localhost.localdomain ([187.107.181.84]) by smtp.googlemail.com with ESMTPSA id z51sm2089465qtz.11.2017.06.21.10.10.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 10:10:46 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 170463D955 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 170463D955 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="vRHQjRtX" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 18973BDD0 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcfaracco@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 18973BDD0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=0D5VCx+ExHs+SMDLpwM6B5+Yi/v0xVJIR5cgClaIZ7Y=; b=vRHQjRtXkbehaauuAikPoiYK5hTH27oSBrl4nigHwpE6boGW12D4ei78/vbBSpw36l Uj5hS8PryIPOTjnfGPtKkO3cT24/CXWqrt/weZlPk7dQgOU3jaRrSaliuL917Un+7LIq CkqzdC4/N1kK8q2h7/yEnrY+04DSB27ltr00UtWuZbhUcyQ0ALWvqa+vd5ltAgc+QIPl ga2C9A1rqzroq10DAJmKhNztwPidHbh86LGPLvF+SDOrHZvoo11Ko4x1iiebHIV2ehEM /wcdCrfTrpLUIfZVroiP6W6+q30jfA2Exumzr76fjN7uPLZwKPbuZX50EspWOc79AnZH 1Lig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0D5VCx+ExHs+SMDLpwM6B5+Yi/v0xVJIR5cgClaIZ7Y=; b=fWHa1XEJChrQwcTEbzYSUAmHkqHX7Naz1QK0zNuxto1tc7CTZYnCWPlLG2dcDvv2jo qd+WFNPAsWl7Apen2cRfvQ5wG2uspO59NbjL0ccZS/LLrlwx3rfmpQrJlyFNESA3ztna 6gpgF7wf1k0FQi8Iwq+t0z3P9a0PqRGjEQaXiXeQVW85ojCzuo7iRMMp64w8QE5jJQrL GDlRKyV0JPVEGBwS+lWqaBHt26gWTsLE3Tokye695VYQ2fEdhqh9/BlIXm24P6FfFoUO Vm8Nf5V+v+FVeNx8jBAkYUREFF8usZZ9GX7F0QtWik8jLpxdCW+cnQO5TIcIDReqHIJu s9eA== X-Gm-Message-State: AKS2vOwazuo+PxH2RULK6Suvd4dJaQNEncfOc1O4u6kFQoijw0QdhqCt izFqwSdno9ftnflk X-Received: by 10.237.43.69 with SMTP id p63mr42819076qtd.200.1498065047075; Wed, 21 Jun 2017 10:10:47 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Wed, 21 Jun 2017 14:08:28 -0300 Message-Id: <1498064909-8189-2-git-send-email-jcfaracco@gmail.com> In-Reply-To: <1498064909-8189-1-git-send-email-jcfaracco@gmail.com> References: <1498064909-8189-1-git-send-email-jcfaracco@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 21 Jun 2017 17:10:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 21 Jun 2017 17:10:48 +0000 (UTC) for IP:'209.85.216.196' DOMAIN:'mail-qt0-f196.google.com' HELO:'mail-qt0-f196.google.com' FROM:'jcfaracco@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.67 (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.216.196 mail-qt0-f196.google.com 209.85.216.196 mail-qt0-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 1/2] util: moving virDoubleToStr() from virutil to virstring. X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 21 Jun 2017 17:10:54 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 --- 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 b= ase, return 0; } =20 +/* In case thread-safe locales are available */ +#if HAVE_NEWLOCALE + +static locale_t virLocale; + +static int +virLocaleOnceInit(void) +{ + virLocale =3D 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; } =20 +/** + * 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 =3D -1; + +#if HAVE_NEWLOCALE + + locale_t old_loc; + + if (virLocaleInitialize() < 0) + goto error; + + old_loc =3D uselocale(virLocale); + ret =3D virAsprintf(strp, "%lf", number); + uselocale(old_loc); + +#else + + char *radix, *tmp; + struct lconv *lc; + + if ((ret =3D virAsprintf(strp, "%lf", number) < 0)) + goto error; + + lc =3D localeconv(); + radix =3D lc->decimal_point; + tmp =3D strstr(*strp, radix); + if (tmp) { + *tmp =3D '.'; + 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; =20 +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; } =20 -/* In case thread-safe locales are available */ -#if HAVE_NEWLOCALE - -static locale_t virLocale; - -static int -virLocaleOnceInit(void) -{ - virLocale =3D 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 =3D -1; - -#if HAVE_NEWLOCALE - - locale_t old_loc; - - if (virLocaleInitialize() < 0) - goto error; - - old_loc =3D uselocale(virLocale); - ret =3D virAsprintf(strp, "%lf", number); - uselocale(old_loc); - -#else - - char *radix, *tmp; - struct lconv *lc; - - if ((ret =3D virAsprintf(strp, "%lf", number) < 0)) - goto error; - - lc =3D localeconv(); - radix =3D lc->decimal_point; - tmp =3D strstr(*strp, radix); - if (tmp) { - *tmp =3D '.'; - if (strlen(radix) > 1) - memmove(tmp + 1, tmp + strlen(radix), strlen(*strp) - (tmp - *= strp)); - } - -#endif /* HAVE_NEWLOCALE */ - error: - return ret; -} - =20 /** * 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); =20 -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; =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 22:25:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498065086400689.676766087016; Wed, 21 Jun 2017 10:11:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC6AC7F3F2; Wed, 21 Jun 2017 17:11:23 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A14CB5C7A9; Wed, 21 Jun 2017 17:11:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5C6454E982; Wed, 21 Jun 2017 17:11:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5LHBLEf003653 for ; Wed, 21 Jun 2017 13:11:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7E46A60470; Wed, 21 Jun 2017 17:11:21 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 77E1B5C7A9 for ; Wed, 21 Jun 2017 17:11:17 +0000 (UTC) Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ECB3B61A14 for ; Wed, 21 Jun 2017 17:11:15 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id c20so4162640qte.0 for ; Wed, 21 Jun 2017 10:11:15 -0700 (PDT) Received: from localhost.localdomain ([187.107.181.84]) by smtp.googlemail.com with ESMTPSA id z51sm2089465qtz.11.2017.06.21.10.10.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 10:11:14 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CC6AC7F3F2 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CC6AC7F3F2 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KopRY0cC" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ECB3B61A14 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jcfaracco@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ECB3B61A14 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=sSs1Ys5YXm2+QpPIQ/fHZ+qvj9lgh1+YqaTMqPWrbZg=; b=KopRY0cCqRKJbx65tIru0ueqtOway+x2dtTe20NVIDrOS0eTgrNtKw7HeXC6+FOYbe 0VA5dPoc6GELxkMfFNX2Xi06IbzNQrrX8bPTVo8HEeTDDPCAhn6UtZAVBVEfwoT9372O Eku2iMabvRhvpkuNKfaE5zwj6HmwJ9VEBTVWM2PkOUrJ4lNx0DLxAcWFtfzhNAidVF4k aOnD+H9/Nm/+3QtXSiKlZyHHl3EgPuD8ziuc2RAUSTy6zUiv9hyXxSeZrPfUB7eT2p3z S7pfDTwndUCFaBPAycDZRIsl1HnIE5xtPmvON+sDQ7crkHwHvYZIOyyVH5mc+0JnAS2d nuaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=sSs1Ys5YXm2+QpPIQ/fHZ+qvj9lgh1+YqaTMqPWrbZg=; b=YSPqYNhw09SAH21f8iRqpYJaEeMwso6UXkIsRL+eV1StbI9jBG8vkUM++ytK1MdS7z CKtoy8e5fYSTdhOqZ3sfGMR2l+HCtitaUue3GGgLtx3mbAFbmLgbME64yOk2n3YwQJ39 8Xny/CKO1/N0XIzVurPpwpTcjqu4EWmMKpwi91n8EQy16t2kIJsQL1oUs7a8pbKWM96Q zXOcwgGhKyQMt+xuc97yOEBI2a3gGRi2gR5dSUzWE46vDBtiSK8466KvAlt6mwL4e7jK 6HM4PXD7MZXylW0f22NSDu2XYvziZZdgHaVFcCp3075j0vxyw7CrQi8iqc0aUW71MA0D 0Oew== X-Gm-Message-State: AKS2vOx4pD81VjtekirYMM6258x9kLlP+I6+S9iVXAs5PRuVcu3lDN2d AsbhVSjlVoyQBi29 X-Received: by 10.237.33.78 with SMTP id 72mr38618329qtc.99.1498065074953; Wed, 21 Jun 2017 10:11:14 -0700 (PDT) From: Julio Faracco To: libvir-list@redhat.com Date: Wed, 21 Jun 2017 14:08:29 -0300 Message-Id: <1498064909-8189-3-git-send-email-jcfaracco@gmail.com> In-Reply-To: <1498064909-8189-1-git-send-email-jcfaracco@gmail.com> References: <1498064909-8189-1-git-send-email-jcfaracco@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 21 Jun 2017 17:11:16 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 21 Jun 2017 17:11:16 +0000 (UTC) for IP:'209.85.216.196' DOMAIN:'mail-qt0-f196.google.com' HELO:'mail-qt0-f196.google.com' FROM:'jcfaracco@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.67 (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.216.196 mail-qt0-f196.google.com 209.85.216.196 mail-qt0-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 2/2] util: fix locale problem with virStrToDouble(). X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 21 Jun 2017 17:11:24 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This commit fixes a locale problem with locales that use comma as a mantissa separator. Example: 12.34 en_US =3D 12,34 pt_BR. Since strtod() is a non-sa= fe function, virStrToDouble() will have problems to parse double numbers from kernel settings and other double numbers from static files (XMLs, JSONs, et= c). Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1457634 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1457481 Signed-off-by: Julio Faracco --- src/util/virstring.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/util/virstring.c b/src/util/virstring.c index 9c12f7b..1bd6777 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -534,7 +534,13 @@ virLocaleOnceInit(void) VIR_ONCE_GLOBAL_INIT(virLocale); #endif =20 - +/** + * virStrToDouble + * + * converts string with C locale (thread-safe) to double. + * + * Returns -1 on error or returns 0 on success. + */ int virStrToDouble(char const *s, char **end_ptr, @@ -545,7 +551,17 @@ virStrToDouble(char const *s, int err; =20 errno =3D 0; +#if HAVE_NEWLOCALE + locale_t old_loc; + if (virLocaleInitialize() < 0) + return -1; + + old_loc =3D uselocale(virLocale); +#endif val =3D strtod(s, &p); /* exempt from syntax-check */ +#if HAVE_NEWLOCALE + uselocale(old_loc); +#endif err =3D (errno || (!end_ptr && *p) || p =3D=3D s); if (end_ptr) *end_ptr =3D p; --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list