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>
19 #include <storage_class.h>
21 #if !defined(_MSC_VER)
23 * For all non microsoft cases, we need the following functions
27 /** @brief Copy from src_buf to dest_buf.
29 * @param[out] dest_buf. Destination buffer to copy to
30 * @param[in] dest_size. The size of the destination buffer in bytes
31 * @param[in] src_buf. The source buffer
32 * @param[in] src_size. The size of the source buffer in bytes
33 * @return 0 on success, error code on failure
34 * @return EINVAL on Invalid arguments
35 * @return ERANGE on Destination size too small
37 STORAGE_CLASS_INLINE int memcpy_s(
43 if ((src_buf == NULL) || (dest_buf == NULL)) {
44 /* Invalid arguments*/
48 if ((dest_size < src_size) || (src_size == 0)) {
49 /* Destination too small*/
53 memcpy(dest_buf, src_buf, src_size);
57 /** @brief Get the length of the string, excluding the null terminator
59 * @param[in] src_str. The source string
60 * @param[in] max_len. Look only for max_len bytes in the string
61 * @return Return the string length excluding null character
62 * @return Return max_len if no null character in the first max_len bytes
63 * @return Returns 0 if src_str is NULL
65 static size_t strnlen_s(
70 if (src_str == NULL) {
71 /* Invalid arguments*/
75 for (ix = 0; ix < max_len && src_str[ix] != '\0'; ix++)
78 /* On Error, it will return src_size == max_len*/
82 /** @brief Copy string from src_str to dest_str
84 * @param[out] dest_str. Destination buffer to copy to
85 * @param[in] dest_size. The size of the destination buffer in bytes
86 * @param[in] src_str. The source buffer
87 * @param[in] src_size. The size of the source buffer in bytes
88 * @return Returns 0 on success
89 * @return Returns EINVAL on invalid arguments
90 * @return Returns ERANGE on destination size too small
92 STORAGE_CLASS_INLINE int strncpy_s(
99 if (dest_str == NULL) {
100 /* Invalid arguments*/
104 if ((src_str == NULL) || (dest_size == 0)) {
105 /* Invalid arguments*/
110 len = strnlen_s(src_str, src_size);
112 if (len >= dest_size) {
113 /* Destination too small*/
118 /* dest_str is big enough for the len */
119 strncpy(dest_str, src_str, len);
120 dest_str[len] = '\0';
124 /** @brief Copy string from src_str to dest_str
126 * @param[out] dest_str. Destination buffer to copy to
127 * @param[in] dest_size. The size of the destination buffer in bytes
128 * @param[in] src_str. The source buffer
129 * @return Returns 0 on success
130 * @return Returns EINVAL on invalid arguments
131 * @return Returns ERANGE on destination size too small
133 STORAGE_CLASS_INLINE int strcpy_s(
139 if (dest_str == NULL) {
140 /* Invalid arguments*/
144 if ((src_str == NULL) || (dest_size == 0)) {
145 /* Invalid arguments*/
150 len = strnlen_s(src_str, dest_size);
152 if (len >= dest_size) {
153 /* Destination too small*/
158 /* dest_str is big enough for the len */
159 strncpy(dest_str, src_str, len);
160 dest_str[len] = '\0';
164 #endif /*!defined(_MSC_VER)*/
166 #endif /* __STRING_SUPPORT_H_INCLUDED__ */