ixmlmembuf.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /**************************************************************************
  2. *
  3. * Copyright (c) 2000-2003 Intel Corporation
  4. * All rights reserved.
  5. * Copyright (c) 2012 France Telecom All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * - Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * - Neither name of Intel Corporation nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  27. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. **************************************************************************/
  32. #ifndef IXML_MEMBUF_H
  33. #define IXML_MEMBUF_H
  34. /*!
  35. * \file
  36. */
  37. #include "ixml.h"
  38. #include <stdlib.h> /* for size_t */
  39. #define MINVAL(a, b) ( (a) < (b) ? (a) : (b) )
  40. #define MAXVAL(a, b) ( (a) > (b) ? (a) : (b) )
  41. #define MEMBUF_DEF_SIZE_INC 20u
  42. /*!
  43. * \brief The ixml_membuf type.
  44. */
  45. typedef struct
  46. {
  47. char *buf;
  48. size_t length;
  49. size_t capacity;
  50. size_t size_inc;
  51. } ixml_membuf;
  52. /*!
  53. * \brief ixml_membuf initialization routine.
  54. */
  55. void ixml_membuf_init(
  56. /*! [in,out] The memory buffer to initializa. */
  57. ixml_membuf *m);
  58. /*!
  59. * \brief ixml_membuf clearing routine.
  60. *
  61. * The internal buffer is deleted and ixml_membuf_init() is called in the end
  62. * to reinitialize the buffer.
  63. */
  64. void ixml_membuf_destroy(
  65. /*! [in,out] The memory buffer to clear. */
  66. ixml_membuf *m);
  67. /*!
  68. * \brief Copies the contents o a buffer to the designated ixml_membuf.
  69. *
  70. * The previous contents of the ixml_membuf are destroyed.
  71. *
  72. * \return IXML_SUCCESS if successfull, or the error code returned
  73. * by ixml_membuf_set_size().
  74. *
  75. * \sa ixml_membuf_assign_str().
  76. */
  77. int ixml_membuf_assign(
  78. /*! [in,out] The memory buffer on which to operate. */
  79. ixml_membuf *m,
  80. /*! [in] The input buffer to copy from. */
  81. const void *buf,
  82. /*! [in] The number of bytes to copy from the input buffer. */
  83. size_t buf_len);
  84. /*!
  85. * \brief Copies a \b NULL terminated string to the ixml_buffer.
  86. *
  87. * This is a convenience function that internally uses ixml_membuf_assign().
  88. *
  89. * \return The return value of ixml_membuf_assign().
  90. *
  91. * \sa ixml_membuf_assign().
  92. */
  93. int ixml_membuf_assign_str(
  94. /*! [in,out] The memory buffer on which to operate. */
  95. ixml_membuf *m,
  96. /*! [in] The input string to copy from. */
  97. const char *c_str);
  98. /*!
  99. * \brief Appends one byte to the designated ixml_membuffer.
  100. *
  101. * This is a convenience function that internally uses ixml_membuf_insert().
  102. *
  103. * \return The return value of ixml_membuf_insert().
  104. *
  105. * \sa ixml_membuf_insert()
  106. */
  107. int ixml_membuf_append(
  108. /*! [in,out] The memory buffer on which to operate. */
  109. ixml_membuf *m,
  110. /*! [in] The pointer to the byte to append. */
  111. const void *buf);
  112. /*!
  113. * \brief Appends the contents of a \b NULL terminated string to the designated
  114. * ixml_membuf.
  115. *
  116. * This is a convenience function that internally uses ixml_membuf_insert().
  117. *
  118. * \return The return value of ixml_membuf_insert().
  119. *
  120. * \sa ixml_membuf_insert().
  121. */
  122. int ixml_membuf_append_str(
  123. /*! [in,out] The memory buffer on which to operate. */
  124. ixml_membuf *m,
  125. /*! [in] The input string to copy from. */
  126. const char *c_str);
  127. /*!
  128. * \brief
  129. *
  130. * \return
  131. * \li 0 if successfull.
  132. * \li IXML_INDEX_SIZE_ERR if the index parameter is out of range.
  133. * \li Or the return code of ixml_membuf_set_size()
  134. *
  135. * \sa ixml_membuf_set_size()
  136. */
  137. int ixml_membuf_insert(
  138. /*! [in,out] The memory buffer on which to operate. */
  139. ixml_membuf *m,
  140. /*! [in] The pointer to the input buffer. */
  141. const void *buf,
  142. /*! [in] The buffer length. */
  143. size_t buf_len,
  144. /*! [in] The point of insertion relative to the beggining of the
  145. * ixml_membuf internal buffer. */
  146. size_t index);
  147. #endif /* IXML_MEMBUF_H */