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

  1. /***
  2. *setbuf.c - give new file buffer
  3. *
  4. *       Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       defines setbuf() - given a buffer to a stream or make it unbuffered
  8. *
  9. *******************************************************************************/
  10.  
  11. #include <cruntime.h>
  12. #include <stdio.h>
  13. #include <dbgint.h>
  14.  
  15. /***
  16. *void setbuf(stream, buffer) - give a buffer to a stream
  17. *
  18. *Purpose:
  19. *       Allow user to assign his/her own buffer to a stream.
  20. *               if buffer is not NULL, it must be BUFSIZ in length.
  21. *               if buffer is NULL, stream will be unbuffered.
  22. *
  23. *       Since setbuf()'s functionality is a subset of setvbuf(), simply
  24. *       call the latter routine to do the actual work.
  25. *
  26. *       NOTE: For compatibility reasons, setbuf() uses BUFSIZ as the
  27. *       buffer size rather than _INTERNAL_BUFSIZ. The reason for this,
  28. *       and for the two BUFSIZ constants, is to allow stdio to use larger
  29. *       buffers without breaking (already) compiled code.
  30. *
  31. *Entry:
  32. *       FILE *stream - stream to be buffered or unbuffered
  33. *       char *buffer - buffer of size BUFSIZ or NULL
  34. *
  35. *Exit:
  36. *       None.
  37. *
  38. *Exceptions:
  39. *
  40. *******************************************************************************/
  41.  
  42. void __cdecl setbuf (
  43.         FILE *stream,
  44.         char *buffer
  45.         )
  46. {
  47.         _ASSERTE(stream != NULL);
  48.  
  49.         if (buffer == NULL)
  50.                 setvbuf(stream, NULL, _IONBF, 0);
  51.         else
  52.                 setvbuf(stream, buffer, _IOFBF, BUFSIZ);
  53.  
  54. }
  55.