diff options
author | Masami Hiramatsu <mhiramat@redhat.com> | 2010-03-16 18:05:21 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-03-17 06:32:29 -0400 |
commit | a1d37d5285bcda07f9c0b80a2634ca20ab545297 (patch) | |
tree | 5b6e5c861db7077d6fc954b3d37825751afd5a22 /tools/perf/util/util.h | |
parent | e4713e93b125497e9ba44d93de1bd9d8e5ad8946 (diff) |
perf tools: Introduce xzalloc() for detecting out of memory conditions
Introducing xzalloc() which wrapping zalloc() for detecting out
of memory conditions.
Signed-off-by: Masami Hiramatsu <mhiramat@redhat.com>
Cc: systemtap <systemtap@sources.redhat.com>
Cc: DLE <dle-develop@lists.sourceforge.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <20100316220521.32050.85155.stgit@localhost6.localdomain6>
[ -v2: small cleanups in surrounding code ]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/util.h')
-rw-r--r-- | tools/perf/util/util.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 0f5b2a6f1080..52701087ce04 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h | |||
@@ -295,6 +295,13 @@ extern void *xmemdupz(const void *data, size_t len); | |||
295 | extern char *xstrndup(const char *str, size_t len); | 295 | extern char *xstrndup(const char *str, size_t len); |
296 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); | 296 | extern void *xrealloc(void *ptr, size_t size) __attribute__((weak)); |
297 | 297 | ||
298 | static inline void *xzalloc(size_t size) | ||
299 | { | ||
300 | void *buf = xmalloc(size); | ||
301 | |||
302 | return memset(buf, 0, size); | ||
303 | } | ||
304 | |||
298 | static inline void *zalloc(size_t size) | 305 | static inline void *zalloc(size_t size) |
299 | { | 306 | { |
300 | return calloc(1, size); | 307 | return calloc(1, size); |
@@ -309,6 +316,7 @@ static inline int has_extension(const char *filename, const char *ext) | |||
309 | { | 316 | { |
310 | size_t len = strlen(filename); | 317 | size_t len = strlen(filename); |
311 | size_t extlen = strlen(ext); | 318 | size_t extlen = strlen(ext); |
319 | |||
312 | return len > extlen && !memcmp(filename + len - extlen, ext, extlen); | 320 | return len > extlen && !memcmp(filename + len - extlen, ext, extlen); |
313 | } | 321 | } |
314 | 322 | ||
@@ -322,6 +330,7 @@ static inline int has_extension(const char *filename, const char *ext) | |||
322 | #undef isalnum | 330 | #undef isalnum |
323 | #undef tolower | 331 | #undef tolower |
324 | #undef toupper | 332 | #undef toupper |
333 | |||
325 | extern unsigned char sane_ctype[256]; | 334 | extern unsigned char sane_ctype[256]; |
326 | #define GIT_SPACE 0x01 | 335 | #define GIT_SPACE 0x01 |
327 | #define GIT_DIGIT 0x02 | 336 | #define GIT_DIGIT 0x02 |