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.

160 lines
5.6 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: pantheios/util/string/snprintf.h (was pantheios/util/string/string.h)
  3. *
  4. * Purpose: snprintf() utility functions.
  5. *
  6. * Created: 21st June 2005
  7. * Updated: 15th March 2011
  8. *
  9. * Home: http://www.pantheios.org/
  10. *
  11. * Copyright (c) 2005-2011, Matthew Wilson and Synesis Software
  12. * Copyright (c) 1999-2005, Synesis Software and Matthew Wilson
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are
  17. * met:
  18. *
  19. * - Redistributions of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * - Redistributions in binary form must reproduce the above copyright
  22. * notice, this list of conditions and the following disclaimer in the
  23. * documentation and/or other materials provided with the distribution.
  24. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the
  25. * names of any contributors may be used to endorse or promote products
  26. * derived from this software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  31. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  32. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  33. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  35. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  36. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  37. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * ////////////////////////////////////////////////////////////////////// */
  41. /** \file pantheios/util/string/snprintf.h
  42. *
  43. * [C, C++] snprintf() utility functions.
  44. */
  45. #ifndef PANTHEIOS_INCL_PANTHEIOS_UTIL_STRING_H_SNPRINTF
  46. #define PANTHEIOS_INCL_PANTHEIOS_UTIL_STRING_H_SNPRINTF
  47. /* /////////////////////////////////////////////////////////////////////////
  48. * Version information
  49. */
  50. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  51. # define PANTHEIOS_VER_PANTHEIOS_UTIL_STRING_H_SNPRINTF_MAJOR 2
  52. # define PANTHEIOS_VER_PANTHEIOS_UTIL_STRING_H_SNPRINTF_MINOR 2
  53. # define PANTHEIOS_VER_PANTHEIOS_UTIL_STRING_H_SNPRINTF_REVISION 4
  54. # define PANTHEIOS_VER_PANTHEIOS_UTIL_STRING_H_SNPRINTF_EDIT 20
  55. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  56. /* /////////////////////////////////////////////////////////////////////////
  57. * Includes
  58. */
  59. #ifndef PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS
  60. # include <pantheios/pantheios.h>
  61. #endif /* !PANTHEIOS_INCL_PANTHEIOS_H_PANTHEIOS */
  62. #ifndef PANTHEIOS_INCL_H_STDARG
  63. # define PANTHEIOS_INCL_H_STDARG
  64. # include <stdarg.h>
  65. #endif /* !PANTHEIOS_INCL_H_STDARG */
  66. /* /////////////////////////////////////////////////////////////////////////
  67. * API
  68. */
  69. #if !defined(PANTHEIOS_NO_NAMESPACE)
  70. namespace pantheios
  71. {
  72. #endif /* !PANTHEIOS_NO_NAMESPACE */
  73. /* /////////////////////////////////////////////////////////////////////////
  74. * API
  75. */
  76. /** An <code>snprintf()</code>-equivalent that insulates Pantheios
  77. * implementation code from the peculiarities of different compilers
  78. * and/or libraries.
  79. *
  80. * \param dest The buffer into which the result will be written
  81. * \param cchDest The number of character spaces that are available to be
  82. * written
  83. * \param fmt The format string
  84. *
  85. * \return The usual return values defined for <code>snprinf()</code>
  86. */
  87. PANTHEIOS_CALL(int) pantheios_util_snprintf(
  88. pan_char_t* dest
  89. , size_t cchDest
  90. , const pan_char_t* fmt
  91. , ...
  92. )
  93. /* TODO: Change this to proper discriminated feature */
  94. #if defined(STLSOFT_COMPILER_IS_GCC)
  95. __attribute__((format(printf,3,4)))
  96. #endif /* compiler */
  97. ;
  98. /** A <code>vsnprintf()</code>-equivalent that insulates Pantheios
  99. * implementation code from the peculiarities of different compilers
  100. * and/or libraries.
  101. *
  102. * \param dest The buffer into which the result will be written
  103. * \param cchDest The number of character spaces that are available to be
  104. * written
  105. * \param fmt The format string
  106. * \param args The argument list
  107. *
  108. * \return The usual return values defined for <code>vsnprinf()</code>
  109. */
  110. PANTHEIOS_CALL(int) pantheios_util_vsnprintf(pan_char_t* dest, size_t cchDest, pan_char_t const* fmt, va_list args);
  111. #ifndef PANTHEIOS_DOCUMENTATION_SKIP_SECTION
  112. PANTHEIOS_CALL(int) pantheios_util_snprintf_a(
  113. char* dest
  114. , size_t cchDest
  115. , const char* fmt
  116. , ...
  117. )
  118. /* TODO: Change this to proper discriminated feature */
  119. #if defined(STLSOFT_COMPILER_IS_GCC)
  120. __attribute__((format(printf,3,4)))
  121. #endif /* compiler */
  122. ;
  123. PANTHEIOS_CALL(int) pantheios_util_vsnprintf_a(char* dest, size_t cchDest, char const* fmt, va_list args);
  124. #endif /* !PANTHEIOS_DOCUMENTATION_SKIP_SECTION */
  125. /* /////////////////////////////////////////////////////////////////////////
  126. * Namespace
  127. */
  128. #if !defined(PANTHEIOS_NO_NAMESPACE)
  129. } /* namespace pantheios */
  130. #endif /* !PANTHEIOS_NO_NAMESPACE */
  131. /* /////////////////////////////////////////////////////////////////////////
  132. * Inclusion
  133. */
  134. #ifdef STLSOFT_PPF_pragma_once_SUPPORT
  135. # pragma once
  136. #endif /* STLSOFT_PPF_pragma_once_SUPPORT */
  137. /* ////////////////////////////////////////////////////////////////////// */
  138. #endif /* !PANTHEIOS_INCL_PANTHEIOS_UTIL_STRING_H_SNPRINTF */
  139. /* ///////////////////////////// end of file //////////////////////////// */