home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name mmctrl -- Retrieve a DOS memory control block
- *
- * Synopsis ercode = mmctrl(memblk,pctrlblk,pnextblk);
- *
- * int ercode 0 if memblk is a legitimate DOS
- * memory block, but not the last;
- * 9 if memblk is not a legitimate
- * DOS memory block;
- * 18 if memblk is the last memory block.
- * unsigned memblk Segment address of DOS memory block
- * as allocated by DOS function 0x48.
- * MEMCTRL *pctrlblk Address of structure in which to
- * return copy of memory control block
- * associated with memblk.
- * unsigned *pnextblk
- * Segment of next memory block,
- * or 0 if memblk is invalid or if
- * there is no next block.
- *
- * Description MMCTRL fetches a copy of the control block associated
- * with a DOS memory block and returns the segment address
- * of the next memory block.
- *
- * The control block is a 16-byte data structure located
- * exactly 16 bytes (one paragraph) before the memory block
- * (i.e., at segment (memblk-1), offset 0). Its leading
- * byte should be 'M' or 'Z'; a 'Z' indicates the final
- * block in the chain.
- *
- * MMCTRL fails if memblk is not a currently-allocated DOS
- * memory block. In that case 9 is returned as the value
- * of the function.
- *
- * Returns ercode 0 if memblk is a legitimate DOS
- * memory block, but not the last;
- * 9 if memblk is not a legitimate
- * DOS memory block;
- * 18 if memblk is the last memory block.
- * *pctrlblk Copy of memory control block
- * associated with memblk.
- * *pnextblk Segment of next memory block,
- * or 0 if memblk is invalid or if
- * there is no next block.
- *
- * Version 6.00 (C)Copyright Blaise Computing Inc. 1987, 1989
- *
- **/
-
- #include <bmem.h>
- #include <butil.h>
-
- int mmctrl(memblk,pctrlblk,pnextblk)
- unsigned memblk;
- MEMCTRL *pctrlblk;
- unsigned *pnextblk;
- {
- register int result;
-
- utpeekn(uttofaru(memblk-1,0), /* Fetch 16 bytes. */
- (char far *) &pctrlblk->ident,
- 16);
-
- switch (pctrlblk->ident)
- {
- case 'M': /* Valid memory block, not the */
- result = 0; /* last. */
- *pnextblk = memblk + pctrlblk->size + 1;
- break;
-
- case 'Z': /* Last memory block in the */
- result = 18; /* chain. */
- *pnextblk = 0;
- break;
-
- default: /* Invalid memory block. */
- result = 9;
- *pnextblk = 0;
- break;
- }
- return result;
- }