Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / c_common / oic_string / include / oic_string.h
1 /******************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
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 OIC_STRING_H_
21 #define OIC_STRING_H_
22
23 #include <stddef.h>
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif // __cplusplus
28
29 /**
30  * Duplicates the source string and returns it.
31  *
32  * @note Caller needs to release this memory by calling OICFree().
33  *
34  * @param str Original valid string which needs to be duplicated.
35  *
36  * @return a pointer to the duplicated string
37  */
38 char *OICStrdup(const char *str);
39
40 /**
41  * Copies a C string into destination buffer.  Ensures that the destination
42  * is null terminated.
43  *
44  * @param dest Destination C buffer.
45  * @param destSize The allocated size of the destination parameter.
46  * @param source Source C string.
47  *
48  * @return
49  *      returns a pointer to the passed in 'dest' parameter
50  */
51 char* OICStrcpy(char* dest, size_t destSize, const char* source);
52
53 /**
54  * Appends a C string into a previously allocated and initialized C string in a buffer. dest
55  * parameter is guaranteed to be null-terminated.
56  *
57  * @param dest Destination C buffer containing initial string.
58  * @param destSize The allocated size of the destination parameter.
59  * @param source Source C string.
60  *
61  * @return
62  *      returns a pointer to the passed in 'dest' parameter
63  */
64 char* OICStrcat(char* dest, size_t destSize, const char* source);
65
66 /**
67  * Copies a partial C string into destination buffer.
68  * Ensures that the destination is null terminated.
69  *
70  * @param dest Destination C buffer.
71  * @param destSize The allocated size of the destination parameter.
72  * @param source Source C string.
73  * @param sourceLen maximum number of characters to copy.
74  *
75  * @return
76  *      returns a pointer to the passed in 'dest' parameter
77  */
78 char* OICStrcpyPartial(char* dest, size_t destSize, const char* source, size_t sourceLen);
79
80 /**
81  * Appends a C string into a previously allocated and initialized C string in a buffer. dest
82  * parameter is guaranteed to be null-terminated.
83  *
84  * @param dest Destination C buffer containing initial string.
85  * @param destSize The allocated size of the destination parameter.
86  * @param source Source C string.
87  * @param sourceLen maximum number of characters to append, not including null termination
88  *
89  * @return
90  *      returns a pointer to the passed in 'dest' parameter
91  */
92 char* OICStrcatPartial(char* dest, size_t destSize, const char* source, size_t sourceLen);
93
94 #ifdef __cplusplus
95 }
96 #endif // __cplusplus
97 #endif // OIC_STRING_H_