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.

162 lines
4.5 KiB

  1. /***
  2. *vswprint.c - print formatted data into a string from var arg list
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines vswprintf() and _vsnwprintf() - print formatted output to
  8. * a string, get the data from an argument ptr instead of explicit
  9. * arguments.
  10. *
  11. *Revision History:
  12. * 05-16-92 KRS Created from vsprintf.c.
  13. * 02-18-93 SRW Make FILE a local and remove lock usage.
  14. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  15. * 02-07-94 CFW POSIXify.
  16. * 09-05-94 SKS Change "#ifdef" inside comments to "*ifdef" to avoid
  17. * problems with CRTL source release process.
  18. * 02-06-94 CFW assert -> _ASSERTE.
  19. * 01-06-99 GJF Changes for 64-bit size_t.
  20. * 03-16-00 GB Added _vscwprintf()
  21. *
  22. *******************************************************************************/
  23. #ifndef _POSIX_
  24. #include <cruntime.h>
  25. #include <stdio.h>
  26. #include <wchar.h>
  27. #include <dbgint.h>
  28. #include <stdarg.h>
  29. #include <internal.h>
  30. #include <limits.h>
  31. #include <mtdll.h>
  32. #define MAXSTR INT_MAX
  33. /***
  34. *ifndef _COUNT_
  35. *int vswprintf(string, format, ap) - print formatted data to string from arg ptr
  36. *else
  37. *int _vsnwprintf(string, cnt, format, ap) - print formatted data to string from arg ptr
  38. *endif
  39. *
  40. *Purpose:
  41. * Prints formatted data, but to a string and gets data from an argument
  42. * pointer.
  43. * Sets up a FILE so file i/o operations can be used, make string look
  44. * like a huge buffer to it, but _flsbuf will refuse to flush it if it
  45. * fills up. Appends '\0' to make it a true string.
  46. *
  47. * Allocate the 'fake' _iob[] entryit statically instead of on
  48. * the stack so that other routines can assume that _iob[] entries are in
  49. * are in DGROUP and, thus, are near.
  50. *
  51. *ifdef _COUNT_
  52. * The _vsnwprintf() flavor takes a count argument that is
  53. * the max number of bytes that should be written to the
  54. * user's buffer.
  55. *endif
  56. *
  57. * Multi-thread: (1) Since there is no stream, this routine must never try
  58. * to get the stream lock (i.e., there is no stream lock either). (2)
  59. * Also, since there is only one staticly allocated 'fake' iob, we must
  60. * lock/unlock to prevent collisions.
  61. *
  62. *Entry:
  63. * wchar_t *string - place to put destination string
  64. *ifdef _COUNT_
  65. * size_t count - max number of bytes to put in buffer
  66. *endif
  67. * wchar_t *format - format string, describes format of data
  68. * va_list ap - varargs argument pointer
  69. *
  70. *Exit:
  71. * returns number of wide characters in string
  72. *
  73. *Exceptions:
  74. *
  75. *******************************************************************************/
  76. #ifndef _COUNT_
  77. int __cdecl vswprintf (
  78. wchar_t *string,
  79. const wchar_t *format,
  80. va_list ap
  81. )
  82. #else
  83. int __cdecl _vsnwprintf (
  84. wchar_t *string,
  85. size_t count,
  86. const wchar_t *format,
  87. va_list ap
  88. )
  89. #endif
  90. {
  91. FILE str;
  92. REG1 FILE *outfile = &str;
  93. REG2 int retval;
  94. _ASSERTE(string != NULL);
  95. _ASSERTE(format != NULL);
  96. outfile->_flag = _IOWRT|_IOSTRG;
  97. outfile->_ptr = outfile->_base = (char *) string;
  98. #ifndef _COUNT_
  99. outfile->_cnt = MAXSTR;
  100. #else
  101. outfile->_cnt = (int)(count*sizeof(wchar_t));
  102. #endif
  103. retval = _woutput(outfile,format,ap );
  104. _putc_lk('\0',outfile); /* no-lock version */
  105. _putc_lk('\0',outfile); /* 2nd byte for wide char version */
  106. return(retval);
  107. }
  108. /***
  109. * _vscwprintf() - counts the number of character needed to print the formatted
  110. * data
  111. *
  112. *Purpose:
  113. * Counts the number of characters in the fotmatted data.
  114. *
  115. *Entry:
  116. * wchar_t *format - format string, describes format of data
  117. * va_list ap - varargs argument pointer
  118. *
  119. *Exit:
  120. * returns number of characters needed to print formatted data.
  121. *
  122. *Exceptions:
  123. *
  124. *******************************************************************************/
  125. #ifndef _COUNT_
  126. int __cdecl _vscwprintf (
  127. const wchar_t *format,
  128. va_list ap
  129. )
  130. {
  131. FILE str;
  132. REG1 FILE *outfile = &str;
  133. REG2 int retval;
  134. _ASSERTE(format != NULL);
  135. outfile->_cnt = MAXSTR;
  136. outfile->_flag = _IOWRT|_IOSTRG;
  137. outfile->_ptr = outfile->_base = NULL;
  138. retval = _woutput(outfile,format,ap);
  139. return(retval);
  140. }
  141. #endif
  142. #endif /* _POSIX_ */