Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 199102
b: refs/heads/master
c: 151f85a
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo committed May 19, 2010
1 parent 9416ec1 commit 583b721
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 52 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8a7ddad8e756a72906851fdd5a6e149cbb056e0d
refs/heads/master: 151f85a471d29fc81f70348143d009a729901bc0
4 changes: 2 additions & 2 deletions trunk/tools/perf/util/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ const char *perf_extract_argv0_path(const char *argv0)
slash--;

if (slash >= argv0) {
argv0_path = xstrndup(argv0, slash - argv0);
return slash + 1;
argv0_path = strndup(argv0, slash - argv0);
return argv0_path ? slash + 1 : NULL;
}

return argv0;
Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/util/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@ char *strip_path_suffix(const char *path, const char *suffix)

if (path_len && !is_dir_sep(path[path_len - 1]))
return NULL;
return xstrndup(path, chomp_trailing_dir_sep(path, path_len));
return strndup(path, chomp_trailing_dir_sep(path, path_len));
}
8 changes: 0 additions & 8 deletions trunk/tools/perf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,8 @@ static inline char *gitstrchrnul(const char *s, int c)
* Wrappers:
*/
extern char *xstrdup(const char *str);
extern void *xmalloc(size_t size) __attribute__((weak));
extern char *xstrndup(const char *str, size_t len);
extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));

static inline void *xzalloc(size_t size)
{
void *buf = xmalloc(size);

return memset(buf, 0, size);
}

static inline void *zalloc(size_t size)
{
Expand Down
40 changes: 0 additions & 40 deletions trunk/tools/perf/util/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,46 +23,6 @@ char *xstrdup(const char *str)
return ret;
}

void *xmalloc(size_t size)
{
void *ret = malloc(size);
if (!ret && !size)
ret = malloc(1);
if (!ret) {
release_pack_memory(size, -1);
ret = malloc(size);
if (!ret && !size)
ret = malloc(1);
if (!ret)
die("Out of memory, malloc failed");
}
#ifdef XMALLOC_POISON
memset(ret, 0xA5, size);
#endif
return ret;
}

/*
* xmemdupz() allocates (len + 1) bytes of memory, duplicates "len" bytes of
* "data" to the allocated memory, zero terminates the allocated memory,
* and returns a pointer to the allocated memory. If the allocation fails,
* the program dies.
*/
static void *xmemdupz(const void *data, size_t len)
{
char *p = xmalloc(len + 1);
memcpy(p, data, len);
p[len] = '\0';
return p;
}

char *xstrndup(const char *str, size_t len)
{
char *p = memchr(str, '\0', len);

return xmemdupz(str, p ? (size_t)(p - str) : len);
}

void *xrealloc(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);
Expand Down

0 comments on commit 583b721

Please sign in to comment.