From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) by dpdk.org (Postfix) with ESMTP id 9E58C7E3B for ; Fri, 26 Sep 2014 16:33:36 +0200 (CEST) Received: by mail-wi0-f169.google.com with SMTP id hi2so1146303wib.2 for ; Fri, 26 Sep 2014 07:39:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=AK3KdvtKJ2xuvd8pxByfTi1UYP6FJEbbBzGHCdRbYR0=; b=dzGrNjBc37GUuwP+mkwkXlzLdyZdQML3at5pIqMbSVovLbqwtlQ29y4TZuhtTKeIlB zsIeOJiFzivdFDr7i1/rwEBfiLWPpgdYMjCEBnULQZrLhFQVyybNMvVPR6DlzPOgHz9d NsjokVk1HAMrduOM2TG/Vbg0ByKJZGRvNDFTg9Ee9GeOr6jBimCl3fO2Kh/vJ2XF6E1C oXwQhijlVoDJn6/tXzePijioon+fMV6Je6M9B60ed0jC5PSEpHMLjlpq3MTlD2bD6fto 5kehND6ga9rTx1HaV5t4Tolld3zlgPw/3bVYLyqgY1DQIe1ZdZhWOhl66LYdP726ejJX x4gg== X-Gm-Message-State: ALoCoQkL7dzvM34z04U9j/Fst6rmdZQ15KMJd7y0Jj9cLSAr2Nkjk/lWzBq7vMdc41pJy4RZvWq5 X-Received: by 10.180.38.114 with SMTP id f18mr27299194wik.24.1411742399156; Fri, 26 Sep 2014 07:39:59 -0700 (PDT) Received: from localhost.localdomain (136-92-190-109.dsl.ovh.fr. [109.190.92.136]) by mx.google.com with ESMTPSA id iy10sm2449126wic.5.2014.09.26.07.39.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 26 Sep 2014 07:39:58 -0700 (PDT) From: Thomas Monjalon To: dev@dpdk.org Date: Fri, 26 Sep 2014 16:39:44 +0200 Message-Id: <1411742384-29216-1-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.0.4 Subject: [dpdk-dev] [PATCH] eal: remove rte_snprintf X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Sep 2014 14:33:36 -0000 The function rte_snprintf() was deprecated in version 1.7.0 (commit 6f41fe75e2dd). It's now totally removed. Signed-off-by: Thomas Monjalon --- app/test/Makefile | 7 -- app/test/test_string_fns.c | 136 +------------------------ lib/librte_eal/common/eal_common_string_fns.c | 28 ----- lib/librte_eal/common/include/rte_string_fns.h | 24 ----- lib/librte_eal/common/include/rte_warnings.h | 4 - 5 files changed, 1 insertion(+), 198 deletions(-) diff --git a/app/test/Makefile b/app/test/Makefile index 210a7f6..822bbd4 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -133,13 +133,6 @@ SRCS-$(CONFIG_RTE_LIBRTE_KVARGS) += test_kvargs.c CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) -# Allow use of deprecated rte_snprintf in test_string_fns.c -ifeq ($(CC), icc) -CFLAGS_test_string_fns.o += -Wd1478 -else -CFLAGS_test_string_fns.o += -Wno-deprecated-declarations -endif - # Disable warnings of deprecated-declarations in test_kni.c ifeq ($(CC), icc) CFLAGS_test_kni.o += -wd1478 diff --git a/app/test/test_string_fns.c b/app/test/test_string_fns.c index 29bfe5b..39e6a9d 100644 --- a/app/test/test_string_fns.c +++ b/app/test/test_string_fns.c @@ -49,139 +49,6 @@ #define DATA_BYTE 'a' static int -test_rte_snprintf(void) -{ - /* ================================================= - * First test with a string that will fit in buffer - * =================================================*/ - do { - int retval; - const char source[] = "This is a string that will fit in buffer"; - char buf[sizeof(source)+2]; /* make buffer big enough to fit string */ - - /* initialise buffer with characters so it can contain no nulls */ - memset(buf, DATA_BYTE, sizeof(buf)); - - /* run rte_snprintf and check results */ - retval = rte_snprintf(buf, sizeof(buf), "%s", source); - if (retval != sizeof(source) - 1) { - LOG("Error, retval = %d, expected = %u\n", - retval, (unsigned)sizeof(source)); - return -1; - } - if (buf[retval] != '\0') { - LOG("Error, resultant is not null-terminated\n"); - return -1; - } - if (memcmp(source, buf, sizeof(source)-1) != 0){ - LOG("Error, corrupt data in buffer\n"); - return -1; - } - } while (0); - - do { - /* ================================================= - * Test with a string that will get truncated - * =================================================*/ - int retval; - const char source[] = "This is a long string that won't fit in buffer"; - char buf[sizeof(source)/2]; /* make buffer half the size */ - - /* initialise buffer with characters so it can contain no nulls */ - memset(buf, DATA_BYTE, sizeof(buf)); - - /* run rte_snprintf and check results */ - retval = rte_snprintf(buf, sizeof(buf), "%s", source); - if (retval != sizeof(source) - 1) { - LOG("Error, retval = %d, expected = %u\n", - retval, (unsigned)sizeof(source)); - return -1; - } - if (buf[sizeof(buf)-1] != '\0') { - LOG("Error, buffer is not null-terminated\n"); - return -1; - } - if (memcmp(source, buf, sizeof(buf)-1) != 0){ - LOG("Error, corrupt data in buffer\n"); - return -1; - } - } while (0); - - do { - /* =========================================================== - * Test using zero-size buf to check how long a buffer we need - * ===========================================================*/ - int retval; - const char source[] = "This is a string"; - char buf[10]; - - /* call with a zero-sized non-NULL buffer, should tell how big a buffer - * we need */ - retval = rte_snprintf(buf, 0, "%s", source); - if (retval != sizeof(source) - 1) { - LOG("Call with 0-length buffer does not return correct size." - "Expected: %zu, got: %d\n", sizeof(source), retval); - return -1; - } - - /* call with a zero-sized NULL buffer, should tell how big a buffer - * we need */ - retval = rte_snprintf(NULL, 0, "%s", source); - if (retval != sizeof(source) - 1) { - LOG("Call with 0-length buffer does not return correct size." - "Expected: %zu, got: %d\n", sizeof(source), retval); - return -1; - } - - } while (0); - - do { - /* ================================================= - * Test with invalid parameter values - * =================================================*/ - const char source[] = "This is a string"; - char buf[10]; - - /* call with buffer value set to NULL is EINVAL */ - if (rte_snprintf(NULL, sizeof(buf), "%s\n", source) != -1 || - errno != EINVAL) { - LOG("Failed to get suitable error when passing NULL buffer\n"); - return -1; - } - - memset(buf, DATA_BYTE, sizeof(buf)); - /* call with a NULL format and zero-size should return error - * without affecting the buffer */ - if (rte_snprintf(buf, 0, NULL) != -1 || - errno != EINVAL) { - LOG("Failed to get suitable error when passing NULL buffer\n"); - return -1; - } - if (buf[0] != DATA_BYTE) { - LOG("Error, zero-length buffer modified after call with NULL" - " format string\n"); - return -1; - } - - /* call with a NULL format should return error but also null-terminate - * the buffer */ - if (rte_snprintf(buf, sizeof(buf), NULL) != -1 || - errno != EINVAL) { - LOG("Failed to get suitable error when passing NULL buffer\n"); - return -1; - } - if (buf[0] != '\0') { - LOG("Error, buffer not null-terminated after call with NULL" - " format string\n"); - return -1; - } - } while (0); - - LOG("%s - PASSED\n", __func__); - return 0; -} - -static int test_rte_strsplit(void) { int i; @@ -294,8 +161,7 @@ test_rte_strsplit(void) static int test_string_fns(void) { - if (test_rte_snprintf() < 0 || - test_rte_strsplit() < 0) + if (test_rte_strsplit() < 0) return -1; return 0; } diff --git a/lib/librte_eal/common/eal_common_string_fns.c b/lib/librte_eal/common/eal_common_string_fns.c index fb0bbe8..125a3e2 100644 --- a/lib/librte_eal/common/eal_common_string_fns.c +++ b/lib/librte_eal/common/eal_common_string_fns.c @@ -38,34 +38,6 @@ #include -/* safe version os snprintf */ -int -rte_snprintf(char *buffer, int buflen, const char *format, ...) -{ - int len; - va_list ap; - - if (buffer == NULL && buflen != 0) - goto einval_error; - if (format == NULL) { - if (buflen > 0) - buffer[0] = '\0'; - goto einval_error; - } - - va_start(ap, format); - len = vsnprintf(buffer, buflen, format, ap); - va_end(ap); - if (len >= buflen && buflen > 0) - buffer[buflen - 1] = '\0'; - - return len; - -einval_error: - errno = EINVAL; - return -1; -} - /* split string into tokens */ int rte_strsplit(char *string, int stringlen, diff --git a/lib/librte_eal/common/include/rte_string_fns.h b/lib/librte_eal/common/include/rte_string_fns.h index cf96b2c..cfca2f8 100644 --- a/lib/librte_eal/common/include/rte_string_fns.h +++ b/lib/librte_eal/common/include/rte_string_fns.h @@ -45,30 +45,6 @@ extern "C" { #endif /** - * This functio is deprecated and just for backward compatibility. - * It is just an alternate version of snprintf. - * - * @param buffer - * The buffer into which the output is to be written - * - * @param buflen - * The size of the output buffer - * - * @param format - * The format string to be printed to the buffer - * - * @return - * The number of characters written to the buffer, or if the string has been - * truncated, the number of characters which would have been written had the - * buffer been sufficiently big. - * - */ -int -rte_snprintf(char *buffer, int buflen, const char *format, ...) - __attribute__((format(printf,3,4))) - __attribute__((deprecated)); - -/** * Takes string "string" parameter and splits it at character "delim" * up to maxtokens-1 times - to give "maxtokens" resulting tokens. Like * strtok or strsep functions, this modifies its input string, by replacing diff --git a/lib/librte_eal/common/include/rte_warnings.h b/lib/librte_eal/common/include/rte_warnings.h index 423e6fb..da80877 100644 --- a/lib/librte_eal/common/include/rte_warnings.h +++ b/lib/librte_eal/common/include/rte_warnings.h @@ -54,10 +54,6 @@ #include #endif -/* rte_snprintf uses snprintf, so include its definition before we poison the - * functions, otherwise we'll get an error in it. */ -#include - /* the following function are deemed not fully secure for use e.g. they * do not always null-terminate arguments */ #pragma GCC poison sprintf strtok snprintf vsnprintf -- 2.0.4