1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 3 #ifndef FLASHMAP_LIB_VALSTR_H__ 4 #define FLASHMAP_LIB_VALSTR_H__ 5 6 #include <inttypes.h> 7 8 /* value + string structure for common conversions */ 9 struct valstr { 10 uint32_t val; /* field value */ 11 const char *str; /* field description */ 12 }; 13 14 /* 15 * val2str_default - convert value to string 16 * 17 * @val: value to convert 18 * @vs: value-string data 19 * @def_str: default string to return if no matching value found 20 * 21 * returns pointer to string 22 * returns def_str if no matching value found 23 */ 24 const char *val2str_default(uint32_t val, const struct valstr *vs, 25 const char *def_str); 26 27 /* 28 * val2str - convert value to string 29 * 30 * @val: value to convert 31 * @vs: value-string data 32 * 33 * returns pointer to string 34 * returns pointer to "unknown" static string if not found 35 */ 36 const char *val2str(uint32_t val, const struct valstr *vs); 37 38 /* 39 * str2val - convert string to value 40 * 41 * @str: string to convert 42 * @vs: value-string data 43 * 44 * returns value for string 45 * returns value for last entry in value-string data if not found 46 */ 47 uint32_t str2val(const char *str, const struct valstr *vs); 48 49 #endif /* FLASHMAP_LIB_VALSTR_H__ */ 50