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.

92 lines
2.6 KiB

  1. /***
  2. *fputs.c - write a string to a stream
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines fputs() - writes a string to a stream
  8. *
  9. *Revision History:
  10. * 09-02-83 RN initial version
  11. * 08-31-84 RN modified to use the new, fast fwrite.
  12. * 04-13-87 JCR added const to declaration
  13. * 06-30-87 JCR made fputs return values conform to ANSI [MSC only]
  14. * 11-06-87 JCR Multi-thread support
  15. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  16. * 05-18-88 JCR Error return = EOF
  17. * 05-27-88 PHG Merged DLL and normal versions
  18. * 09-22-88 GJF Include internal.h to get prototypes for _[s|f]tbuf()
  19. * 02-15-90 GJF Fixed copyright and indents
  20. * 03-19-90 GJF Replaced _LOAD_DS with _CALLTYPE1, added #include
  21. * <cruntime.h> and removed #include <register.h>.
  22. * 03-26-90 GJF Added #include <string.h>.
  23. * 07-23-90 SBM Replaced <assertm.h> by <assert.h>
  24. * 10-02-90 GJF New-style function declarators.
  25. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  26. * 09-06-94 CFW Replace MTHREAD with _MT.
  27. * 02-06-94 CFW assert -> _ASSERTE.
  28. * 03-07-95 GJF _[un]lock_str macros now take FILE * arg.
  29. * 02-27-98 GJF Exception-safe locking.
  30. * 01-04-99 GJF Changes for 64-bit size_t.
  31. *
  32. *******************************************************************************/
  33. #include <cruntime.h>
  34. #include <stdio.h>
  35. #include <dbgint.h>
  36. #include <file2.h>
  37. #include <string.h>
  38. #include <internal.h>
  39. #include <mtdll.h>
  40. /***
  41. *int fputs(string, stream) - write a string to a file
  42. *
  43. *Purpose:
  44. * Output the given string to the stream, don't write the '\0' or
  45. * supply a '\n'. Uses _stbuf and _ftbuf for efficiency reasons.
  46. *
  47. *Entry:
  48. * char *string - string to write
  49. * FILE *stream - stream to write to.
  50. *
  51. *Exit:
  52. * Good return = 0
  53. * Error return = EOF
  54. *
  55. *Exceptions:
  56. *
  57. *******************************************************************************/
  58. int __cdecl fputs (
  59. const char *string,
  60. FILE *stream
  61. )
  62. {
  63. REG2 int buffing;
  64. REG1 size_t length;
  65. REG3 size_t ndone;
  66. _ASSERTE(string != NULL);
  67. _ASSERTE(stream != NULL);
  68. length = strlen(string);
  69. #ifdef _MT
  70. _lock_str(stream);
  71. __try {
  72. #endif
  73. buffing = _stbuf(stream);
  74. ndone = _fwrite_lk(string,1,length,stream);
  75. _ftbuf(buffing, stream);
  76. #ifdef _MT
  77. }
  78. __finally {
  79. _unlock_str(stream);
  80. }
  81. #endif
  82. return(ndone == length ? 0 : EOF);
  83. }