home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / crypl200.zip / BNLIB / LBNMEM.H < prev    next >
C/C++ Source or Header  |  1996-05-16  |  2KB  |  63 lines

  1. /*
  2.  * Operations on the usual buffers of bytes
  3.  */
  4. #ifndef BNSECURE
  5. #define BNSECURE 1
  6. #endif
  7.  
  8. /*
  9.  * These operations act on buffers of memory, just like malloc & free.
  10.  * One exception: it is not legal to pass a NULL pointer to lbnMemFree.
  11.  */
  12.  
  13. #ifndef lbnMemAlloc
  14. void *lbnMemAlloc(unsigned bytes);
  15. #endif
  16.  
  17. #ifndef lbnMemFree
  18. void lbnMemFree(void *ptr, unsigned bytes);
  19. #endif
  20.  
  21. /* This wipes out a buffer of bytes if necessary needed. */
  22.  
  23. #ifndef lbnMemWipe
  24. #if BNSECURE
  25. void lbnMemWipe(void *ptr, unsigned bytes);
  26. #else
  27. #define lbnMemWipe(ptr, bytes) (void)(ptr,bytes)
  28. #endif
  29. #endif /* !lbnMemWipe */
  30.  
  31. /*
  32.  * lbnRealloc is NOT like realloc(); it's endian-sensitive
  33.  * If lbnMemRealloc is #defined, lbnRealloc will be defined in terms of it.
  34.  * It is legal to pass a NULL pointer to lbnRealloc, although oldbytes
  35.  * will always be sero.
  36.  */
  37. #ifndef lbnRealloc
  38. void *lbnRealloc(void *ptr, unsigned oldbytes, unsigned newbytes);
  39. #endif
  40.  
  41.  
  42. /*
  43.  * These macros are the ones actually used most often in the math library.
  44.  * They take and return pointers to the *end* of the given buffer, and
  45.  * take sizes in terms of words, not bytes.
  46.  *
  47.  * Note that LBNALLOC takes the pointer as an argument instead of returning
  48.  * the value.
  49.  *
  50.  * Note also that these macros are only useable if you have included
  51.  * lbn.h (for the BIG and BIGLITTLE macros), which this file does NOT include.
  52.  */
  53.  
  54. #define LBNALLOC(p,words) BIGLITTLE( \
  55.     if ( ((p) = lbnMemAlloc((words)*sizeof*(p))) != 0) (p) += (words), \
  56.     (p) = lbnMemAlloc((words) * sizeof*(p)) \
  57.     )
  58. #define LBNFREE(p,words) lbnMemFree((p) BIG(-(words)), (words) * sizeof*(p))
  59. #define LBNREALLOC(p,old,new) \
  60.     lbnRealloc(p, (old) * sizeof*(p), (new) * sizeof*(p))
  61. #define LBNWIPE(p,words) lbnMemWipe((p) BIG(-(words)), (words) * sizeof*(p))
  62.  
  63.