From nobody Mon Feb 9 19:52:54 2026 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 1492468624651846.104983175596; Mon, 17 Apr 2017 15:37:04 -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 C9188C04B940; Mon, 17 Apr 2017 22:37:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9C7F75C54F; Mon, 17 Apr 2017 22:37:02 +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 5698C5EC6B; Mon, 17 Apr 2017 22:37:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3HMaRbk018016 for ; Mon, 17 Apr 2017 18:36:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id E79DF78372; Mon, 17 Apr 2017 22:36:27 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E035117962 for ; Mon, 17 Apr 2017 22:36:26 +0000 (UTC) Received: from mail-qt0-f178.google.com (mail-qt0-f178.google.com [209.85.216.178]) (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 6026E4E8AB for ; Mon, 17 Apr 2017 22:36:25 +0000 (UTC) Received: by mail-qt0-f178.google.com with SMTP id y33so29147451qta.2 for ; Mon, 17 Apr 2017 15:36:25 -0700 (PDT) Received: from silas.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id m62sm5751088qte.5.2017.04.17.15.36.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Apr 2017 15:36:23 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C9188C04B940 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx07.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 C9188C04B940 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=datto-com.20150623.gappssmtp.com header.i=@datto-com.20150623.gappssmtp.com header.b="V8GOJPGb" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6026E4E8AB Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=sramanujam@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6026E4E8AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datto-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=w1DLtqYmn5in9+0B8lcImFyiIh2DVyTBUSmZrZQS/zE=; b=V8GOJPGb704q/mCXAfzJcdNxlx02/z/Q/H5reod9fMz8yQ7dZnGF+CXXC7t1b3RTIi Ix525MUcTvZxISLY9B16cTnwxb6CMuSWJ5CjFN3Q8xfGL7lMwUiAen/VtDE2A98FNOv7 bE7lZf6kEUJ9DSv2406XlV8fO93UHJxtRl82ZLo8vXty+vxcNarbcAwMnhWiWPRGWjGn 0QrYV5d2vbRU2fubE8DE4mdpq/kJ3klFPweb/A61Vf1+q46HNtj4VfKL8xvHquyZKM1T rHoSE+H3MOoHmBUKESbbDqJluQlLUDwTLHrqoHvxXILKXc6qbXAmIpUttPkmBRhhBMBE igrg== 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=w1DLtqYmn5in9+0B8lcImFyiIh2DVyTBUSmZrZQS/zE=; b=oXkOhMmCEd9jP3xVmJImePX+IwTIqpRlMpXqkNGo4NfaxIk66RWHFO0dAVCjAOhTih dSbstCm5ur4tWkomQQYR99HLZPX866vdt4HK3I0olLJpGBwqm4cELalqAa9KA8joKlkH a9pwRZvljiDC2ZvF72DnnBSSEsBB8ZpUunilECEm2uM7f1vTC9D+Idvo8k6uG0wmYcQc fT9j3+bjoJhQ2T+1OOjy3Ty55RcxBYCVpN9CM1ito0HwIi5BlRiOT17fjmx342CH9gdM ZqqLtTqHeKRk6Iu278qg649uvMcSy4drpPlRlRu+cIVY/JVoaOJb3DrBFJwJzkTJQlS1 dMMw== X-Gm-Message-State: AN3rC/5D9qN343hl6xRvl8yzm+cPjewkKhNs0FFaRzkenlWY8E/00mDD 8xAAjSUSd/QPwT0Rxk4= X-Received: by 10.200.57.18 with SMTP id s18mr10730198qtb.1.1492468584508; Mon, 17 Apr 2017 15:36:24 -0700 (PDT) From: Sri Ramanujam To: libvir-list@redhat.com Date: Mon, 17 Apr 2017 18:36:14 -0400 Message-Id: <20170417223615.20817-6-sramanujam@datto.com> In-Reply-To: <20170417223615.20817-1-sramanujam@datto.com> References: <20170417223615.20817-1-sramanujam@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 17 Apr 2017 22:36:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 17 Apr 2017 22:36:25 +0000 (UTC) for IP:'209.85.216.178' DOMAIN:'mail-qt0-f178.google.com' HELO:'mail-qt0-f178.google.com' FROM:'sramanujam@datto.com' RCPT:'' X-RedHat-Spam-Score: 0.179 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.216.178 mail-qt0-f178.google.com 209.85.216.178 mail-qt0-f178.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/6] util: add virNumToStr 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.31]); Mon, 17 Apr 2017 22:37:03 +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" Add virNumToStr(), which safely converts numbers into their string representation. Functions added: * virNumToStr_l * virNumToStr_ul --- src/util/virstring.c | 34 ++++++++++++++++++++++++++++++++++ src/util/virstring.h | 8 ++++++++ 2 files changed, 42 insertions(+) diff --git a/src/util/virstring.c b/src/util/virstring.c index 69abc26..f0d9e19 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -536,6 +536,40 @@ virStrToDouble(char const *s, return 0; } =20 +/** + * Converts signed number to string representation. The caller is responsi= ble + * for freeing the result. + */ +int +virNumToStr_l(long num, char **dst) +{ + int sz; + + sz =3D snprintf(NULL, 0, "%ld", num); + if (sz > 0 && VIR_ALLOC_N(*dst, sz + 1) < 0) + return -1; + + snprintf(*dst, sz + 1, "%ld", num); + return 0; +} + +/** + * Converts unsigned number to string representation. The caller is respon= sible + * for freeing the result. + */ +int +virNumToStr_ul(unsigned long num, char **dst) +{ + int sz; + + sz =3D snprintf(NULL, 0, "%lu", num); + if (sz > 0 && VIR_ALLOC_N(*dst, sz + 1) < 0) + return -1; + + snprintf(*dst, sz + 1, "%lu", num); + return 0; +} + int virVasprintfInternal(bool report, int domcode, diff --git a/src/util/virstring.h b/src/util/virstring.h index 603650a..9918e07 100644 --- a/src/util/virstring.h +++ b/src/util/virstring.h @@ -109,6 +109,13 @@ int virStrToDouble(char const *s, double *result) ATTRIBUTE_RETURN_CHECK; =20 +int virNumToStr_l(long num, + char **dst) + ATTRIBUTE_RETURN_CHECK; +int virnumToStr_ul(unsigned long num, + char **dst) + 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); @@ -288,6 +295,7 @@ bool virStringBufferIsPrintable(const uint8_t *buf, siz= e_t buflen); =20 char *virStringEncodeBase64(const uint8_t *buf, size_t buflen); =20 + static inline void virStringTrimOptionalNewline(char *str) { --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list