Skip to content

Commit

Permalink
perf tools: add test for strlcpy()
Browse files Browse the repository at this point in the history
Some Linux distributions like ALT Linux provides patched glibc with
contains strlcpy(). It's confilcts with strlcpy() from perf.

Let's add check for strlcpy().

Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@elte.hu>
LKML-Reference: <1282351101-8879-1-git-send-email-kirill@shutemov.name>
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Kirill A. Shutemov authored and Arnaldo Carvalho de Melo committed Aug 21, 2010
1 parent 8b9e74e commit f4e7ac0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,15 @@ else
endif
endif


ifdef NO_STRLCPY
BASIC_CFLAGS += -DNO_STRLCPY
else
ifneq ($(call try-cc,$(SOURCE_STRLCPY),),y)
BASIC_CFLAGS += -DNO_STRLCPY
endif
endif

ifndef CC_LD_DYNPATH
ifdef NO_R_TO_GCC_LINKER
# Some gcc does not accept and pass -R to the linker to specify
Expand Down
11 changes: 11 additions & 0 deletions tools/perf/feature-tests.mak
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ int main(void)
}
endef

define SOURCE_STRLCPY
#include <stdlib.h>
extern size_t strlcpy(char *dest, const char *src, size_t size);

int main(void)
{
strlcpy(NULL, NULL, 0);
return 0;
}
endef

# try-cc
# Usage: option = $(call try-cc, source-to-build, cc-options)
try-cc = $(shell sh -c \
Expand Down
2 changes: 2 additions & 0 deletions tools/perf/util/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ extern char *perf_path(const char *fmt, ...) __attribute__((format (printf, 1, 2
extern char *perf_pathdup(const char *fmt, ...)
__attribute__((format (printf, 1, 2)));

#ifdef NO_STRLCPY
extern size_t strlcpy(char *dest, const char *src, size_t size);
#endif

#endif /* __PERF_CACHE_H */
3 changes: 2 additions & 1 deletion tools/perf/util/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static const char *get_perf_dir(void)
return ".";
}

#ifdef NO_STRLCPY
size_t strlcpy(char *dest, const char *src, size_t size)
{
size_t ret = strlen(src);
Expand All @@ -33,7 +34,7 @@ size_t strlcpy(char *dest, const char *src, size_t size)
}
return ret;
}

#endif

static char *get_pathname(void)
{
Expand Down

0 comments on commit f4e7ac0

Please sign in to comment.