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.

106 lines
1.7 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. fusionprintf.h
  5. Abstract:
  6. safer sprintf variants
  7. Author:
  8. Jay Krell (JayKrell) November 2000
  9. Revision History:
  10. Jay Krell (JayKrell) January 2002
  11. from base\ntsetup\textmode\kernel\spprintf.c to base\win32\fusion\inc\fusionprintf.h
  12. --*/
  13. #include <stdarg.h>
  14. #include <stdio.h>
  15. //
  16. // _snprintf and co. do not write a terminal nul when the string just fits.
  17. // These function do.
  18. //
  19. inline
  20. void
  21. FusionpFormatStringVaA(
  22. PSTR Buffer,
  23. SIZE_T Size,
  24. PCSTR Format,
  25. va_list Args
  26. )
  27. {
  28. if (Buffer != NULL && Size != 0)
  29. {
  30. Buffer[0] = 0;
  31. Size -= 1;
  32. if (Size != 0)
  33. {
  34. ::_vsnprintf(Buffer, Size, Format, Args);
  35. }
  36. Buffer[Size] = 0;
  37. }
  38. }
  39. inline
  40. void
  41. __cdecl
  42. FusionpFormatStringA(
  43. PSTR Buffer,
  44. SIZE_T Size,
  45. PCSTR Format,
  46. ...
  47. )
  48. {
  49. va_list Args;
  50. va_start(Args, Format);
  51. FusionpFormatStringVaA(Buffer, Size, Format, Args);
  52. va_end(Args);
  53. }
  54. inline
  55. void
  56. FusionpFormatStringVaW(
  57. PWSTR Buffer,
  58. SIZE_T Size,
  59. PCWSTR Format,
  60. va_list Args
  61. )
  62. {
  63. if (Buffer != NULL && Size != 0)
  64. {
  65. Buffer[0] = 0;
  66. Size -= 1;
  67. if (Size != 0)
  68. {
  69. ::_vsnwprintf(Buffer, Size, Format, Args);
  70. }
  71. Buffer[Size] = 0;
  72. }
  73. }
  74. inline
  75. void
  76. __cdecl
  77. FusionpFormatStringW(
  78. PWSTR Buffer,
  79. SIZE_T Size,
  80. PCWSTR Format,
  81. ...
  82. )
  83. {
  84. va_list Args;
  85. va_start(Args, Format);
  86. FusionpFormatStringVaW(Buffer, Size, Format, Args);
  87. va_end(Args);
  88. }