Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1207783rwb; Wed, 9 Nov 2022 14:32:10 -0800 (PST) X-Google-Smtp-Source: AMsMyM52HkUKlFSeLk3Th3YObF0zxkXGHvTtw6qUF67TtQTeHdCv1h6Rj0XZShUrskiDPdxkGTBO X-Received: by 2002:a05:6402:2a03:b0:463:11e7:cd5f with SMTP id ey3-20020a0564022a0300b0046311e7cd5fmr57201972edb.274.1668033129798; Wed, 09 Nov 2022 14:32:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668033129; cv=none; d=google.com; s=arc-20160816; b=UrW/TT9+u44xZ/XOsLNOgkboMPF1nCM3+Ym36TCEnUekZf5NGihBa6GK9hiziGxlFX /NDhFtfZKzsuYwLs8ss5h6rSkdX1Eus5bQ3eL7W68JC2iQwMPMk88hhamrLE9hlGC+bF SeRSNVC5sGW0a78H41kcAXmY4BuhVYquQ9/ugTGIwxizrc69aFbqqDGFZZ1Ynl1H2oAp uN8flYjqH8EAptCr7GU/Lmu90I8K2GB8ZnueVASX4p3+yaxUKV5MkNj7VmHeUOh+ROIv zRwX3HgvU6v7jeMHXUhr4Sq5JOqCUnZZ3fOORl3sp8LXbvRcXAjZCtvVGIH+DUwn49e2 rK+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=XLY8KpeE8Egd3biw/bjn/d0MZKjfy02OzHvVagQIpyA=; b=LGQi6z++/2umD+r02DFfU8S+Eytop3U5WdakRNG5Tw6EqfjzSarC35btASeGoxj+Xf 2O4Yqen/nYZX6CVcJTJUp/WIqu9T5XW/8YJAJZkE0atJO7KNbvspKE4b4pf97/mp/CBJ 4UeP6fEisuyMcJzI5WXuqgL4gOUCesXLk4JFPBIJ6tDJI2G2o8BgVUonbIUwlSECdnA2 d4plfkXIDpmfibEMOjiwTTt8vugt/SY6ugds7qNVhHUw44vS1sTwQmTSXtFF5Is8OMlj n20HjC7Fo4H/X8SjkiwbIMgZGWZeekGchjRqIW4DUgfcufVWHCG3snaUm1uTOATBp2Sv cIfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=C7vSILYr; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ci4-20020a170906c34400b00781599eb7dbsi12390788ejb.573.2022.11.09.14.31.43; Wed, 09 Nov 2022 14:32:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=C7vSILYr; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232114AbiKIW3y (ORCPT + 99 others); Wed, 9 Nov 2022 17:29:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232191AbiKIW3x (ORCPT ); Wed, 9 Nov 2022 17:29:53 -0500 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 619C82EF61 for ; Wed, 9 Nov 2022 14:29:51 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id p18so145651qkg.2 for ; Wed, 09 Nov 2022 14:29:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=XLY8KpeE8Egd3biw/bjn/d0MZKjfy02OzHvVagQIpyA=; b=C7vSILYrF7CMoh6vv7kQmWkWsxTQkO4jBm3HdXPNg0xA3PqWWJNZkAURoRsNG0Ko2i UQ0btzHqDBS4u3b7aowwCFfgIh8YL6Bbx+IjiqkmOaMWkjByDucBvqSV/ayCh5yeVeOL FUzhUcz1U3ir4SV6yC2yVBYkAqWvm2wm7Q410ZEHbsHVwHf0f7Faq6FeWPvAveCWQidM dB3jFyYqyh/C98Oqtc3fu+hTfRGRXladlWctBMiVMvrOPQgPFnRwjNt6b5zbMb6imV72 NhsIyasFU6UdMrRjM93bvgt71BqByZ9ATnOs48eY4wWu9JNGyt4W0PeLbmdAFq00rRKC ihVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XLY8KpeE8Egd3biw/bjn/d0MZKjfy02OzHvVagQIpyA=; b=pm1X3VIDXl0rOjnvlFqFmFVvLRprK8qx370EjHDmPBx6kUlxU1GA6l8q7TY51U10b1 JAp/SWOntThsu57k2h2QAMUU/6VvHkE03AFmxqBcYxmMJhTqSC00+iWsU7yt6z/pnxAF SqBCz+ivpgLFq4m7RWH2l3w0ww0f/XYeUdcdDtRkyYWF92TbPnUBSz5d9T8BT+t6dNle nt6oCSuRDFj/Z/Rjg5oCliUMQAv7Ul+Wqh/clHjGUSS7NnSqBtO8iYWR95q2gKVit5CV EJIkUEYUCfFmAsdX36++yI25owzncuikmAAlcNG3aEnhNHIuopBRtQPS9pbSppRxbQCX sZ0Q== X-Gm-Message-State: ACrzQf06ZxRIwvWqXzloIjAv7rHWiVIEB06MNxDaOI5t/mkskXlItQkD NMuVwYW5mkkMYeMzZMXDzTfiKyGkByo= X-Received: by 2002:a37:e107:0:b0:6fa:4c1a:54ee with SMTP id c7-20020a37e107000000b006fa4c1a54eemr32760634qkm.728.1668032989919; Wed, 09 Nov 2022 14:29:49 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id z9-20020a05622a028900b0039bde72b14asm10518732qtw.92.2022.11.09.14.29.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 14:29:49 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/4] shared/util: Add iovec helpers Date: Wed, 9 Nov 2022 14:29:44 -0800 Message-Id: <20221109222947.1137901-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds iovec helpers functions. --- src/shared/util.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/util.h | 6 ++++++ 2 files changed, 59 insertions(+) diff --git a/src/shared/util.c b/src/shared/util.c index 0a0308cb0786..228044be459a 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -189,6 +189,59 @@ void util_clear_uid(uint64_t *bitmap, uint8_t id) *bitmap &= ~(((uint64_t)1) << (id - 1)); } +struct iovec *util_iov_dup(const struct iovec *iov, size_t cnt) +{ + struct iovec *dup; + size_t i; + + if (!iov) + return NULL; + + dup = new0(struct iovec, cnt); + + for (i = 0; i < cnt; i++) + util_iov_memcpy(&dup[i], iov[i].iov_base, iov[i].iov_len); + + return dup; +} + +int util_iov_memcmp(const struct iovec *iov1, const struct iovec *iov2) +{ + if (!iov1) + return 1; + + if (!iov2) + return -1; + + if (iov1->iov_len != iov2->iov_len) + return iov1->iov_len - iov2->iov_len; + + return memcmp(iov1->iov_base, iov2->iov_base, iov1->iov_len); +} + +void util_iov_memcpy(struct iovec *iov, void *src, size_t len) +{ + if (!iov) + return; + + iov->iov_base = realloc(iov->iov_base, len); + iov->iov_len = len; + memcpy(iov->iov_base, src, len); +} + +void util_iov_free(struct iovec *iov, size_t cnt) +{ + size_t i; + + if (!iov) + return; + + for (i = 0; i < cnt; i++) + free(iov[i].iov_base); + + free(iov); +} + static const struct { uint16_t uuid; const char *str; diff --git a/src/shared/util.h b/src/shared/util.h index 554481e1e1ea..765a4e956636 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -15,6 +15,7 @@ #include #include #include +#include #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) #define BIT(n) (1 << (n)) @@ -109,6 +110,11 @@ ssize_t util_getrandom(void *buf, size_t buflen, unsigned int flags); uint8_t util_get_uid(uint64_t *bitmap, uint8_t max); void util_clear_uid(uint64_t *bitmap, uint8_t id); +struct iovec *util_iov_dup(const struct iovec *iov, size_t cnt); +int util_iov_memcmp(const struct iovec *iov1, const struct iovec *iov2); +void util_iov_memcpy(struct iovec *iov, void *src, size_t len); +void util_iov_free(struct iovec *iov, size_t cnt); + const char *bt_uuid16_to_str(uint16_t uuid); const char *bt_uuid32_to_str(uint32_t uuid); const char *bt_uuid128_to_str(const uint8_t uuid[16]); -- 2.37.3