From: Thomas Monjalon Date: Fri, 26 Sep 2014 14:13:37 +0000 (+0200) Subject: eal: remove rte_snprintf X-Git-Tag: spdx-start~10379 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=3185322809c1ae1b46192c5eb1447b11527720c3;p=dpdk.git eal: remove rte_snprintf The function rte_snprintf() was deprecated in version 1.7.0 (commit 6f41fe75e2dd). It's now totally removed. Signed-off-by: Thomas Monjalon Acked-by: Neil Horman --- diff --git a/app/test/Makefile b/app/test/Makefile index 37a3772a18..6af6d76f60 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -137,13 +137,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 29bfe5b8e0..39e6a9dac3 100644 --- a/app/test/test_string_fns.c +++ b/app/test/test_string_fns.c @@ -48,139 +48,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) { @@ -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 fb0bbe8628..125a3e2d9b 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 cf96b2c7dc..cfca2f8df3 100644 --- a/lib/librte_eal/common/include/rte_string_fns.h +++ b/lib/librte_eal/common/include/rte_string_fns.h @@ -44,30 +44,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 diff --git a/lib/librte_eal/common/include/rte_warnings.h b/lib/librte_eal/common/include/rte_warnings.h index 423e6fb2a9..da80877f37 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