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 /**********************************************************************************
28   $Revision: #1 $
29 ***********************************************************************************/
30 
31 #include "oi_cpu_dep.h"
32 #include "oi_stddefs.h"
33 
34 #if defined(USE_NATIVE_MEMCPY) || defined(USE_NATIVE_MALLOC)
35 #include <string.h>
36 #endif
37 
38 /** \addtogroup Misc Miscellaneous APIs */
39 /**@{*/
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
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, OI_UINT32 Size);
78 
79 
80 /*
81  * OI_MemSet
82  *
83  * Sets all bytes in a block of memory to the same value
84  */
85 void OI_MemSet(void *Block, OI_UINT8 Val, OI_UINT32 Size);
86 
87 
88 /*
89  * OI_MemZero
90  *
91  * Sets all bytes in a block of memory to zero
92  */
93 void OI_MemZero(void *Block, OI_UINT32 Size);
94 
95 
96 /*
97  * OI_MemCmp
98  *
99  * Compare two blocks of memory
100  *
101  * Returns:
102  *        0, if s1 == s2
103  *      < 0, if s1 < s2
104  *      > 0, if s2 > s2
105  */
106 OI_INT OI_MemCmp(void const *s1, void const *s2, OI_UINT32 n);
107 
108 /*
109  * OI_Strcpy
110  *
111  * Copies the Null terminated string from pStr to pDest, and
112  * returns pDest.
113  */
114 
115 OI_CHAR *OI_Strcpy(OI_CHAR *pDest,
116                    OI_CHAR const *pStr);
117 
118 /*
119  * OI_Strcat
120  *
121  * Concatonates the pStr string to the end of pDest, and
122  * returns pDest.
123  */
124 
125 OI_CHAR *OI_Strcat(OI_CHAR *pDest,
126                    OI_CHAR const *pStr) ;
127 
128 /*
129  * OI_StrLen
130  *
131  * Calculates the number of OI_CHARs in pStr (not including
132  * the Null terminator) and returns the value.
133  */
134 OI_UINT OI_StrLen(OI_CHAR const *pStr) ;
135 
136 /*
137  * OI_Strcmp
138  *
139  * Compares two Null terminated strings
140  *
141  * Returns:
142  *        0, if s1 == s2
143  *      < 0, if s1 < s2
144  *      > 0, if s2 > s2
145  */
146 OI_INT OI_Strcmp(OI_CHAR const *s1,
147                  OI_CHAR const *s2);
148 
149 /*
150  * OI_Strncmp
151  *
152  * Compares the first "len" OI_CHARs of strings s1 and s2.
153  *
154  * Returns:
155  *        0, if s1 == s2
156  *      < 0, if s1 < s2
157  *      > 0, if s2 > s2
158  */
159 OI_INT OI_Strncmp(OI_CHAR const *s1,
160                   OI_CHAR const *s2,
161                   OI_UINT32      len);
162 
163 
164 #endif /* USE_NATIVE_MEMCPY */
165 
166 /*
167  * OI_StrcmpInsensitive
168  *
169  * Compares two Null terminated strings, treating
170  * the Upper and Lower case of 'A' through 'Z' as
171  * equivilent.
172  *
173  * Returns:
174  *        0, if s1 == s2
175  *      < 0, if s1 < s2
176  *      > 0, if s2 > s2
177  */
178 OI_INT OI_StrcmpInsensitive(OI_CHAR const *s1,
179                             OI_CHAR const *s2);
180 
181 /*
182  * OI_StrncmpInsensitive
183  *
184  * Compares the first "len" OI_CHARs of strings s1 and s2,
185  * treating the Upper and Lower case of 'A' through 'Z' as
186  * equivilent.
187  *
188  *
189  * Returns:
190  *        0, if s1 == s2
191  *      < 0, if s1 < s2
192  *      > 0, if s2 > s2
193  */
194 OI_INT OI_StrncmpInsensitive(OI_CHAR const *s1,
195                              OI_CHAR const *s2,
196                              OI_UINT        len);
197 
198 
199 
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 /** @} */
205 
206 /*****************************************************************************/
207 #endif /* OI_STRING_H */
208