00001 /** 00002 * @file op_libiberty.h 00003 * Wrapper for libiberty - always use this instead of 00004 * libiberty.h 00005 * 00006 * @remark Copyright 2002 OProfile authors 00007 * @remark Read the file COPYING 00008 * 00009 * @author John Levon 00010 * @author Philippe Elie 00011 */ 00012 00013 #ifndef OP_LIBIBERTY_H 00014 #define OP_LIBIBERTY_H 00015 00016 #include <stddef.h> 00017 00018 #include "config.h" 00019 00020 #ifdef MALLOC_ATTRIBUTE_OK 00021 #define OP_ATTRIB_MALLOC __attribute__((malloc)) 00022 #else 00023 #define OP_ATTRIB_MALLOC 00024 #endif 00025 00026 #ifdef HAVE_LIBIBERTY_H 00027 #include <libiberty.h> 00028 #else 00029 00030 #ifdef __cplusplus 00031 extern "C" { 00032 #endif 00033 00034 /* some system have a libiberty.a but no libiberty.h so we must provide 00035 * ourself the missing proto */ 00036 #ifndef HAVE_LIBIBERTY_H 00037 /* Set the program name used by xmalloc. */ 00038 void xmalloc_set_program_name(char const *); 00039 00040 /* Allocate memory without fail. If malloc fails, this will print a 00041 message to stderr (using the name set by xmalloc_set_program_name, 00042 if any) and then call xexit. */ 00043 void * xmalloc(size_t) OP_ATTRIB_MALLOC; 00044 00045 /* Reallocate memory without fail. This works like xmalloc. Note, 00046 realloc type functions are not suitable for attribute malloc since 00047 they may return the same address across multiple calls. */ 00048 void * xrealloc(void *, size_t); 00049 00050 /* Allocate memory without fail and set it to zero. This works like xmalloc */ 00051 void * xcalloc(size_t, size_t) OP_ATTRIB_MALLOC; 00052 00053 /* Copy a string into a memory buffer without fail. */ 00054 char * xstrdup(char const *) OP_ATTRIB_MALLOC; 00055 00056 /** 00057 * Duplicates a region of memory without fail. First, alloc_size bytes 00058 * are allocated, then copy_size bytes from input are copied into 00059 * it, and the new memory is returned. If fewer bytes are copied than were 00060 * allocated, the remaining memory is zeroed. 00061 */ 00062 void * xmemdup(void const *, size_t, size_t) OP_ATTRIB_MALLOC; 00063 00064 #endif /* !HAVE_LIBIBERTY_H */ 00065 00066 #ifdef __cplusplus 00067 } 00068 #endif 00069 00070 #endif /* !HAVE_LIBIBERTY_H */ 00071 00072 #endif /* OP_LIBIBERTY_H */
1.6.1