oi_string.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2014 The Android Open Source Project
  4. * Copyright 2002 - 2004 Open Interface North America, Inc. All rights reserved.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at:
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. ******************************************************************************/
  19. #ifndef OI_STRING_H
  20. #define OI_STRING_H
  21. /**
  22. * @file
  23. * This file contains BM3 supplied portable string.h functions
  24. *
  25. */
  26. /**********************************************************************************
  27. $Revision: #1 $
  28. ***********************************************************************************/
  29. #include "oi_cpu_dep.h"
  30. #include "oi_stddefs.h"
  31. #if defined(USE_NATIVE_MEMCPY) || defined(USE_NATIVE_MALLOC)
  32. #include <string.h>
  33. #endif
  34. /** \addtogroup Misc Miscellaneous APIs */
  35. /**@{*/
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /*
  40. * If we are using Native malloc(), we must also use
  41. * native Ansi string.h functions for memory manipulation.
  42. */
  43. #ifdef USE_NATIVE_MALLOC
  44. #ifndef USE_NATIVE_MEMCPY
  45. #define USE_NATIVE_MEMCPY
  46. #endif
  47. #endif
  48. #ifdef USE_NATIVE_MEMCPY
  49. #define OI_MemCopy(to, from, size) memcpy((to), (from), (size))
  50. #define OI_MemSet(block, val, size) memset((block), (val), (size))
  51. #define OI_MemZero(block, size) memset((block), 0, (size))
  52. #define OI_MemCmp(s1, s2, n) memcmp((s1), (s2), (n))
  53. #define OI_Strcpy(dest, src) strcpy((dest),(src))
  54. #define OI_Strcat(dest, src) strcat((dest),(src))
  55. #define OI_StrLen(str) strlen((str))
  56. #define OI_Strcmp(s1, s2) strcmp((s1), (s2))
  57. #define OI_Strncmp(s1, s2, n) strncmp((s1), (s2), (n))
  58. #else
  59. /*
  60. * OI_MemCopy
  61. *
  62. * Copy an arbitrary number of bytes from one memory address to another.
  63. * The underlying implementation is the ANSI memmove() or equivalant, so
  64. * overlapping memory copies will work correctly.
  65. */
  66. void OI_MemCopy(void *To, void const *From, OI_UINT32 Size);
  67. /*
  68. * OI_MemSet
  69. *
  70. * Sets all bytes in a block of memory to the same value
  71. */
  72. void OI_MemSet(void *Block, OI_UINT8 Val, OI_UINT32 Size);
  73. /*
  74. * OI_MemZero
  75. *
  76. * Sets all bytes in a block of memory to zero
  77. */
  78. void OI_MemZero(void *Block, OI_UINT32 Size);
  79. /*
  80. * OI_MemCmp
  81. *
  82. * Compare two blocks of memory
  83. *
  84. * Returns:
  85. * 0, if s1 == s2
  86. * < 0, if s1 < s2
  87. * > 0, if s2 > s2
  88. */
  89. OI_INT OI_MemCmp(void const *s1, void const *s2, OI_UINT32 n);
  90. /*
  91. * OI_Strcpy
  92. *
  93. * Copies the Null terminated string from pStr to pDest, and
  94. * returns pDest.
  95. */
  96. OI_CHAR *OI_Strcpy(OI_CHAR *pDest,
  97. OI_CHAR const *pStr);
  98. /*
  99. * OI_Strcat
  100. *
  101. * Concatonates the pStr string to the end of pDest, and
  102. * returns pDest.
  103. */
  104. OI_CHAR *OI_Strcat(OI_CHAR *pDest,
  105. OI_CHAR const *pStr) ;
  106. /*
  107. * OI_StrLen
  108. *
  109. * Calculates the number of OI_CHARs in pStr (not including
  110. * the Null terminator) and returns the value.
  111. */
  112. OI_UINT OI_StrLen(OI_CHAR const *pStr) ;
  113. /*
  114. * OI_Strcmp
  115. *
  116. * Compares two Null terminated strings
  117. *
  118. * Returns:
  119. * 0, if s1 == s2
  120. * < 0, if s1 < s2
  121. * > 0, if s2 > s2
  122. */
  123. OI_INT OI_Strcmp(OI_CHAR const *s1,
  124. OI_CHAR const *s2);
  125. /*
  126. * OI_Strncmp
  127. *
  128. * Compares the first "len" OI_CHARs of strings s1 and s2.
  129. *
  130. * Returns:
  131. * 0, if s1 == s2
  132. * < 0, if s1 < s2
  133. * > 0, if s2 > s2
  134. */
  135. OI_INT OI_Strncmp(OI_CHAR const *s1,
  136. OI_CHAR const *s2,
  137. OI_UINT32 len);
  138. #endif /* USE_NATIVE_MEMCPY */
  139. /*
  140. * OI_StrcmpInsensitive
  141. *
  142. * Compares two Null terminated strings, treating
  143. * the Upper and Lower case of 'A' through 'Z' as
  144. * equivilent.
  145. *
  146. * Returns:
  147. * 0, if s1 == s2
  148. * < 0, if s1 < s2
  149. * > 0, if s2 > s2
  150. */
  151. OI_INT OI_StrcmpInsensitive(OI_CHAR const *s1,
  152. OI_CHAR const *s2);
  153. /*
  154. * OI_StrncmpInsensitive
  155. *
  156. * Compares the first "len" OI_CHARs of strings s1 and s2,
  157. * treating the Upper and Lower case of 'A' through 'Z' as
  158. * equivilent.
  159. *
  160. *
  161. * Returns:
  162. * 0, if s1 == s2
  163. * < 0, if s1 < s2
  164. * > 0, if s2 > s2
  165. */
  166. OI_INT OI_StrncmpInsensitive(OI_CHAR const *s1,
  167. OI_CHAR const *s2,
  168. OI_UINT len);
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. /** @} */
  173. /*****************************************************************************/
  174. #endif /* OI_STRING_H */