Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 169777
b: refs/heads/master
c: 727dad1
h: refs/heads/master
i:
  169775: c9dc392
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo authored and Ingo Molnar committed Nov 24, 2009
1 parent cad3fdd commit a523256
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 69 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: 364794845cbc49e638b83d7ef739524291e1e961
refs/heads/master: 727dad10c17cbaade3cb6a56bd4863a4630f4d13
11 changes: 2 additions & 9 deletions trunk/tools/perf/util/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,10 @@ static inline char *gitstrchrnul(const char *s, int c)
* Wrappers:
*/
extern char *xstrdup(const char *str);
extern void *xmalloc(size_t size);
extern void *xmalloc(size_t size) __attribute__((weak));
extern void *xmemdupz(const void *data, size_t len);
extern char *xstrndup(const char *str, size_t len);
extern void *xrealloc(void *ptr, size_t size);
extern void *xcalloc(size_t nmemb, size_t size);
extern void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
extern ssize_t xread(int fd, void *buf, size_t len);
extern ssize_t xwrite(int fd, const void *buf, size_t len);
extern int xdup(int fd);
extern FILE *xfdopen(int fd, const char *mode);
extern int xmkstemp(char *template);
extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));

static inline void *zalloc(size_t size)
{
Expand Down
61 changes: 2 additions & 59 deletions trunk/tools/perf/util/wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,43 +79,12 @@ void *xrealloc(void *ptr, size_t size)
return ret;
}

void *xcalloc(size_t nmemb, size_t size)
{
void *ret = calloc(nmemb, size);
if (!ret && (!nmemb || !size))
ret = calloc(1, 1);
if (!ret) {
release_pack_memory(nmemb * size, -1);
ret = calloc(nmemb, size);
if (!ret && (!nmemb || !size))
ret = calloc(1, 1);
if (!ret)
die("Out of memory, calloc failed");
}
return ret;
}

void *xmmap(void *start, size_t length,
int prot, int flags, int fd, off_t offset)
{
void *ret = mmap(start, length, prot, flags, fd, offset);
if (ret == MAP_FAILED) {
if (!length)
return NULL;
release_pack_memory(length, fd);
ret = mmap(start, length, prot, flags, fd, offset);
if (ret == MAP_FAILED)
die("Out of memory? mmap failed: %s", strerror(errno));
}
return ret;
}

/*
* xread() is the same a read(), but it automatically restarts read()
* operations with a recoverable error (EAGAIN and EINTR). xread()
* DOES NOT GUARANTEE that "len" bytes is read even if the data is available.
*/
ssize_t xread(int fd, void *buf, size_t len)
static ssize_t xread(int fd, void *buf, size_t len)
{
ssize_t nr;
while (1) {
Expand All @@ -131,7 +100,7 @@ ssize_t xread(int fd, void *buf, size_t len)
* operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT
* GUARANTEE that "len" bytes is written even if the operation is successful.
*/
ssize_t xwrite(int fd, const void *buf, size_t len)
static ssize_t xwrite(int fd, const void *buf, size_t len)
{
ssize_t nr;
while (1) {
Expand Down Expand Up @@ -179,29 +148,3 @@ ssize_t write_in_full(int fd, const void *buf, size_t count)

return total;
}

int xdup(int fd)
{
int ret = dup(fd);
if (ret < 0)
die("dup failed: %s", strerror(errno));
return ret;
}

FILE *xfdopen(int fd, const char *mode)
{
FILE *stream = fdopen(fd, mode);
if (stream == NULL)
die("Out of memory? fdopen failed: %s", strerror(errno));
return stream;
}

int xmkstemp(char *template)
{
int fd;

fd = mkstemp(template);
if (fd < 0)
die("Unable to create temporary file: %s", strerror(errno));
return fd;
}

0 comments on commit a523256

Please sign in to comment.