You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xmalloc.h 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* This file is part of Netsukuku system
  2. * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
  3. *
  4. * This source code is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as published
  6. * by the Free Software Foundation; either version 2 of the License,
  7. * or (at your option) any later version.
  8. *
  9. * This source code is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. * Please refer to the GNU Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Public License along with
  15. * this source code; if not, write to:
  16. * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef XMALLOC_H
  19. #define XMALLOC_H
  20. #ifdef USE_DMALLOC
  21. #include "dmalloc.h"
  22. #else
  23. /* xmalloc.h: Shamelessly ripped from openssh:
  24. * Author: Tatu Ylonen <ylo@cs.hut.fi>
  25. * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
  26. * All rights reserved
  27. * Created: Mon Mar 20 22:09:17 1995 ylo
  28. *
  29. * Versions of malloc and friends that check their results, and never return
  30. * failure (they call fatal if they encounter an error).
  31. *
  32. * --
  33. *
  34. * xfree() macro wrapper added. AlpT
  35. */
  36. /*
  37. * xfree
  38. *
  39. * It calls _xfree(__pptr) and then sets `__pptr' to 0.
  40. * It is safe, you can use it also with expressions:
  41. * xfree(a++);
  42. */
  43. #define xfree(__pptr) \
  44. do{ \
  45. char **_p=(char **)&(__pptr); \
  46. _xfree(*_p); \
  47. *_p=0; \
  48. }while(0)
  49. /* Functions declaration */
  50. void *xmalloc(size_t);
  51. void *xzalloc(size_t size);
  52. void *xrealloc(void *, size_t);
  53. void *xcalloc(size_t nmemb, size_t size);
  54. void _xfree(void *);
  55. char *xstrndup(const char *str, size_t n);
  56. char *xstrdup(const char *);
  57. #endif
  58. #endif /*XMALLOC_H */