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.

118 lines
3.3 KiB

  1. /***
  2. *puts.c - put a string to stdout
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines puts() and _putws() - put a string to stdout
  8. *
  9. *Revision History:
  10. * 09-02-83 RN initial version
  11. * 08-31-84 RN modified to use new, blazing fast fwrite
  12. * 07-01-87 JCR made return values conform to ANSI [MSC only]
  13. * 09-24-87 JCR Added 'const' to declaration [ANSI]
  14. * 11-05-87 JCR Multi-thread version
  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. * 06-15-88 JCR Near reference to _iob[] entries; improve REG variables
  19. * 08-18-89 GJF Clean up, now specific to OS/2 2.0 (i.e., 386 flat
  20. * model). Also fixed copyright and indents.
  21. * 02-15-90 GJF Fixed copyright
  22. * 03-19-90 GJF Made calling type _CALLTYPE1, added #include
  23. * <cruntime.h> and removed #include <register.h>.
  24. * 03-26-90 GJF Added #include <string.h>.
  25. * 07-23-90 SBM Replaced <assertm.h> by <assert.h>
  26. * 10-03-90 GJF New-style function declarators.
  27. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  28. * 01-31-94 CFW Unicode enable.
  29. * 02-04-94 CFW Use _putwchar_lk.
  30. * 04-18-94 CFW Get rid of those pesky warnings.
  31. * 09-06-94 CFW Replace MTHREAD with _MT.
  32. * 02-06-94 CFW assert -> _ASSERTE.
  33. * 02-22-95 GJF Replaced WPRFLAG with _UNICODE.
  34. * 03-07-95 GJF Use _[un]lock_str2 instead of _[un]lock_str. Also,
  35. * removed useless local and macros.
  36. * 03-02-98 GJF Exception-safe locking.
  37. * 01-04-99 GJF Changes for 64-bit size_t.
  38. *
  39. *******************************************************************************/
  40. #include <cruntime.h>
  41. #include <stdio.h>
  42. #include <dbgint.h>
  43. #include <file2.h>
  44. #include <string.h>
  45. #include <internal.h>
  46. #include <mtdll.h>
  47. #include <tchar.h>
  48. /***
  49. *int puts(string) - put a string to stdout with newline
  50. *
  51. *Purpose:
  52. * Write a string to stdout; don't include '\0' but append '\n'. Uses
  53. * temporary buffering for efficiency on stdout if unbuffered.
  54. *
  55. *Entry:
  56. * char *string - string to output
  57. *
  58. *Exit:
  59. * Good return = 0
  60. * Error return = EOF
  61. *
  62. *Exceptions:
  63. *
  64. *******************************************************************************/
  65. int __cdecl _putts (
  66. const _TCHAR *string
  67. )
  68. {
  69. int buffing;
  70. #ifndef _UNICODE
  71. size_t length;
  72. size_t ndone;
  73. #endif
  74. int retval = _TEOF; /* error */
  75. _ASSERTE(string != NULL);
  76. #ifdef _MT
  77. _lock_str2(1, stdout);
  78. __try {
  79. #endif
  80. buffing = _stbuf(stdout);
  81. #ifdef _UNICODE
  82. while (*string) {
  83. if (_putwchar_lk(*string++) == WEOF)
  84. goto done;
  85. }
  86. if (_putwchar_lk(L'\n') != WEOF)
  87. retval = 0; /* success */
  88. #else
  89. length = strlen(string);
  90. ndone = _fwrite_lk(string,1,length,stdout);
  91. if (ndone == length) {
  92. _putc_lk('\n',stdout);
  93. retval = 0; /* success */
  94. }
  95. #endif
  96. #ifdef _UNICODE
  97. done:
  98. #endif
  99. _ftbuf(buffing, stdout);
  100. #ifdef _MT
  101. }
  102. __finally {
  103. _unlock_str2(1, stdout);
  104. }
  105. #endif
  106. return retval;
  107. }