mirror of
https://github.com/espressif/openthread.git
synced 2026-08-02 00:57:47 +00:00
[utils] remove strlcat (#4483)
This commit is contained in:
@@ -228,7 +228,6 @@ LOCAL_SRC_FILES := \
|
||||
src/core/utils/heap.cpp \
|
||||
src/core/utils/jam_detector.cpp \
|
||||
src/core/utils/missing_strlcpy.c \
|
||||
src/core/utils/missing_strlcat.c \
|
||||
src/core/utils/missing_strnlen.c \
|
||||
src/core/utils/parse_cmdline.cpp \
|
||||
src/core/utils/slaac_address.cpp \
|
||||
|
||||
@@ -159,7 +159,6 @@ static_library("lib-ot-core") {
|
||||
"src/core/utils/child_supervision.cpp",
|
||||
"src/core/utils/heap.cpp",
|
||||
"src/core/utils/jam_detector.cpp",
|
||||
"src/core/utils/missing_strlcat.c",
|
||||
"src/core/utils/missing_strlcpy.c",
|
||||
"src/core/utils/missing_strnlen.c",
|
||||
"src/core/utils/parse_cmdline.cpp",
|
||||
|
||||
@@ -173,7 +173,6 @@ then
|
||||
# Here we guess conservative values for tests that require link checks
|
||||
# to test for these features. This will prevent these checks from
|
||||
# being performed later in the configuration process.
|
||||
ac_cv_func_strlcat=${ac_cv_func_strlcat-no}
|
||||
ac_cv_func_strlcpy=${ac_cv_func_strlcpy-no}
|
||||
ac_cv_func_strnlen=${ac_cv_func_strnlen-no}
|
||||
else
|
||||
@@ -952,7 +951,6 @@ AC_CHECK_HEADERS([string.h])
|
||||
# Missing Functions
|
||||
#
|
||||
AC_CHECK_FUNC([strlcpy], [AC_DEFINE([HAVE_STRLCPY], [1], [Define if strlcpy exists.])])
|
||||
AC_CHECK_FUNC([strlcat], [AC_DEFINE([HAVE_STRLCAT], [1], [Define if strlcat exists.])])
|
||||
AC_CHECK_FUNC([strnlen], [AC_DEFINE([HAVE_STRNLEN], [1], [Define if strnlen exists.])])
|
||||
|
||||
#
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
include(CheckFunctionExists)
|
||||
|
||||
check_function_exists("strlcat" HAVE_STRLCAT)
|
||||
check_function_exists("strlcpy" HAVE_STRLCPY)
|
||||
check_function_exists("strnlen" HAVE_STRNLEN)
|
||||
|
||||
|
||||
@@ -26,9 +26,6 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Define if strlcat exists. */
|
||||
#cmakedefine01 HAVE_STRLCAT
|
||||
|
||||
/* Define if strlcpy exists. */
|
||||
#cmakedefine01 HAVE_STRLCPY
|
||||
|
||||
|
||||
@@ -178,7 +178,6 @@ set(COMMON_SOURCES
|
||||
utils/child_supervision.cpp
|
||||
utils/heap.cpp
|
||||
utils/jam_detector.cpp
|
||||
utils/missing_strlcat.c
|
||||
utils/missing_strlcpy.c
|
||||
utils/missing_strnlen.c
|
||||
utils/parse_cmdline.cpp
|
||||
|
||||
@@ -235,7 +235,6 @@ SOURCES_COMMON = \
|
||||
utils/child_supervision.cpp \
|
||||
utils/heap.cpp \
|
||||
utils/jam_detector.cpp \
|
||||
utils/missing_strlcat.c \
|
||||
utils/missing_strlcpy.c \
|
||||
utils/missing_strnlen.c \
|
||||
utils/parse_cmdline.cpp \
|
||||
@@ -269,7 +268,6 @@ libopenthread_radio_a_SOURCES = \
|
||||
radio/radio_callbacks.cpp \
|
||||
radio/radio_platform.cpp \
|
||||
thread/link_quality.cpp \
|
||||
utils/missing_strlcat.c \
|
||||
utils/missing_strlcpy.c \
|
||||
utils/missing_strnlen.c \
|
||||
utils/parse_cmdline.cpp \
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "utils/wrap_string.h"
|
||||
|
||||
size_t missing_strlcat(char *dst, const char *src, size_t dstsize)
|
||||
{
|
||||
size_t len = strlen(dst);
|
||||
|
||||
if (len < dstsize - 1)
|
||||
{
|
||||
return (len + strlcpy(dst + len, src, dstsize - len));
|
||||
}
|
||||
|
||||
return len + strlen(src);
|
||||
}
|
||||
@@ -51,8 +51,6 @@
|
||||
|
||||
/* See: https://www.freebsd.org/cgi/man.cgi?query=strlcpy */
|
||||
WRAP_EXTERN_C size_t missing_strlcpy(char *dst, const char *src, size_t dstsize);
|
||||
/* See: https://www.freebsd.org/cgi/man.cgi?query=strlcat */
|
||||
WRAP_EXTERN_C size_t missing_strlcat(char *dst, const char *src, size_t dstsize);
|
||||
/* See: https://www.freebsd.org/cgi/man.cgi?query=strnlen */
|
||||
WRAP_EXTERN_C size_t missing_strnlen(const char *s, size_t maxlen);
|
||||
|
||||
@@ -66,10 +64,6 @@ WRAP_EXTERN_C size_t missing_strnlen(const char *s, size_t maxlen);
|
||||
#define HAVE_STRLCPY 0
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
#define HAVE_STRLCAT 0
|
||||
#endif
|
||||
|
||||
#if (!HAVE_STRNLEN)
|
||||
#define strnlen(S, N) missing_strnlen(S, N)
|
||||
#endif
|
||||
@@ -78,8 +72,4 @@ WRAP_EXTERN_C size_t missing_strnlen(const char *s, size_t maxlen);
|
||||
#define strlcpy(D, S, N) missing_strlcpy(D, S, N)
|
||||
#endif
|
||||
|
||||
#if (!HAVE_STRLCAT)
|
||||
#define strlcat(D, S, N) missing_strlcat(D, S, N)
|
||||
#endif
|
||||
|
||||
#endif // WRAP_STRING_H
|
||||
|
||||
@@ -122,7 +122,6 @@ check_PROGRAMS += \
|
||||
test-priority-queue \
|
||||
test-pskc \
|
||||
test-string \
|
||||
test-strlcat \
|
||||
test-strlcpy \
|
||||
test-strnlen \
|
||||
test-timer \
|
||||
@@ -223,9 +222,6 @@ test_pskc_SOURCES = $(COMMON_SOURCES) test_pskc.cpp
|
||||
test_string_LDADD = $(COMMON_LDADD)
|
||||
test_string_SOURCES = $(COMMON_SOURCES) test_string.cpp
|
||||
|
||||
test_strlcat_LDADD = $(COMMON_LDADD)
|
||||
test_strlcat_SOURCES = test_strlcat.c
|
||||
|
||||
test_strlcpy_LDADD = $(COMMON_LDADD)
|
||||
test_strlcpy_SOURCES = test_strlcpy.c
|
||||
|
||||
@@ -267,7 +263,6 @@ PRETTY_FILES = \
|
||||
$(test_spinel_decoder_SOURCES) \
|
||||
$(test_spinel_encoder_SOURCES) \
|
||||
$(test_string_SOURCES) \
|
||||
$(test_strlcat_SOURCES) \
|
||||
$(test_strlcpy_SOURCES) \
|
||||
$(test_strnlen_SOURCES) \
|
||||
$(test_timer_SOURCES) \
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <openthread/config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "utils/wrap_string.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char string_a[8] = "foo";
|
||||
char string_b[8] = "barbar";
|
||||
size_t ret = 0;
|
||||
int errors = 0;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
|
||||
ret = missing_strlcat(string_a, string_b, sizeof(string_a));
|
||||
|
||||
if (0 != strcmp(string_a, "foobarb"))
|
||||
{
|
||||
printf("strcmp failed\n");
|
||||
errors++;
|
||||
}
|
||||
|
||||
if (ret != 9)
|
||||
{
|
||||
printf("strlcat return value is wrong (%d)\n", (int)ret);
|
||||
errors++;
|
||||
}
|
||||
|
||||
if (errors != 0)
|
||||
{
|
||||
printf("FAIL\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("OK\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user