Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1207201rwb; Wed, 9 Nov 2022 14:31:42 -0800 (PST) X-Google-Smtp-Source: AMsMyM5t/iSTdRQ7CT0P7V38KtcG22qk70X1G1/Lxun8yn5CoKBctal1Do8Nqfb5Sr+Kgf4Qczu1 X-Received: by 2002:a17:906:2c11:b0:79e:3312:9a0f with SMTP id e17-20020a1709062c1100b0079e33129a0fmr1760727ejh.576.1668033102183; Wed, 09 Nov 2022 14:31:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668033102; cv=none; d=google.com; s=arc-20160816; b=aDDZ8d3XRXg7kFjnoA/MnRS7xXwWHIGnhx8mwwahUfpUAFmxnH9tSpytaH9ehSZTiB B7w+1dy4XDyifcr2TmuxxzwIHDNC/vEHyhxpv1anzEz69zBdVI1lqU5btLZvbwcT/A7X h2G1luByglihTWTCha0Fkk6lo+4Fi6p8HMJegLIK7P8RACYoz320R27+ijevyChpBciQ RL24UuyjvRzv8rdiKoI7Qh3EyC7GYR445Tt7gMS/reEVF2cy+pQKJbjckvb8HAzrjoPr 0SlJE0MIRblAVi/kKmJW+7x/jk86vmiIa7WN/u/0urcRGfk/w51EgjWhHQO70awefLDf ybVw== 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=TTIvBh6D8EWr0IiNAhVJGZYFUF8uxyPcA/1bxXvB+nIhTaF3Vx+s2onpLRMyQLW5of 0YwFvZpI7I5FhsYHfuU5d6sGOZxoERN7c0KCja0w3d0qm1IO1N8WIqbPvEFFMfHgvMNK mC7+Qb+9GGbXgJPR+ASzsuYwKX6M/ybIn6+xxCUnST4kVLpMMuo3RcYU6q/6iEkgvxVI y41QJ7q249X0ITsbv+WAmKdq5H+XPe63q8GGcVddFfW0GvXixnDMPcixjxUvPI+caYBJ pz5hopVbkPwV+JrDACDs7UZsWesNiSZO8z9HCrLPibvaaWk9e3RZe2A9n394u9qgHEOx Ppxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Gzz6P4OZ; 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 w8-20020a056402268800b0045bdff8a884si20345482edd.268.2022.11.09.14.31.06; Wed, 09 Nov 2022 14:31:42 -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=Gzz6P4OZ; 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 S232187AbiKIW3n (ORCPT + 99 others); Wed, 9 Nov 2022 17:29:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232217AbiKIW3i (ORCPT ); Wed, 9 Nov 2022 17:29:38 -0500 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A9C82EF77 for ; Wed, 9 Nov 2022 14:29:34 -0800 (PST) Received: by mail-qt1-x82f.google.com with SMTP id fz10so56491qtb.3 for ; Wed, 09 Nov 2022 14:29:34 -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=Gzz6P4OZ55yVkH+wMdZvOlSQ0AeYLvPt4DjmcRcgFGST732eWvAKvF5kbPzGxzfdHH DuwZE4YxcklTpwS46LN4qPFV9zoNOqUtOxXeJy5M9eWFdJDRPNlT48XvcMeVu/yJgPgM A1xE86PORFjgpUv3T7gyvRIeoNwnanGH5Vcti3UDrKqLsk93hfx1nBcD6TceBgDitF+g kq7SsYspQjzlC5Yzn8Yp5msB9HBoyjAWT2C/MWUTRSEvlDiU/5Py7edas3iqCgZtxQVA WCeE4lK3XGBmH8cpLYPifxcPnUq4GZp+uMiHTuxY+6p5Dc42r6fFseY5YDaIw1KrAmJ8 fvYQ== 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=d/5XFtAKX/t042Naai7t1cev1aVJkg1kYNTe7kWyXosxg5F4HG09U9PtZ46cBAP46P I1onr64j7AfcHrU2Q9BYxia+9A6JUzI+7JcYZH/KAOILggo4cj+QHPetvkLKC0uAEp5m YN/bZX7Ug2Z81jbvUMz1VkLXmHF0qYdKe3LyTEpUBUTTtn4rgoZXRoy4f/PxQJBWYk8h U38WCgGuo4Inw4eavZd40oWTJ8TcFxtrzcqarGMYRacuXMScIh365nMBeEM5wivWN054 raaKp8HDxae1hOqK62yIVecQ5N6CIUXfkAGad6DfXtPw4wDHYI3thUHT9UhPC1fvPnE5 ImAQ== X-Gm-Message-State: ANoB5pm6XMhN6MQ149l+Xr8z2HD+97EhUHER+TymTBhKW0gqizGijZ0F lvAv5wkkL5mDE4Z1zSGIdIFw2okBL/s= X-Received: by 2002:a05:622a:144b:b0:3a5:abe2:51c8 with SMTP id v11-20020a05622a144b00b003a5abe251c8mr6856783qtx.433.1668032972865; Wed, 09 Nov 2022 14:29:32 -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 q21-20020a37f715000000b006ed61f18651sm11499501qkj.16.2022.11.09.14.29.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Nov 2022 14:29:32 -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:26 -0800 Message-Id: <20221109222930.1137690-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