From nobody Mon Feb 9 01:48:30 2026 Delivered-To: importer@patchew.org Received-SPF: permerror (zohomail.com: Error in processing SPF Record) client-ip=216.145.221.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=permerror (zohomail.com: Error in processing SPF Record) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1687176245; cv=none; d=zohomail.com; s=zohoarc; b=QzAgwZolyzdgyi/l2qsMezLo69ErXnuE8B9vGNDvBWMC4QfkikyV+EWfaR898Cx5FxCIK5ndhNSGCo5HOLCtmao89fGW3p9ugFa46o85tyBqurQp7aTs4Aui7vHXOEo9LA9hokihLyYFYvybwMiaDKjFNJxTDMvx0Sx+ERJtfnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687176245; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kT/F6/Mh23WgFbXL8io+BV2SgXnkhORNs/GPJetfFKQ=; b=lFYdPGBTcjNG2org/G+ezsnx/Kybf54G+5U6jkGZAl3rTra2w0zX+Ye/uJwdEI2E+4/GzVp/ocudD9ZIDW/9ISQ4NQT0lTw3xiRu5fIkSU5G0wYzfokUK53qN0JXrINd5tqn/FizVuF5YzUrEV0snrlSsxYvr3P6mcWFfHoYqZc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=permerror (zohomail.com: Error in processing SPF Record) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.145.221.124]) by mx.zohomail.com with SMTPS id 1687176245277520.915067153066; Mon, 19 Jun 2023 05:04:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-2-Dq8MUexiOgiifW-aOUIskA-1; Mon, 19 Jun 2023 08:03:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B2A71185A794; Mon, 19 Jun 2023 12:03:54 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DD6F2166B26; Mon, 19 Jun 2023 12:03:53 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 170401946594; Mon, 19 Jun 2023 12:03:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1A3C41946589 for ; Mon, 19 Jun 2023 12:03:51 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EE64C40C20F6; Mon, 19 Jun 2023 12:03:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.43.2.36]) by smtp.corp.redhat.com (Postfix) with ESMTP id 965EA40C20F5 for ; Mon, 19 Jun 2023 12:03:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687176244; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=kT/F6/Mh23WgFbXL8io+BV2SgXnkhORNs/GPJetfFKQ=; b=NZpFcM2ccS5Fzori72UxqFWtmA33BBfk4ZuuuuqYRZxmymTsFUbeEoIrDBpmhAiuyPJwH7 aDtIUPGKIXW9RgFC3nV2zDf4hPQtMnRpDSWLb2pkn/4D820ahhfP3Q4bBF73GV94IQvXp6 zk037kU+sfG+CNfRx90eNgW7kpFMrII= X-MC-Unique: Dq8MUexiOgiifW-aOUIskA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] virstring: Move locale wrappers at the beginning Date: Mon, 19 Jun 2023 14:03:47 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687176246740100001 Content-Type: text/plain; charset="utf-8"; x-default="true" 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 --- 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 @@ =20 VIR_LOG_INIT("util.string"); =20 +/* In case thread-safe locales are available */ +#if WITH_NEWLOCALE + +typedef locale_t virLocale; +static virLocale virLocaleRaw; + +static int +virLocaleOnceInit(void) +{ + virLocaleRaw =3D 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 =3D 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 =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 /* !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 b= ase, return 0; } =20 -/* In case thread-safe locales are available */ -#if WITH_NEWLOCALE - -typedef locale_t virLocale; -static virLocale virLocaleRaw; - -static int -virLocaleOnceInit(void) -{ - virLocaleRaw =3D 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 =3D 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 =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 /* !WITH_NEWLOCALE */ - =20 /** * virStrToDouble --=20 2.39.3