home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / FCALLOC.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.7 KB  |  89 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. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21. #include <alloc.h>
  22. #include <stddef.h>
  23.  
  24. #if (LDATA)
  25. #include <mem.h>
  26. #else
  27.  
  28. /*--------------------------------------------------------------------------*
  29.  
  30. Name        lsetmem - assigns a value to memory
  31.  
  32. Usage        void near pascal lsetmem(char far *p, unsigned n,
  33.                      unsigned char val);
  34.  
  35. Description    sets the first n bytes of the block pointed to by the
  36.         far pointer p to the character val.
  37.  
  38. Return value    Nothing.
  39.  
  40. *---------------------------------------------------------------------------*/
  41. static void near pascal lsetmem(char far *p, unsigned n, unsigned char val)
  42. {
  43. asm    les    di, dword ptr p
  44. asm    mov    cx, n
  45. asm    mov    al, val
  46. asm    rep    stosb
  47. }
  48. #endif
  49.  
  50.  
  51. /*--------------------------------------------------------------------------*
  52.  
  53. Name        farcalloc - allocates memory from far heap
  54.  
  55. Usage        void *farcalloc(unsigned long nunits,
  56.                   unsigned long unitsz);
  57.  
  58. Prototype in    alloc.h
  59.  
  60. Description     allocates memory from the far heap for an array containing
  61.         nunits elements, each unitsz bytes long, and set the
  62.         allocated bytes to zero
  63.  
  64. Return value    success : far pointer to the newly allocated memory block
  65.         failure : NULL
  66.  
  67. *---------------------------------------------------------------------------*/
  68. #pragma warn -def
  69. void far *farcalloc(unsigned long nunits, unsigned long unitsz)
  70. {
  71.     register char    far *cp, huge *scp;
  72.     unsigned    sval;
  73.  
  74.     nunits *= unitsz;
  75.     if ((cp = farmalloc(nunits)) != NULL)
  76.         for (scp = cp; nunits; scp += sval, nunits -= sval)
  77.         {
  78.                         sval = (nunits > 64000L) ? (unsigned)64000L : (unsigned)nunits;
  79. #if (LDATA)
  80.             setmem((char far *)scp, sval, 0);
  81. #else
  82.             lsetmem((char far *)scp, sval, 0);
  83. #endif
  84.         }
  85.     return(cp);
  86. }
  87. #pragma warn .def
  88.  
  89.