home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / util_src / memap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-29  |  1.3 KB  |  77 lines

  1. #include <osbind.h>
  2. void Bconws(char *s)
  3. {
  4.     while (*s) Bconout(2, *s++);
  5. }
  6. #define LONG long
  7. #define WORD short
  8. /*
  9.  * Prinl - print a long integer (32 bits)
  10.  *
  11.  */
  12. void printl(val)
  13. register LONG val;
  14. {
  15.         register WORD j;
  16.         register WORD div_idx;
  17.         register WORD first;
  18.         static LONG divisors[] = { 1000000000,100000000,10000000,1000000,
  19.                    100000,10000, 1000, 100, 10, 1 };
  20. #define MAX_IDX 10
  21.     
  22.         if (val == 0)
  23.     {
  24.         Bconout(2, '0');
  25.                 return;
  26.     }
  27.         else if (val == -2147483648)
  28.     {
  29.                 Bconws( "-2147483648");
  30.         return;
  31.     }
  32.     
  33.         if (val < 0L)
  34.     {
  35.         Bconout(2, '-');
  36.                 val = -val;
  37.     }
  38.     
  39.     first = 0;
  40.         for(div_idx = 0; div_idx < MAX_IDX; div_idx++)
  41.     {
  42.                 if(((j = (WORD)(val / divisors[div_idx])) != 0) || first != 0)
  43.         {
  44.                         Bconout(2, j + '0');
  45.                         first = 1;
  46.         }
  47.                 val %= divisors[div_idx];
  48.     }
  49.     
  50. }
  51.  
  52. main()
  53. {
  54.     long size;
  55.     long *buf, *first, *last = 0;
  56.  
  57.     while ((size = Malloc(-1L)) >= 8)
  58.     {
  59.         buf = Malloc(size);
  60.         printl(size);
  61.             Bconws("\tbytes free at ");
  62.         printl(buf);
  63.         Bconws("\r\n");
  64.         if (last) *last = buf;
  65.         else first = buf;
  66.         last = buf;
  67.         *buf = 0;
  68.     }
  69.     /* free all those buffers */
  70.     buf = first;
  71.     while (buf) {
  72.         last = *buf;
  73.         Mfree(buf);
  74.         buf = last;
  75.     }
  76. }
  77.