1 /* 2 * Arm SCP/MCP Software 3 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef FWK_STRING_H 9 #define FWK_STRING_H 10 11 #include <fwk_attributes.h> 12 13 #include <stddef.h> 14 #include <stdlib.h> 15 #include <string.h> 16 17 /*! 18 * \addtogroup GroupLibFramework Framework 19 * \{ 20 */ 21 22 /*! 23 * \addtogroup GroupString Strings Management 24 * 25 * \brief Manipulation of strings and arrays. 26 * 27 * \details This interface extends the standard C library for strings and arrays 28 * manipulations to improve portability and provide a consistent set of 29 * checks. 30 * 31 * \{ 32 */ 33 34 /*! 35 * \brief Copies the value `ch` into each of the first `count` characters of the 36 * object pointed by dest. 37 * 38 * \details This is a wrapper of the memset() provided by the standard 39 * library. It behaves as the standard-library function but also checks on 40 * whether the returned `dest` is equal to the original dest. If not, the 41 * function traps. 42 * 43 * \details This should be used in place of memset() when the return value can 44 * be discarded. 45 * 46 * \param[in] dest Pointer to the object to fill 47 * \param[in] ch Value to be copied 48 * \param[in] count number of bytes to copy 49 */ 50 FWK_LEAF FWK_NOTHROW void fwk_str_memset(void *dest, int ch, size_t count); 51 52 /*! 53 * \brief Copies `count` characters from the object pointed to by `src` to the 54 * object pointed to by `dest`. 55 * 56 * \details This is a wrapper of the memcpy() provided by the standard 57 * library. It behaves as the standard-library function but also checks on 58 * whether the returned `dest` is equal to the original dest. If not, the 59 * function traps. 60 * 61 * \details This should be used in place of memcpy() when the return value can 62 * be discarded. 63 * 64 * \param[in] dest Pointer to the object to copy to 65 * \param[in] src Pointer to the object to copy from 66 * \param[in] count number of bytes to copy 67 */ 68 FWK_LEAF FWK_NOTHROW void fwk_str_memcpy( 69 void *dest, 70 const void *src, 71 size_t count); 72 73 /*! 74 * \brief Copies at most `count` characters from the object pointed to by `src` 75 * (including the terminating null character) to the object pointed to by 76 * `dest`. 77 * 78 * \details This is a wrapper of the strncpy() provided by the standard 79 * library. It behaves as the standard-library function but also checks on 80 * whether the returned `dest` is equal to the original dest. If not, the 81 * function traps. 82 * 83 * \details This should be used in place of strncpy() when the return value can 84 * be discarded. 85 * 86 * \param[in] dest Pointer to the object to copy to 87 * \param[in] src Pointer to the object to copy from 88 * \param[in] count number of bytes to copy 89 */ 90 FWK_LEAF FWK_NOTHROW void fwk_str_strncpy( 91 char *dest, 92 const char *src, 93 size_t count); 94 95 /*! 96 * \} 97 */ 98 99 /*! 100 * \} 101 */ 102 103 #endif /* FWK_STRING_H */ 104