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.

99 lines
2.8 KiB

  1. /***
  2. *printf.c - print formatted
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines printf() - print formatted data
  8. *
  9. *Revision History:
  10. * 09-02-83 RN initial version
  11. * 04-13-87 JCR added const to declaration
  12. * 06-24-87 JCR (1) Made printf conform to ANSI prototype and use the
  13. * va_ macros; (2) removed SS_NE_DS conditionals.
  14. * 11-04-87 JCR Multi-thread support
  15. * 12-11-87 JCR Added "_LOAD_DS" to declaration
  16. * 05-27-88 PHG Merged DLL and normal versions
  17. * 06-14-88 JCR Use near pointer to reference _iob[] entries
  18. * 08-17-89 GJF Clean up, now specific to OS/2 2.0 (i.e., 386 flat
  19. * model). Also fixed copyright and indents.
  20. * 02-15-90 GJF Fixed copyright
  21. * 03-19-90 GJF Made calling type _CALLTYPE2, added #include
  22. * <cruntime.h> and removed #include <register.h>.
  23. * 07-23-90 SBM Replaced <assertm.h> by <assert.h>
  24. * 10-03-90 GJF New-style function declarator.
  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. * 03-07-95 GJF Use _[un]lock_str2 instead of _[un]lock_str. Also,
  30. * removed useless local and macros.
  31. * 03-02-98 GJF Exception-safe locking.
  32. *
  33. *******************************************************************************/
  34. #include <cruntime.h>
  35. #include <stdio.h>
  36. #include <dbgint.h>
  37. #include <stdarg.h>
  38. #include <file2.h>
  39. #include <internal.h>
  40. #include <mtdll.h>
  41. /***
  42. *int printf(format, ...) - print formatted data
  43. *
  44. *Purpose:
  45. * Prints formatted data on stdout using the format string to
  46. * format data and getting as many arguments as called for
  47. * Uses temporary buffering to improve efficiency.
  48. * _output does the real work here
  49. *
  50. *Entry:
  51. * char *format - format string to control data format/number of arguments
  52. * followed by list of arguments, number and type controlled by
  53. * format string
  54. *
  55. *Exit:
  56. * returns number of characters printed
  57. *
  58. *Exceptions:
  59. *
  60. *******************************************************************************/
  61. int __cdecl printf (
  62. const char *format,
  63. ...
  64. )
  65. /*
  66. * stdout 'PRINT', 'F'ormatted
  67. */
  68. {
  69. va_list arglist;
  70. int buffing;
  71. int retval;
  72. va_start(arglist, format);
  73. _ASSERTE(format != NULL);
  74. #ifdef _MT
  75. _lock_str2(1, stdout);
  76. __try {
  77. #endif
  78. buffing = _stbuf(stdout);
  79. retval = _output(stdout,format,arglist);
  80. _ftbuf(buffing, stdout);
  81. #ifdef _MT
  82. }
  83. __finally {
  84. _unlock_str2(1, stdout);
  85. }
  86. #endif
  87. return(retval);
  88. }