home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / xmalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-19  |  1.4 KB  |  124 lines

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conf.h>
  5. #include "sysdeps.h"
  6. #include "xmalloc.h"
  7.  
  8. #if defined __GLIBC__ || defined MALLOC_HOOKS
  9. void
  10. xminit(void)
  11. {
  12. }
  13.  
  14. void
  15. xminfo(void)
  16. {
  17.     malloc_stats();
  18. }
  19.  
  20. void
  21. xmterm(void)
  22. {
  23. }
  24. #else
  25. void
  26. xminit(void)
  27. {
  28. }
  29.  
  30. void
  31. xminfo(void)
  32. {
  33. }
  34. void
  35. xmterm(void)
  36. {
  37. }
  38. #endif
  39.  
  40. #define _L     LOG_INTERNAL | LOG_INFO
  41.  
  42. void *
  43. xmalloc(size_t sz)
  44. {
  45.     void       *ret;
  46.  
  47.     ret = malloc(sz);
  48.     if (!ret)
  49.     {
  50.         fprintf(stderr, "xmalloc:  failed in allocation of %d bytes\n", sz);
  51.         exit(23);
  52.     }
  53.     return ret;
  54. }
  55.  
  56. void *
  57. xcalloc(size_t sz)
  58. {
  59.     void       *ret;
  60.  
  61.     ret = calloc(sz, 1);
  62.     if (!ret)
  63.     {
  64.         fprintf(stderr, "xcalloc:  failed in allocation of %d bytes\n\n", sz);
  65.         exit(23);
  66.     }
  67.     return ret;
  68. }
  69.  
  70. void *
  71. xrealloc(void *ptr, size_t sz)
  72. {
  73.     void       *ret = realloc(ptr, sz);
  74.  
  75.     if (!ret)
  76.     {
  77.         fprintf(stderr, "xrealloc:  failed in reallocation to %d bytes\n\n",
  78.              sz);
  79.         exit(23);
  80.     }
  81.     return ret;
  82. }
  83.  
  84. void
  85. xfree(void *ptr)
  86. {
  87.     if (ptr)
  88.         free(ptr);
  89. }
  90.  
  91. char *
  92. xstrdup(const char *str)
  93. {
  94.     char       *ret;
  95.      
  96.     if (str)
  97.     {
  98.         ret = (char *) strdup(str);
  99.         if (!ret)
  100.         {
  101.             fprintf(stderr, "xstrdup:  failed to copy string\n\n");
  102.             exit(23);
  103.         }
  104.         return ret;
  105.     }
  106.     else
  107.         return 0L;
  108. }
  109.  
  110. char *
  111. xintdup(int x)
  112. {
  113.     char       *ret = (char *) xmalloc(sizeof(int));
  114.  
  115.     if (!ret)
  116.     {
  117.         fprintf(stderr, "xintdup:  failed to copy int\n\n");
  118.         exit(23);
  119.     }
  120.     memcpy(ret, &x, sizeof(int));
  121.  
  122.     return ret;
  123. }
  124.