home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / CLIBSRC1.ZIP / DOSALLOC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.6 KB  |  55 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - dosalloc.c
  3.  *
  4.  * function(s)
  5.  *        _dos_allocmem - allocates DOS memory segment (MSC compatible)
  6.  *--------------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1991, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <dos.h>
  18. #include <_io.h>
  19.  
  20. /*--------------------------------------------------------------------------*
  21.  
  22. Name            _dos_allocmem - allocates DOS memory segment
  23.  
  24. Usage           int allocmem(unsigned size, unsigned *seg);
  25.  
  26. Prototype in    dos.h
  27.  
  28. Description     uses the MS-DOS system call 0x48 to allocate a block of free
  29.                 memory and returns the segment address of the allocated block.
  30.  
  31. Return value    returns 0 on success.  In the event of an error,
  32.                 the size of the largest available block) is stored at *seg,
  33.                 errno is set to ENOMEM, and the DOS error code is returned.
  34.  
  35. Note            Compatible with Microsoft C.  Not the same as allocmem().
  36.  
  37. *---------------------------------------------------------------------------*/
  38.  
  39. unsigned _dos_allocmem(unsigned size, unsigned *segp)
  40. {
  41.     _BX = size;
  42.     _AH = 0x48;
  43.     geninterrupt(0x21);
  44.     if (_FLAGS & 1)                     /* if carry set, error */
  45.     {
  46.         *segp = _BX;                    /* return max. block size */
  47.         return (__DOSerror(_AX));       /* set errno */
  48.     }
  49.     else
  50.     {
  51.         *segp = _AX;                    /* return block address */
  52.         return (0);
  53.     }
  54. }
  55.