123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #ifndef XALLOC_H_
- # define XALLOC_H_
- # ifndef PARAMS
- # if defined PROTOTYPES || (defined __STDC__ && __STDC__)
- # define PARAMS(Args) Args
- # else
- # define PARAMS(Args) ()
- # endif
- # endif
- # ifndef __attribute__
- # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
- # define __attribute__(x)
- # endif
- # endif
- # ifndef ATTRIBUTE_NORETURN
- # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
- # endif
- extern int xalloc_exit_failure;
- extern void (*xalloc_fail_func) PARAMS ((void));
- extern char const xalloc_msg_memory_exhausted[];
- extern void xalloc_die PARAMS ((void)) ATTRIBUTE_NORETURN;
- void *xmalloc PARAMS ((size_t n));
- void *xcalloc PARAMS ((size_t n, size_t s));
- void *xrealloc PARAMS ((void *p, size_t n));
- char *xstrdup PARAMS ((const char *str));
- # define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items)))
- # define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items)))
- # define XREALLOC(Ptr, Type, N_items) \
- ((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items)))
- # define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1)
- # define XFREE(Var) \
- do { \
- if (Var) \
- free (Var); \
- } while (0)
- # define CCLONE(Src, Num) \
- (memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num)))
- # define CLONE(Src) CCLONE (Src, 1)
- #endif
|