2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #ifndef __STRING_SUPPORT_H_INCLUDED__
16 #define __STRING_SUPPORT_H_INCLUDED__
17 #include <platform_support.h>
18 #include <type_support.h>
20 #if !defined(_MSC_VER)
22 * For all non microsoft cases, we need the following functions
26 /* @brief Copy from src_buf to dest_buf.
28 * @param[out] dest_buf. Destination buffer to copy to
29 * @param[in] dest_size. The size of the destination buffer in bytes
30 * @param[in] src_buf. The source buffer
31 * @param[in] src_size. The size of the source buffer in bytes
32 * @return 0 on success, error code on failure
33 * @return EINVAL on Invalid arguments
34 * @return ERANGE on Destination size too small
36 static inline int memcpy_s(
42 if ((src_buf == NULL) || (dest_buf == NULL)) {
43 /* Invalid arguments*/
47 if ((dest_size < src_size) || (src_size == 0)) {
48 /* Destination too small*/
52 memcpy(dest_buf, src_buf, src_size);
56 /* @brief Get the length of the string, excluding the null terminator
58 * @param[in] src_str. The source string
59 * @param[in] max_len. Look only for max_len bytes in the string
60 * @return Return the string length excluding null character
61 * @return Return max_len if no null character in the first max_len bytes
62 * @return Returns 0 if src_str is NULL
64 static size_t strnlen_s(
69 if (src_str == NULL) {
70 /* Invalid arguments*/
74 for (ix = 0; ix < max_len && src_str[ix] != '\0'; ix++)
77 /* On Error, it will return src_size == max_len*/
81 /* @brief Copy string from src_str to dest_str
83 * @param[out] dest_str. Destination buffer to copy to
84 * @param[in] dest_size. The size of the destination buffer in bytes
85 * @param[in] src_str. The source buffer
86 * @param[in] src_size. The size of the source buffer in bytes
87 * @return Returns 0 on success
88 * @return Returns EINVAL on invalid arguments
89 * @return Returns ERANGE on destination size too small
91 static inline int strncpy_s(
98 if (dest_str == NULL) {
99 /* Invalid arguments*/
103 if ((src_str == NULL) || (dest_size == 0)) {
104 /* Invalid arguments*/
109 len = strnlen_s(src_str, src_size);
111 if (len >= dest_size) {
112 /* Destination too small*/
117 /* dest_str is big enough for the len */
118 strncpy(dest_str, src_str, len);
119 dest_str[len] = '\0';
123 /* @brief Copy string from src_str to dest_str
125 * @param[out] dest_str. Destination buffer to copy to
126 * @param[in] dest_size. The size of the destination buffer in bytes
127 * @param[in] src_str. The source buffer
128 * @return Returns 0 on success
129 * @return Returns EINVAL on invalid arguments
130 * @return Returns ERANGE on destination size too small
132 static inline int strcpy_s(
138 if (dest_str == NULL) {
139 /* Invalid arguments*/
143 if ((src_str == NULL) || (dest_size == 0)) {
144 /* Invalid arguments*/
149 len = strnlen_s(src_str, dest_size);
151 if (len >= dest_size) {
152 /* Destination too small*/
157 /* dest_str is big enough for the len */
158 strncpy(dest_str, src_str, len);
159 dest_str[len] = '\0';
163 #endif /*!defined(_MSC_VER)*/
165 #endif /* __STRING_SUPPORT_H_INCLUDED__ */