/usr.bin/xlint/common/mem.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 88 lines · 43 code · 14 blank · 31 comment · 9 complexity · ee3ed7bbfb6799db3cecd63b9f5c20df MD5 · raw file

  1. /* $NetBSD: mem.c,v 1.2 2002/01/21 19:49:51 tv Exp $ */
  2. /*
  3. * Copyright (c) 1994, 1995 Jochen Pohl
  4. * All Rights Reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. All advertising materials mentioning features or use of this software
  15. * must display the following acknowledgement:
  16. * This product includes software developed by Jochen Pohl for
  17. * The NetBSD Project.
  18. * 4. The name of the author may not be used to endorse or promote products
  19. * derived from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  22. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  23. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  30. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include <sys/cdefs.h>
  33. #if defined(__RCSID) && !defined(lint)
  34. __RCSID("$NetBSD: mem.c,v 1.2 2002/01/21 19:49:51 tv Exp $");
  35. #endif
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include "lint.h"
  39. void *
  40. xmalloc(size_t s)
  41. {
  42. void *p;
  43. if ((p = malloc(s)) == NULL)
  44. nomem();
  45. return (p);
  46. }
  47. void *
  48. xcalloc(size_t n, size_t s)
  49. {
  50. void *p;
  51. if ((p = calloc(n, s)) == NULL)
  52. nomem();
  53. return (p);
  54. }
  55. void *
  56. xrealloc(void *p, size_t s)
  57. {
  58. if ((p = realloc(p, s)) == NULL)
  59. nomem();
  60. return (p);
  61. }
  62. char *
  63. xstrdup(const char *s)
  64. {
  65. char *s2;
  66. if ((s2 = strdup(s)) == NULL)
  67. nomem();
  68. return (s2);
  69. }
  70. void
  71. nomem(void)
  72. {
  73. errx(1, "virtual memory exhausted");
  74. }