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.

96 lines
3.1 KiB

  1. /***
  2. *cputs.c - direct console output
  3. *
  4. * Copyright (c) 1989-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines _cputs() - write string directly to console
  8. *
  9. *Revision History:
  10. * 06-09-89 PHG Module created, based on asm version
  11. * 03-12-90 GJF Made calling type _CALLTYPE2 (for now), added #include
  12. * <cruntime.h> and fixed the copyright. Also, cleaned up
  13. * the formatting a bit.
  14. * 04-10-90 GJF Now _CALLTYPE1.
  15. * 06-05-90 SBM Recoded as pure 32-bit, using new file handle state bits
  16. * 07-24-90 SBM Removed '32' from API names
  17. * 09-28-90 GJF New-style function declarator.
  18. * 12-04-90 SRW Changed to include <oscalls.h> instead of <doscalls.h>
  19. * 12-06-90 SRW Added _CRUISER_ and _WIN32 conditionals.
  20. * 01-16-91 GJF ANSI naming.
  21. * 02-19-91 SRW Adapt to OpenFile/CreateFile changes (_WIN32_)
  22. * 02-25-91 MHL Adapt to ReadFile/WriteFile changes (_WIN32_)
  23. * 07-26-91 GJF Took out init. stuff and cleaned up the error
  24. * handling [_WIN32_].
  25. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  26. * 04-19-93 GJF Use WriteConsole instead of WriteFile.
  27. * 09-06-94 CFW Remove Cruiser support.
  28. * 12-08-95 SKS _confh is now initialized on demand
  29. * 02-07-98 GJF Changes for Win64: _confh is now an intptr_t.
  30. * 12-18-98 GJF Changes for 64-bit size_t.
  31. *
  32. *******************************************************************************/
  33. #include <cruntime.h>
  34. #include <oscalls.h>
  35. #include <internal.h>
  36. #include <mtdll.h>
  37. #include <conio.h>
  38. #include <stdio.h>
  39. #include <string.h>
  40. /*
  41. * declaration for console handle
  42. */
  43. extern intptr_t _confh;
  44. /***
  45. *int _cputs(string) - put a string to the console
  46. *
  47. *Purpose:
  48. * Writes the string directly to the console. No newline
  49. * is appended.
  50. *
  51. *Entry:
  52. * char *string - string to write
  53. *
  54. *Exit:
  55. * Good return = 0
  56. * Error return = !0
  57. *
  58. *Exceptions:
  59. *
  60. *******************************************************************************/
  61. int __cdecl _cputs (
  62. const char *string
  63. )
  64. {
  65. ULONG num_written;
  66. int error = 0; /* error occurred? */
  67. _mlock(_CONIO_LOCK); /* acquire console lock */
  68. /*
  69. * _confh, the handle to the console output, is created the
  70. * first time that either _putch() or _cputs() is called.
  71. */
  72. if (_confh == -2)
  73. __initconout();
  74. /* write string to console file handle */
  75. if ( (_confh == -1) || !WriteConsole( (HANDLE)_confh,
  76. (LPVOID)string,
  77. (unsigned int)strlen(string),
  78. &num_written,
  79. NULL )
  80. )
  81. /* return error indicator */
  82. error = -1;
  83. _munlock(_CONIO_LOCK); /* release console lock */
  84. return error;
  85. }