Mistake on this page?
Report an issue in GitHub or email us
strconv.h
1 /*
2  * Copyright (c) 2018 ARM Limited. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  * Licensed under the Apache License, Version 2.0 (the License); you may
5  * not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef STRCONVERSION_H
17 #define STRCONVERSION_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include "ns_types.h"
24 
25 /** Convert hex string to binary array
26  * e.g.
27  * char str[] = {30, 31, 32, 33};
28  * uint8_t buffer[4];
29  * strtohex( buffer, str, 4 );
30  */
31 int8_t strtohex(uint8_t *out, const char *str, int8_t max_length);
32 
33 /** Convert space separated hex string (eg. "76 ab ff") to binary array.
34  */
35 int string_to_bytes(const char *str, uint8_t *buf, int bytes);
36 
37 /** Convert a colon/space separated hex string (eg. "76:ab:ff") to binary
38  * array (inplace) returning the number of the bytes in the array.
39  */
40 int hexstr_to_bytes_inplace(char *str);
41 
42 /** Convert hex array to string
43  */
44 int16_t hextostr(const uint8_t *buf, uint16_t buf_length, char *out, int16_t out_length, char delimiter);
45 /** Replace hex characters from string
46  * e.g.
47  * "hello\\n" -> "hello\n"
48  * "hello\\r" -> "hello\r"
49  * "val: \\10" -> "val: \x0a" //integer
50  * "val: \\x10" -> "val: \x10" //hex value
51  * @param str string that will be replaced
52  * @return length
53  */
54 int replace_hexdata(char *str);
55 /**
56  * check if array contains only visible characters
57  * = isalpha | isdigit
58  */
59 bool is_visible(uint8_t *buf, int len);
60 
61 /** Convert ipv6 address to string format
62  */
63 char *print_ipv6(const void *addr_ptr);
64 /** Convert ipv6 prefix to string format
65  */
66 char *print_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
67 /** Convert binary array to string format and return static results
68  */
69 char *print_array(const uint8_t *buf, uint16_t len);
70 /** The strdupl() function shall return a pointer to a new string,
71  * which is a duplicate of the string pointed to by s1. The returned pointer can be passed to free().
72  * A null pointer is returned if the new string cannot be created.
73  * strdupl are same than linux strdup, but this way we avoid to duplicate reference in linux
74  */
75 char *strdupl(const char *str);
76 /** The strdup() function returns a pointer to a new string which is a duplicate of the string.
77  * Memory for the new string is obtained with malloc(3), and can be freed with free(3).
78  * The strndup() function is similar, but only copies at most n bytes. If s is longer than n,
79  * only n bytes are copied, and a terminating null byte ('\0') is added.
80  */
81 char *strndupl(const char *s, int n);
82 /** strnlen - determine the length of a fixed-size string
83  * The strnlen() function returns the number of bytes in the string pointed to by s, excluding the terminating null bye ('\0'), but at most maxlen.
84  * In doing this, strnlen() looks only at the first maxlen bytes at s and never beyond s+maxlen.
85  * The strnlen() function returns strlen(s), if that is less than maxlen, or maxlen if there is no null byte ('\0')
86  * among the first maxlen bytes pointed to by s.
87  */
88 int strnlen_(const char *s, int n);
89 /** strnicmp compares a and b without sensitivity to case.
90  * All alphabetic characters in the two arguments a and b are converted to lowercase before the comparison.
91  */
92 int strnicmp_(char const *a, char const *b, int n);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 #endif
98 
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.