Source code of Windows XP (NT5)
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.

69 lines
1.9 KiB

  1. /***
  2. *setbuf.c - give new file buffer
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines setbuf() - given a buffer to a stream or make it unbuffered
  8. *
  9. *Revision History:
  10. * 09-19-83 RN initial version
  11. * 09-28-87 JCR Corrected _iob2 indexing (now uses _iob_index() macro).
  12. * 11-02-87 JCR Re-wrote to use setvbuf()
  13. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  14. * 05-27-88 PHG Merged DLL and normal versions
  15. * 02-15-90 GJF Fixed copyright and indents
  16. * 03-19-90 GJF Replaced _LOAD_DS with _CALLTYPE1 and added #include
  17. * <cruntime.h>.
  18. * 07-23-90 SBM Replaced <assertm.h> by <assert.h>
  19. * 10-03-90 GJF New-style function declarator.
  20. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  21. * 05-11-93 GJF Added comments.
  22. * 02-06-94 CFW assert -> _ASSERTE.
  23. *
  24. *******************************************************************************/
  25. #include <cruntime.h>
  26. #include <stdio.h>
  27. #include <dbgint.h>
  28. /***
  29. *void setbuf(stream, buffer) - give a buffer to a stream
  30. *
  31. *Purpose:
  32. * Allow user to assign his/her own buffer to a stream.
  33. * if buffer is not NULL, it must be BUFSIZ in length.
  34. * if buffer is NULL, stream will be unbuffered.
  35. *
  36. * Since setbuf()'s functionality is a subset of setvbuf(), simply
  37. * call the latter routine to do the actual work.
  38. *
  39. * NOTE: For compatibility reasons, setbuf() uses BUFSIZ as the
  40. * buffer size rather than _INTERNAL_BUFSIZ. The reason for this,
  41. * and for the two BUFSIZ constants, is to allow stdio to use larger
  42. * buffers without breaking (already) compiled code.
  43. *
  44. *Entry:
  45. * FILE *stream - stream to be buffered or unbuffered
  46. * char *buffer - buffer of size BUFSIZ or NULL
  47. *
  48. *Exit:
  49. * None.
  50. *
  51. *Exceptions:
  52. *
  53. *******************************************************************************/
  54. void __cdecl setbuf (
  55. FILE *stream,
  56. char *buffer
  57. )
  58. {
  59. _ASSERTE(stream != NULL);
  60. if (buffer == NULL)
  61. setvbuf(stream, NULL, _IONBF, 0);
  62. else
  63. setvbuf(stream, buffer, _IOFBF, BUFSIZ);
  64. }