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