op_libiberty.c revision 48ae5fc270ea3bbb965b4bd07cb1691a5c115642
1/** 2 * @file op_libiberty.c 3 * Wrapper for libiberty - always use this instead of 4 * libiberty.h 5 * 6 * @remark Copyright 2002 OProfile authors 7 * @remark Read the file COPYING 8 * 9 * @author John Levon 10 * @author Philippe Elie 11 */ 12 13#include <string.h> 14#include <stdlib.h> 15 16#include "op_libiberty.h" 17 18#ifndef HAVE_XCALLOC 19/* some system have a valid libiberty without xcalloc */ 20void * xcalloc(size_t n_elem, size_t sz) 21{ 22 void * ptr = xmalloc(n_elem * sz); 23 24 memset(ptr, '\0', n_elem * sz); 25 26 return ptr; 27} 28#endif 29 30#ifndef HAVE_XMEMDUP 31void * xmemdup (void const * input, size_t copy_size, size_t alloc_size) 32{ 33 void * output = xcalloc(1, alloc_size); 34 35 memcpy(output, input, copy_size); 36 37 return output; 38} 39#endif 40 41#ifndef HAVE_LIBIBERTY_H 42 43void xmalloc_set_program_name(char const * a) 44{ 45} 46 47void * xmalloc(size_t s) 48{ 49 return malloc(s); 50} 51 52void * xrealloc(void *p, size_t s) 53{ 54 return realloc(p, s); 55} 56 57/* Copy a string into a memory buffer without fail. */ 58char * xstrdup(char const * str) 59{ 60 return strdup(str); 61} 62 63#endif 64