Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.5 KiB

  1. /***
  2. *_freebuf.c - release a buffer from a stream
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _freebuf() - release a buffer from a stream
  8. *
  9. *Revision History:
  10. * 09-19-83 RN initial version
  11. * 02-15-90 GJF Fixed copyright, alignment.
  12. * 03-16-90 GJF Replaced cdecl _LOAD_DS with _CALLTYPE1, added #include
  13. * <cruntime.h> and removed #include <register.h>.
  14. * 07-23-90 SBM Replaced <assertm.h> by <assert.h>
  15. * 10-03-90 GJF New-style function declarator.
  16. * 02-14-92 GJF Replaced _nfile with _nhandle for Win32.
  17. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  18. * 06-22-93 GJF Clear _IOSETVBUF flag (new).
  19. * 09-05-94 SKS Change "#ifdef" inside comments to "*ifdef" to avoid
  20. * problems with CRTL source release process.
  21. * 09-06-94 CFW Replace MTHREAD with _MT.
  22. * 01-04-95 GJF _WIN32_ -> _WIN32.
  23. * 01-10-95 CFW Debug CRT allocs.
  24. * 02-06-94 CFW assert -> _ASSERTE.
  25. * 02-16-95 GJF Merged in Mac version.
  26. * 09-06-95 GJF Removed inappropriate ASSERTE()-s.
  27. * 05-17-99 PML Remove all Macintosh support.
  28. *
  29. *******************************************************************************/
  30. #include <cruntime.h>
  31. #include <stdio.h>
  32. #include <file2.h>
  33. #include <dbgint.h>
  34. #include <internal.h>
  35. #include <stdlib.h>
  36. /***
  37. *void _freebuf(stream) - release a buffer from a stream
  38. *
  39. *Purpose:
  40. * free a buffer if at all possible. free() the space if malloc'd by me.
  41. * forget about trying to free a user's buffer for him; it may be static
  42. * memory (not from malloc), so he has to take care of it. this function
  43. * is not intended for use outside the library.
  44. *
  45. *ifdef _MT
  46. * Multi-thread notes:
  47. * _freebuf() does NOT get the stream lock; it is assumed that the
  48. * caller has already done this.
  49. *endif
  50. *
  51. *Entry:
  52. * FILE *stream - stream to free bufer on
  53. *
  54. *Exit:
  55. * Buffer may be freed.
  56. * No return value.
  57. *
  58. *Exceptions:
  59. *
  60. *******************************************************************************/
  61. void __cdecl _freebuf (
  62. REG1 FILE *stream
  63. )
  64. {
  65. _ASSERTE(stream != NULL);
  66. if (inuse(stream) && mbuf(stream))
  67. {
  68. _free_crt(stream->_base);
  69. stream->_flag &= ~(_IOMYBUF | _IOSETVBUF);
  70. stream->_base = stream->_ptr = NULL;
  71. stream->_cnt = 0;
  72. }
  73. }