home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / _freebuf.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  70 lines

  1. /***
  2. *_freebuf.c - release a buffer from a stream
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines _freebuf() - release a buffer from a stream
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <stdio.h>
  13. #include <file2.h>
  14. #include <dbgint.h>
  15. #include <internal.h>
  16. #include <stdlib.h>
  17.  
  18. /***
  19. *void _freebuf(stream) - release a buffer from a stream
  20. *
  21. *Purpose:
  22. *       free a buffer if at all possible. free() the space if malloc'd by me.
  23. *       forget about trying to free a user's buffer for him; it may be static
  24. *       memory (not from malloc), so he has to take care of it. this function
  25. *       is not intended for use outside the library.
  26. *
  27. *ifdef _MT
  28. *       Multi-thread notes:
  29. *       _freebuf() does NOT get the stream lock; it is assumed that the
  30. *       caller has already done this.
  31. *endif
  32. *
  33. *Entry:
  34. *       FILE *stream - stream to free bufer on
  35. *
  36. *Exit:
  37. *       Buffer may be freed.
  38. *       No return value.
  39. *
  40. *Exceptions:
  41. *
  42. *******************************************************************************/
  43.  
  44. void __cdecl _freebuf (
  45.         REG1 FILE *stream
  46.         )
  47. {
  48.         _ASSERTE(stream != NULL);
  49.  
  50.         if (inuse(stream) && mbuf(stream))
  51.         {
  52.                 _free_crt(stream->_base);
  53.  
  54. #ifdef _WIN32
  55.  
  56.                 stream->_flag &= ~(_IOMYBUF | _IOSETVBUF);
  57.  
  58. #else  /* _WIN32 */
  59. #if defined (_M_MPPC) || defined (_M_M68K)
  60.  
  61.                 stream->_flag &= ~_IOMYBUF;
  62.  
  63. #endif  /* defined (_M_MPPC) || defined (_M_M68K) */
  64. #endif  /* _WIN32 */
  65.  
  66.                 stream->_base = stream->_ptr = NULL;
  67.                 stream->_cnt = 0;
  68.         }
  69. }
  70.