home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / MMCTRL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  2.5 KB  |  84 lines

  1. /**
  2. *
  3. * Name        mmctrl -- Retrieve a DOS memory control block
  4. *
  5. * Synopsis    ercode = mmctrl(memblk,pctrlblk,pnextblk);
  6. *
  7. *        int ercode      0  if memblk is a legitimate DOS
  8. *                     memory block, but not the last;
  9. *                  9 if memblk is not a legitimate
  10. *                     DOS memory block;
  11. *                  18 if memblk is the last memory block.
  12. *        unsigned memblk   Segment address of DOS memory block
  13. *                  as allocated by DOS function 0x48.
  14. *        MEMCTRL *pctrlblk Address of structure in which to
  15. *                  return copy of memory control block
  16. *                  associated with memblk.
  17. *        unsigned *pnextblk
  18. *                  Segment of next memory block,
  19. *                  or 0 if memblk is invalid or if
  20. *                  there is no next block.
  21. *
  22. * Description    MMCTRL fetches a copy of the control block associated
  23. *        with a DOS memory block and returns the segment address
  24. *        of the next memory block.
  25. *
  26. *        The control block is a 16-byte data structure located
  27. *        exactly 16 bytes (one paragraph) before the memory block
  28. *        (i.e., at segment (memblk-1), offset 0).  Its leading
  29. *        byte should be 'M' or 'Z'; a 'Z' indicates the final
  30. *        block in the chain.
  31. *
  32. *        MMCTRL fails if memblk is not a currently-allocated DOS
  33. *        memory block.  In that case 9 is returned as the value
  34. *        of the function.
  35. *
  36. * Returns    ercode          0  if memblk is a legitimate DOS
  37. *                     memory block, but not the last;
  38. *                  9 if memblk is not a legitimate
  39. *                     DOS memory block;
  40. *                  18 if memblk is the last memory block.
  41. *        *pctrlblk      Copy of memory control block
  42. *                  associated with memblk.
  43. *        *pnextblk      Segment of next memory block,
  44. *                  or 0 if memblk is invalid or if
  45. *                  there is no next block.
  46. *
  47. * Version    6.00 (C)Copyright Blaise Computing Inc. 1987, 1989
  48. *
  49. **/
  50.  
  51. #include <bmem.h>
  52. #include <butil.h>
  53.  
  54. int mmctrl(memblk,pctrlblk,pnextblk)
  55. unsigned memblk;
  56. MEMCTRL  *pctrlblk;
  57. unsigned *pnextblk;
  58. {
  59.     register int result;
  60.  
  61.     utpeekn(uttofaru(memblk-1,0),          /* Fetch 16 bytes.  */
  62.         (char far *) &pctrlblk->ident,
  63.         16);
  64.  
  65.     switch (pctrlblk->ident)
  66.     {
  67.     case 'M':                     /* Valid memory block, not the  */
  68.         result    = 0;          /*   last.              */
  69.         *pnextblk = memblk + pctrlblk->size + 1;
  70.         break;
  71.  
  72.     case 'Z':                     /* Last memory block in the     */
  73.         result    = 18;          /* chain.               */
  74.         *pnextblk = 0;
  75.         break;
  76.  
  77.     default:              /* Invalid memory block.          */
  78.         result    = 9;
  79.         *pnextblk = 0;
  80.         break;
  81.     }
  82.     return result;
  83. }
  84.