From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2FD4743D8B; Sat, 30 Mar 2024 04:05:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3DEEB40A6B; Sat, 30 Mar 2024 04:04:50 +0100 (CET) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) by mails.dpdk.org (Postfix) with ESMTP id 712C3402EC for ; Sat, 30 Mar 2024 04:04:44 +0100 (CET) Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5d81b08d6f2so1835711a12.0 for ; Fri, 29 Mar 2024 20:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711767883; x=1712372683; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YwHfWcdLNfli8f+JFimP9JJamA7SW0tTDfnLjdRpUKc=; b=bxw4jAAaqsxGku4lpq45STN5dgeO8yP8V9jfx/LvUZas6ulotOzX8adyCoc+kcdLqb itYfgxgUwuoJDOsPjHr0CMVMRJHRAJW5/HYdljyHpHh/AUme/E8p/50vmNakIDXBgTFm RY3PDlretEV/dmwF2+3vkq6YxqsRSyE3s7eMruZimTxRZwlvzZ6tU+hHRrf1Y3HHz9oT 8kyu2SpPteWiEj7Dmq8/QmvHH94mLbkk5rHdwePRYoYd16GYAkgxsL8UhG89S0SJt6o+ tEUUfscZutYuj6EHPa5BhgpR9TGFMem2sH6oX8NQGpu8yIyykFuUjE6mYA/IQIioj8so gGKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711767883; x=1712372683; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YwHfWcdLNfli8f+JFimP9JJamA7SW0tTDfnLjdRpUKc=; b=UxZGgaHlFJnrazj5rydLra4nuIYFXWVQSJnIpOf3SLIikWcJzB4SEOl3c+JmqR3Qhv OZvPnD3Ptj8XjGJs/np+OGmGVY1Vc/BphPe2Ref7CbzmZawJ6i3MpFIghMb4KZc9YiMY /SAQg0XsOEKJhpb437PMbXvuFfJYV64BrnDKh2vhEnAutFCZm6cWgfv44XmSZLewSLBL 2XJkpY6EUxQrKgZ8a2cIjLPSnE1+DTaCN5wRRQYoKir2aOxNpDu/GO3s70dczXrTwsZS X7NTiaFvueeM+5JSgQdL3R+t54Xx1uB6Z4nadhabx+5AlwaygzmkLpLr3MsXvpiMW28w GDtg== X-Gm-Message-State: AOJu0Yx4gvh15SpTY/NU0/Dwg2uRW1E9ZVhps9pUb0mwgaB3QsHvIsz7 7rUbYrC6d8ET1j5iMrOtZiBVDR8sTxRYZ0fFXTFsgkLpOCJZNXfTXk3NKCKksccSe6y6B3OHPjm U X-Google-Smtp-Source: AGHT+IE28d8uac5RJFvvGmRYq0jwFucpohQ8dfz9fxkNIe7Kg94Ds8tWEmLCnfxsBTRHK/TRO79Esw== X-Received: by 2002:a05:6a20:4323:b0:1a3:c8a9:6deb with SMTP id h35-20020a056a20432300b001a3c8a96debmr4427287pzk.48.1711767883598; Fri, 29 Mar 2024 20:04:43 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id o3-20020a056a00214300b006e6288ef4besm3655486pfk.54.2024.03.29.20.04.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 20:04:43 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Chenbo Xia , Nipun Gupta , Dmitry Kozlyuk , Pallavi Kadam , Bruce Richardson , David Marchand , Nick Connolly , Ranjit Menon , Khoa To Subject: [PATCH v19 04/15] windows: common wrapper for vasprintf and asprintf Date: Fri, 29 Mar 2024 20:00:47 -0700 Message-ID: <20240330030429.4630-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240330030429.4630-1-stephen@networkplumber.org> References: <20200814173441.23086-1-stephen@networkplumber.org> <20240330030429.4630-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Replace the windows version of asprintf() that was only usable in eal. With a more generic one that supports both vasprintf() and asprintf(). This also eliminates duplicate code. Fixes: 8f4de2dba9b9 ("bus/pci: fill bus specific information") Fixes: 9ec521006db0 ("eal/windows: hide asprintf shim") Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- drivers/bus/pci/pci_common.c | 32 ------------------ lib/eal/common/eal_private.h | 10 ------ lib/eal/windows/eal.c | 28 ---------------- lib/eal/windows/include/rte_os_shim.h | 48 +++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 70 deletions(-) diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 889a48d2af..80691c75a3 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -45,38 +45,6 @@ const char *rte_pci_get_sysfs_path(void) return path; } -#ifdef RTE_EXEC_ENV_WINDOWS -#define asprintf pci_asprintf - -static int -__rte_format_printf(2, 3) -pci_asprintf(char **buffer, const char *format, ...) -{ - int size, ret; - va_list arg; - - va_start(arg, format); - size = vsnprintf(NULL, 0, format, arg); - va_end(arg); - if (size < 0) - return -1; - size++; - - *buffer = malloc(size); - if (*buffer == NULL) - return -1; - - va_start(arg, format); - ret = vsnprintf(*buffer, size, format, arg); - va_end(arg); - if (ret != size - 1) { - free(*buffer); - return -1; - } - return ret; -} -#endif /* RTE_EXEC_ENV_WINDOWS */ - static struct rte_devargs * pci_devargs_lookup(const struct rte_pci_addr *pci_addr) { diff --git a/lib/eal/common/eal_private.h b/lib/eal/common/eal_private.h index 71523cfdb8..da8d77a134 100644 --- a/lib/eal/common/eal_private.h +++ b/lib/eal/common/eal_private.h @@ -737,16 +737,6 @@ void __rte_thread_init(unsigned int lcore_id, rte_cpuset_t *cpuset); */ void __rte_thread_uninit(void); -/** - * asprintf(3) replacement for Windows. - */ -#ifdef RTE_EXEC_ENV_WINDOWS -__rte_format_printf(2, 3) -int eal_asprintf(char **buffer, const char *format, ...); - -#define asprintf(buffer, format, ...) \ - eal_asprintf(buffer, format, ##__VA_ARGS__) -#endif #define EAL_LOG(level, ...) \ RTE_LOG_LINE(level, EAL, "" __VA_ARGS__) diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c index 52f0e7462d..8ca00c0f95 100644 --- a/lib/eal/windows/eal.c +++ b/lib/eal/windows/eal.c @@ -503,34 +503,6 @@ rte_eal_init(int argc, char **argv) return fctret; } -/* Don't use MinGW asprintf() to have identical code with all toolchains. */ -int -eal_asprintf(char **buffer, const char *format, ...) -{ - int size, ret; - va_list arg; - - va_start(arg, format); - size = vsnprintf(NULL, 0, format, arg); - va_end(arg); - if (size < 0) - return -1; - size++; - - *buffer = malloc(size); - if (*buffer == NULL) - return -1; - - va_start(arg, format); - ret = vsnprintf(*buffer, size, format, arg); - va_end(arg); - if (ret != size - 1) { - free(*buffer); - return -1; - } - return ret; -} - int rte_vfio_container_dma_map(__rte_unused int container_fd, __rte_unused uint64_t vaddr, diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h index e9741a9df2..65153fdb38 100644 --- a/lib/eal/windows/include/rte_os_shim.h +++ b/lib/eal/windows/include/rte_os_shim.h @@ -3,6 +3,7 @@ #ifndef _RTE_OS_SHIM_ #define _RTE_OS_SHIM_ +#include #include #include @@ -120,4 +121,51 @@ rte_localtime_r(const time_t *timer, struct tm *buf) } #define localtime_r(timer, buf) rte_localtime_r(timer, buf) +/* print to allocated string */ +__rte_format_printf(2, 0) +static inline int +rte_vasprintf(char **strp, const char *fmt, va_list ap) +{ + char *str; + int len, ret; + + *strp = NULL; + + /* determine size of buffer needed */ + len = _vscprintf(fmt, ap); + if (len < 0) + return -1; + + len += 1; /* for nul termination */ + str = malloc(len); + if (str == NULL) + return -1; + + ret = vsnprintf(str, len, fmt, ap); + if (ret < 0) { + free(str); + return -1; + } else { + *strp = str; + return ret; + } +} +#define vasprintf(strp, fmt, ap) rte_vasprintf(strp, fmt, ap) + +__rte_format_printf(2, 3) +static inline int +rte_asprintf(char **strp, const char *fmt, ...) +{ + int ret; + + va_list ap; + + va_start(ap, fmt); + ret = rte_vasprintf(strp, fmt, ap); + va_end(ap); + + return ret; +} + +#define asprintf(strp, fmt, ...) rte_asprintf(strp, fmt, __VA_ARGS__) #endif /* _RTE_OS_SHIM_ */ -- 2.43.0