home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume20 / memlintok / t_memlintok.c < prev   
Encoding:
C/C++ Source or Header  |  1989-10-26  |  1.4 KB  |  72 lines

  1. /* $Header: t_memlintok.c,v 1.3 89/05/02 15:07:08 bobl Exp $ */
  2.  
  3. #include <stdio.h>
  4.  
  5. #include "memlintok.h"
  6.  
  7. main()
  8. {
  9.     int *p, *q;
  10.  
  11.     if (MALLOC_LINTOK(p, 100, int) == NULL)
  12.         fail("can't malloc 100 ints\n");
  13.     else
  14.         succeed("100 ints malloc'd\n");
  15.  
  16.     (void) REALLOC_LINTOK(p, 200, int);
  17.     if (p == NULL)
  18.         fail("can't realloc 200 ints\n");
  19.     else
  20.         succeed("200 ints realloc'd\n");
  21.  
  22.     if (MR_ALLOC_LINTOK(p, 25, int) == NULL)
  23.         fail("can't mr_alloc (realloc) 25 ints\n");
  24.     else
  25.         succeed("25 ints mr_alloc'd (realloc'd)\n");
  26.  
  27.     if (CALLOC_LINTOK(q, 500, int) == NULL)
  28.         fail("can't calloc 500 ints\n");
  29.     else
  30.         succeed("500 ints calloc'd\n");
  31.     q[0] = 0;
  32.     FREE_LINTOK(q);
  33.  
  34.     FREE_LINTOK(p);
  35.     p = NULL;
  36.     if (MR_ALLOC_LINTOK(p, 1000, int) == NULL)
  37.         fail("can't mr_alloc (malloc) 1000 ints\n");
  38.     else
  39.         succeed("1000 ints mr_alloc'd (malloc'd)\n");
  40.  
  41.     CALLOC_OR_ELSE_LINTOK(p, 50, int);
  42.     succeed("50 ints calloc'd (or else)\n");
  43.     MALLOC_OR_ELSE_LINTOK(p, 100, int);
  44.     succeed("100 ints malloc'd (or else)\n");
  45.     REALLOC_OR_ELSE_LINTOK(p, 200, int);
  46.     succeed("200 ints realloc'd (or else)\n");
  47.  
  48. #undef ERROR_EXIT_LINTOK
  49. #define ERROR_EXIT_LINTOK(nelem, size) \
  50.     fail("memory allocation failed\n");
  51.  
  52.     MR_ALLOC_OR_ELSE_LINTOK(p, 400, int);
  53.     succeed("400 ints mr_alloc'd (realloc'd) (or else)\n");
  54.  
  55.     exit(0);
  56.     return 0;    /* shuts up HP-UX lint */
  57. }
  58.  
  59. fail(s)
  60.     char *s;
  61. {
  62.     fputs(s, stdout);
  63.     exit(1);
  64. }
  65.  
  66. succeed(s)
  67.     char *s;
  68. {
  69.     fputs(s, stdout);
  70.     return;
  71. }
  72.