The strlcpy() feature check slows every build unnecessarily - so make it
a __weak function so it does not have to be auto-detected.
If the libc (or any other library) has an strlcpy() implementation it will
be used - otherwise our fallback is active.
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/n/tip-zjbrcupapu08ePsyYhhhxiwk@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
libperl \
libpython \
libpython-version \
- strlcpy \
libbfd \
on-exit \
backtrace \
endif
endif
-ifndef NO_STRLCPY
- ifeq ($(feature-strlcpy), 1)
- CFLAGS += -DHAVE_STRLCPY_SUPPORT
- endif
-endif
-
ifndef NO_ON_EXIT
ifeq ($(feature-on-exit), 1)
CFLAGS += -DHAVE_ON_EXIT_SUPPORT
test-libperl \
test-libpython \
test-libpython-version \
- test-strlcpy \
test-libbfd \
test-on-exit \
test-backtrace \
test-libpython-version:
$(BUILD) $(FLAGS_PYTHON_EMBED)
-test-strlcpy:
- $(BUILD)
-
test-libbfd:
$(BUILD) -DPACKAGE='perf' -DPACKAGE=perf -lbfd -ldl
+++ /dev/null
-#include <stdlib.h>
-extern size_t strlcpy(char *dest, const char *src, size_t size);
-
-int main(void)
-{
- strlcpy(NULL, NULL, 0);
- return 0;
-}
extern char *perf_pathdup(const char *fmt, ...)
__attribute__((format (printf, 1, 2)));
-#ifndef HAVE_STRLCPY_SUPPORT
+/* Matches the libc/libbsd function attribute so we declare this unconditionally: */
extern size_t strlcpy(char *dest, const char *src, size_t size);
-#endif
#endif /* __PERF_CACHE_H */
# define __force
#endif
+#ifndef __weak
+# define __weak __attribute__((weak))
+#endif
+
#endif
return ".";
}
-#ifndef HAVE_STRLCPY_SUPPORT
-size_t strlcpy(char *dest, const char *src, size_t size)
+/*
+ * If libc has strlcpy() then that version will override this
+ * implementation:
+ */
+size_t __weak strlcpy(char *dest, const char *src, size_t size)
{
size_t ret = strlen(src);
if (size) {
size_t len = (ret >= size) ? size - 1 : ret;
+
memcpy(dest, src, len);
dest[len] = '\0';
}
+
return ret;
}
-#endif
static char *get_pathname(void)
{