home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / FCALLOC.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  2.5 KB  |  88 lines

  1. /*--------------------------------------------------------------------------
  2.  * filename - fcalloc.cas
  3.  *
  4.  * function(s)
  5.  *        fcalloc - allocates memory from far heap
  6.  *        lsetmem - assigns a value to memory
  7.  *-------------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <alloc.h>
  21. #include <stddef.h>
  22.  
  23. #if (LDATA)
  24. #include <mem.h>
  25. #else
  26.  
  27. /*--------------------------------------------------------------------------*
  28.  
  29. Name            lsetmem - assigns a value to memory
  30.  
  31. Usage           void near pascal lsetmem(char far *p, unsigned n,
  32.                                          unsigned char val);
  33.  
  34. Description     sets the first n bytes of the block pointed to by the
  35.                 far pointer p to the character val.
  36.  
  37. Return value    Nothing.
  38.  
  39. *---------------------------------------------------------------------------*/
  40. static void near pascal lsetmem(char far *p, unsigned n, unsigned char val)
  41. {
  42. asm     les     di, dword ptr p
  43. asm     mov     cx, n
  44. asm     mov     al, val
  45. asm     rep     stosb
  46. }
  47. #endif
  48.  
  49.  
  50. /*--------------------------------------------------------------------------*
  51.  
  52. Name            farcalloc - allocates memory from far heap
  53.  
  54. Usage           void *farcalloc(unsigned long nunits,
  55.                               unsigned long unitsz);
  56.  
  57. Prototype in    alloc.h
  58.  
  59. Description     allocates memory from the far heap for an array containing
  60.                 nunits elements, each unitsz bytes long, and set the
  61.                 allocated bytes to zero
  62.  
  63. Return value    success : far pointer to the newly allocated memory block
  64.                 failure : NULL
  65.  
  66. *---------------------------------------------------------------------------*/
  67. #pragma warn -def
  68. void far *farcalloc(unsigned long nunits, unsigned long unitsz)
  69. {
  70.         register char   far *cp, huge *scp;
  71.         unsigned        sval;
  72.  
  73.         nunits *= unitsz;
  74.         if ((cp = farmalloc(nunits)) != NULL)
  75.                 for (scp = cp; nunits; scp += sval, nunits -= sval)
  76.                 {
  77.                         sval = (nunits > 64000L) ? (unsigned)64000L : (unsigned)nunits;
  78. #if (LDATA)
  79.                         setmem((char far *)scp, sval, 0);
  80. #else
  81.                         lsetmem((char far *)scp, sval, 0);
  82. #endif
  83.                 }
  84.         return(cp);
  85. }
  86. #pragma warn .def
  87.  
  88.