1 /* SPDX-License-Identifier: BSD-3-Clause or GPL-2.0-only */
3 #ifndef FLASHMAP_LIB_KV_PAIR_H__
4 #define FLASHMAP_LIB_KV_PAIR_H__
10 /* key=value string pair list */
11 #define KV_PAIR_MAX_VALUE_LEN 1024
14 KV_STYLE_PAIR
, /* key1="value1" key2="value2" */
15 KV_STYLE_VALUE
, /* | value1 | value2 | */
16 KV_STYLE_LONG
, /* key1 | value1 */
26 extern enum kv_pair_style
kv_pair_get_style(void);
28 extern void kv_pair_set_style(enum kv_pair_style style
);
31 * kv_pair_new - create new key=value pair
33 * returns pointer to new key=value pair
34 * returns NULL to indicate error
36 extern struct kv_pair
*kv_pair_new(void);
39 * kv_pair_add - add new key=value pair to list
41 * @kv_list: key=value pair list
43 * @value: value string
45 * returns pointer to new key=value pair
46 * returns NULL to indicate error
48 extern struct kv_pair
*kv_pair_add(struct kv_pair
*kv_list
,
49 const char *key
, const char *value
);
52 * kv_pair_add_bool - add new boolean kvpair to list
54 * @kv_list: key=value pair list
58 * returns pointer to new key=value pair
59 * returns NULL to indicate error
61 extern struct kv_pair
*kv_pair_add_bool(struct kv_pair
*kv_list
,
62 const char *key
, int value
);
65 * kv_pair_fmt - add key=value pair based on printf format
66 * NOTE: uses variable argument list
68 * @kv_list: list of key=value pairs
70 * @format: printf-style format for value input
71 * @...: arguments to format
73 * returns pointer to new key=value pair
74 * returns NULL to indicate error
76 extern struct kv_pair
*kv_pair_fmt(struct kv_pair
*kv_list
,
77 const char *kv_key
, const char *format
, ...)
78 #if defined(_WIN32) || (_WIN64)
79 __attribute__((format(gnu_printf
, 3, 4)));
81 __attribute__((format(printf
, 3, 4)));
85 * kv_pair_free - clean a key=value pair list
87 * @kv_list: pointer to key=value list
89 extern void kv_pair_free(struct kv_pair
*kv_list
);
92 * kv_pair_print - print a key=value pair list
94 * @kv_list: pointer to key=value list
97 extern void kv_pair_print_to_file(FILE* fp
, struct kv_pair
*kv_list
,
98 enum kv_pair_style style
);
101 * kv_pair_print - print a key=value pair list to gsys output
103 * @kv_list: pointer to key=value list
105 extern void kv_pair_print(struct kv_pair
*kv_list
);
109 * kv_pair_get_value - return first value with key match
111 * @kv_list: pointer to key=value list
112 * @kv_key: key string
114 extern const char *kv_pair_get_value(struct kv_pair
*kv_list
,
118 * kv_pair_size - return number of kv pairs in the chain
120 * @kv_list: pointer to key=value list
122 extern int kv_pair_size(struct kv_pair
*kv_list
);
124 #endif /* FLASHMAP_LIB_KV_PAIR_H__ */