Skip to content

Commit d1fd7bc

Browse files
committed
maybe hide strl funcs
1 parent 7e8c38c commit d1fd7bc

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

tests/host/Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ GENHTML ?= genhtml
3030
CXXFLAGS += -std=gnu++17
3131
CFLAGS += -std=gnu17
3232

33+
# 32-bit mode is prefered, but not required
3334
ifeq ($(FORCE32),1)
3435
SIZEOFLONG = $(shell echo 'int main(){return sizeof(long);}'|$(CXX) -m32 -x c++ - -o sizeoflong 2>/dev/null && ./sizeoflong; echo $$?; rm -f sizeoflong;)
3536
ifneq ($(SIZEOFLONG),4)
@@ -50,6 +51,29 @@ endif
5051
OUTPUT_BINARY := $(BINDIR)/host_tests
5152
LCOV_DIRECTORY := $(BINDIR)/../lcov
5253

54+
# Core files sometimes override libc functions, check when necessary to hide them
55+
# TODO proper configure script / other build system?
56+
ifeq (,$(wildcard ./.have_strlcpy))
57+
$(shell echo -e '#include <cstring>\nint main(){char a[4]; char b[4]; strlcpy(&a[0], &b[0], sizeof(a)); return 0;}' | \
58+
$(CXX) -x c++ - -o .have_strlcpy 2>/dev/null || { echo -e '#!/bin/sh\nexit 1' > .have_strlcpy ; chmod +x .have_strlcpy; })
59+
endif
60+
61+
$(shell ./.have_strlcpy)
62+
ifeq ($(.SHELLSTATUS), 0)
63+
FLAGS += -DHAVE_STRLCPY
64+
endif
65+
66+
ifeq (,$(wildcard ./.have_strlcat))
67+
$(shell echo -e '#include <cstring>\nint main(){char a[4]; strlcat(&a[0], "test", sizeof(a)); return 0;}' | \
68+
$(CXX) -x c++ - -o .have_strlcat 2>/dev/null || { echo -e '#!/bin/sh\nexit 1' > .have_strlcat ; chmod +x .have_strlcat; })
69+
endif
70+
71+
$(shell ./.have_strlcat)
72+
ifeq ($(.SHELLSTATUS), 0)
73+
FLAGS += -DHAVE_STRLCAT
74+
endif
75+
76+
# Hide full build commands by default
5377
ifeq ($(V), 0)
5478
VERBC = @echo "C $@";
5579
VERBCXX = @echo "C++ $@";

tests/host/common/mock.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@
6565
extern "C"
6666
{
6767
#endif
68-
char* utoa(unsigned value, char* result, int base);
69-
char* itoa(int value, char* result, int base);
68+
char* utoa(unsigned value, char* result, int base);
69+
char* itoa(int value, char* result, int base);
70+
#ifndef HAVE_STRLCAT
7071
size_t strlcat(char* dst, const char* src, size_t size);
72+
#endif
73+
#ifndef HAVE_STRLCPY
7174
size_t strlcpy(char* dst, const char* src, size_t size);
75+
#endif
7276
#ifdef __cplusplus
7377
}
7478
#endif

0 commit comments

Comments
 (0)