aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-05-18 17:54:30 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-05-18 22:05:28 -0400
commit151f85a471d29fc81f70348143d009a729901bc0 (patch)
tree5860102465e3fa3cf660884d91a82d86dbfc4835 /tools/perf
parent8a7ddad8e756a72906851fdd5a6e149cbb056e0d (diff)
perf tools: remove xstrndup, xmalloc, xzalloc
All the functions that call this can handle the equivalent, non panic'ing wrapped routines. Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/exec_cmd.c4
-rw-r--r--tools/perf/util/path.c2
-rw-r--r--tools/perf/util/util.h8
-rw-r--r--tools/perf/util/wrapper.c40
4 files changed, 3 insertions, 51 deletions
diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
index c1b3d34e5716..67eeff571568 100644
--- a/tools/perf/util/exec_cmd.c
+++ b/tools/perf/util/exec_cmd.c
@@ -53,8 +53,8 @@ const char *perf_extract_argv0_path(const char *argv0)
53 slash--; 53 slash--;
54 54
55 if (slash >= argv0) { 55 if (slash >= argv0) {
56 argv0_path = xstrndup(argv0, slash - argv0); 56 argv0_path = strndup(argv0, slash - argv0);
57 return slash + 1; 57 return argv0_path ? slash + 1 : NULL;
58 } 58 }
59 59
60 return argv0; 60 return argv0;
diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c
index b276c187802a..58a470d036dd 100644
--- a/tools/perf/util/path.c
+++ b/tools/perf/util/path.c
@@ -152,5 +152,5 @@ char *strip_path_suffix(const char *path, const char *suffix)
152 152
153 if (path_len && !is_dir_sep(path[path_len - 1])) 153 if (path_len && !is_dir_sep(path[path_len - 1]))
154 return NULL; 154 return NULL;
155 return xstrndup(path, chomp_trailing_dir_sep(path, path_len)); 155 return strndup(path, chomp_trailing_dir_sep(path, path_len));
156} 156}
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 52118a0c0bad..45b9655f3a5c 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -179,16 +179,8 @@ static inline char *gitstrchrnul(const char *s, int c)
179 * Wrappers: 179 * Wrappers:
180 */ 180 */
181extern char *xstrdup(const char *str); 181extern char *xstrdup(const char *str);
182extern void *xmalloc(size_t size) __attribute__((weak));
183extern char *xstrndup(const char *str, size_t len);
184extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); 182extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
185 183
186static inline void *xzalloc(size_t size)
187{
188 void *buf = xmalloc(size);
189
190 return memset(buf, 0, size);
191}
192 184
193static inline void *zalloc(size_t size) 185static inline void *zalloc(size_t size)
194{ 186{
diff --git a/tools/perf/util/wrapper.c b/tools/perf/util/wrapper.c
index c4ced7c1251d..73e900edb5a2 100644
--- a/tools/perf/util/wrapper.c
+++ b/tools/perf/util/wrapper.c
@@ -23,46 +23,6 @@ char *xstrdup(const char *str)
23 return ret; 23 return ret;
24} 24}
25 25
26void *xmalloc(size_t size)
27{
28 void *ret = malloc(size);
29 if (!ret && !size)
30 ret = malloc(1);
31 if (!ret) {
32 release_pack_memory(size, -1);
33 ret = malloc(size);
34 if (!ret && !size)
35 ret = malloc(1);
36 if (!ret)
37 die("Out of memory, malloc failed");
38 }
39#ifdef XMALLOC_POISON
40 memset(ret, 0xA5, size);
41#endif
42 return ret;
43}
44
45/*
46 * xmemdupz() allocates (len + 1) bytes of memory, duplicates "len" bytes of
47 * "data" to the allocated memory, zero terminates the allocated memory,
48 * and returns a pointer to the allocated memory. If the allocation fails,
49 * the program dies.
50 */
51static void *xmemdupz(const void *data, size_t len)
52{
53 char *p = xmalloc(len + 1);
54 memcpy(p, data, len);
55 p[len] = '\0';
56 return p;
57}
58
59char *xstrndup(const char *str, size_t len)
60{
61 char *p = memchr(str, '\0', len);
62
63 return xmemdupz(str, p ? (size_t)(p - str) : len);
64}
65
66void *xrealloc(void *ptr, size_t size) 26void *xrealloc(void *ptr, size_t size)
67{ 27{
68 void *ret = realloc(ptr, size); 28 void *ret = realloc(ptr, size);