Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | f7ae6806 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2009 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Simon Glass | f7ae6806 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __VSPRINTF_H |
| 8 | #define __VSPRINTF_H |
| 9 | |
Maxime Ripard | 9f6903f | 2016-07-05 10:26:36 +0200 | [diff] [blame] | 10 | #include <stdarg.h> |
Masahiro Yamada | 70ed993 | 2017-09-16 14:10:43 +0900 | [diff] [blame] | 11 | #include <linux/types.h> |
Maxime Ripard | 9f6903f | 2016-07-05 10:26:36 +0200 | [diff] [blame] | 12 | |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 13 | /** |
| 14 | * simple_strtoul - convert a string to an unsigned long |
| 15 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 16 | * @cp: The string to be converted |
| 17 | * @endp: Updated to point to the first character not converted |
| 18 | * @base: The number base to use (0 for the default) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 19 | * Return: value decoded from string (0 if invalid) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 20 | * |
| 21 | * Converts a string to an unsigned long. If there are invalid characters at |
| 22 | * the end these are ignored. In the worst case, if all characters are invalid, |
| 23 | * 0 is returned |
Simon Glass | f0722ed | 2021-07-24 09:03:31 -0600 | [diff] [blame] | 24 | * |
Simon Glass | 90877bb | 2021-07-24 09:03:38 -0600 | [diff] [blame] | 25 | * A hex prefix is supported (e.g. 0x123) regardless of the value of @base. |
| 26 | * If found, the base is set to hex (16). |
| 27 | * |
| 28 | * If @base is 0: |
| 29 | * - an octal '0' prefix (e.g. 0777) sets the base to octal (8). |
| 30 | * - otherwise the base defaults to decimal (10). |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 31 | */ |
Simon Glass | f7ae6806 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 32 | ulong simple_strtoul(const char *cp, char **endp, unsigned int base); |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 33 | |
| 34 | /** |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 35 | * hex_strtoul - convert a string in hex to an unsigned long |
| 36 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 37 | * @cp: The string to be converted |
| 38 | * @endp: Updated to point to the first character not converted |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 39 | * Return: value decoded from string (0 if invalid) |
Simon Glass | 3ff49ec | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 40 | * |
| 41 | * Converts a hex string to an unsigned long. If there are invalid characters at |
| 42 | * the end these are ignored. In the worst case, if all characters are invalid, |
| 43 | * 0 is returned |
| 44 | */ |
| 45 | unsigned long hextoul(const char *cp, char **endp); |
| 46 | |
| 47 | /** |
Heinrich Schuchardt | 7fac39a | 2024-11-03 23:42:20 +0100 | [diff] [blame] | 48 | * hex_strtoull - convert a string in hex to an unsigned long long |
| 49 | * |
| 50 | * @cp: The string to be converted |
| 51 | * @endp: Updated to point to the first character not converted |
| 52 | * Return: value decoded from string (0 if invalid) |
| 53 | * |
| 54 | * Converts a hex string to an unsigned long long. If there are invalid |
| 55 | * characters at the end these are ignored. In the worst case, if all characters |
| 56 | * are invalid, 0 is returned |
| 57 | */ |
| 58 | unsigned long long hextoull(const char *cp, char **endp); |
| 59 | |
| 60 | /** |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 61 | * dec_strtoul - convert a string in decimal to an unsigned long |
| 62 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 63 | * @cp: The string to be converted |
| 64 | * @endp: Updated to point to the first character not converted |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 65 | * Return: value decoded from string (0 if invalid) |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 66 | * |
| 67 | * Converts a decimal string to an unsigned long. If there are invalid |
| 68 | * characters at the end these are ignored. In the worst case, if all characters |
| 69 | * are invalid, 0 is returned |
| 70 | */ |
| 71 | unsigned long dectoul(const char *cp, char **endp); |
| 72 | |
| 73 | /** |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 74 | * strict_strtoul - convert a string to an unsigned long strictly |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 75 | * @cp: The string to be converted |
| 76 | * @base: The number base to use (0 for the default) |
| 77 | * @res: The converted result value |
| 78 | * Return: 0 if conversion is successful and `*res` is set to the converted |
| 79 | * value, otherwise it returns -EINVAL and `*res` is set to 0. |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 80 | * |
| 81 | * strict_strtoul converts a string to an unsigned long only if the |
| 82 | * string is really an unsigned long string, any string containing |
| 83 | * any invalid char at the tail will be rejected and -EINVAL is returned, |
| 84 | * only a newline char at the tail is acceptible because people generally |
| 85 | * change a module parameter in the following way: |
| 86 | * |
| 87 | * echo 1024 > /sys/module/e1000/parameters/copybreak |
| 88 | * |
| 89 | * echo will append a newline to the tail. |
| 90 | * |
Simon Glass | 90877bb | 2021-07-24 09:03:38 -0600 | [diff] [blame] | 91 | * A hex prefix is supported (e.g. 0x123) regardless of the value of @base. |
| 92 | * If found, the base is set to hex (16). |
| 93 | * |
| 94 | * If @base is 0: |
| 95 | * - an octal '0' prefix (e.g. 0777) sets the base to octal (8). |
| 96 | * - otherwise the base defaults to decimal (10). |
Simon Glass | f0722ed | 2021-07-24 09:03:31 -0600 | [diff] [blame] | 97 | * |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 98 | * Copied this function from Linux 2.6.38 commit ID: |
| 99 | * 521cb40b0c44418a4fd36dc633f575813d59a43d |
| 100 | * |
| 101 | */ |
Simon Glass | f7ae6806 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 102 | int strict_strtoul(const char *cp, unsigned int base, unsigned long *res); |
| 103 | unsigned long long simple_strtoull(const char *cp, char **endp, |
| 104 | unsigned int base); |
| 105 | long simple_strtol(const char *cp, char **endp, unsigned int base); |
Roland Gaudig | fd8b034 | 2021-07-23 12:29:18 +0000 | [diff] [blame] | 106 | long long simple_strtoll(const char *cp, char **endp, unsigned int base); |
Simon Glass | 509dbf9 | 2015-02-27 22:06:32 -0700 | [diff] [blame] | 107 | |
| 108 | /** |
Simon Glass | 4aaa460 | 2015-06-23 15:39:08 -0600 | [diff] [blame] | 109 | * trailing_strtol() - extract a trailing integer from a string |
| 110 | * |
| 111 | * Given a string this finds a trailing number on the string and returns it. |
| 112 | * For example, "abc123" would return 123. |
| 113 | * |
Simon Glass | 20888f3 | 2022-04-24 23:30:57 -0600 | [diff] [blame] | 114 | * Note that this does not handle a string without a prefix. See dectoul() for |
| 115 | * that case. |
| 116 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 117 | * @str: String to examine |
Simon Glass | e74efcd | 2022-04-24 23:30:55 -0600 | [diff] [blame] | 118 | * Return: trailing number if found, else -1 |
Simon Glass | 4aaa460 | 2015-06-23 15:39:08 -0600 | [diff] [blame] | 119 | */ |
| 120 | long trailing_strtol(const char *str); |
| 121 | |
| 122 | /** |
| 123 | * trailing_strtoln() - extract a trailing integer from a fixed-length string |
| 124 | * |
| 125 | * Given a fixed-length string this finds a trailing number on the string |
| 126 | * and returns it. For example, "abc123" would return 123. Only the |
| 127 | * characters between @str and @end - 1 are examined. If @end is NULL, it is |
| 128 | * set to str + strlen(str). |
| 129 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 130 | * @str: String to examine |
Simon Glass | 4aaa460 | 2015-06-23 15:39:08 -0600 | [diff] [blame] | 131 | * @end: Pointer to end of string to examine, or NULL to use the |
| 132 | * whole string |
Simon Glass | e74efcd | 2022-04-24 23:30:55 -0600 | [diff] [blame] | 133 | * Return: trailing number if found, else -1 |
Simon Glass | 4aaa460 | 2015-06-23 15:39:08 -0600 | [diff] [blame] | 134 | */ |
| 135 | long trailing_strtoln(const char *str, const char *end); |
| 136 | |
| 137 | /** |
Simon Glass | 4bf2fc1 | 2022-04-24 23:30:58 -0600 | [diff] [blame] | 138 | * trailing_strtoln_end() - extract trailing integer from a fixed-length string |
| 139 | * |
| 140 | * Given a fixed-length string this finds a trailing number on the string |
| 141 | * and returns it. For example, "abc123" would return 123. Only the |
| 142 | * characters between @str and @end - 1 are examined. If @end is NULL, it is |
| 143 | * set to str + strlen(str). |
| 144 | * |
| 145 | * @str: String to examine |
| 146 | * @end: Pointer to end of string to examine, or NULL to use the |
| 147 | * whole string |
| 148 | * @endp: If non-NULL, this is set to point to the character where the |
| 149 | * number starts, e.g. for "mmc0" this would be point to the '0'; if no |
| 150 | * trailing number is found, it is set to the end of the string |
| 151 | * Return: training number if found, else -1 |
| 152 | */ |
| 153 | long trailing_strtoln_end(const char *str, const char *end, char const **endp); |
| 154 | |
| 155 | /** |
Simon Glass | 509dbf9 | 2015-02-27 22:06:32 -0700 | [diff] [blame] | 156 | * panic() - Print a message and reset/hang |
| 157 | * |
| 158 | * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is |
Vagrant Cascadian | 259b1fb | 2016-10-23 20:45:19 -0700 | [diff] [blame] | 159 | * defined, then it will hang instead of resetting. |
Simon Glass | 509dbf9 | 2015-02-27 22:06:32 -0700 | [diff] [blame] | 160 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 161 | * @fmt: printf() format string for message, which should not include |
Simon Glass | 509dbf9 | 2015-02-27 22:06:32 -0700 | [diff] [blame] | 162 | * \n, followed by arguments |
| 163 | */ |
Simon Glass | f7ae6806 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 164 | void panic(const char *fmt, ...) |
| 165 | __attribute__ ((format (__printf__, 1, 2), noreturn)); |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 166 | |
| 167 | /** |
Simon Glass | 509dbf9 | 2015-02-27 22:06:32 -0700 | [diff] [blame] | 168 | * panic_str() - Print a message and reset/hang |
| 169 | * |
| 170 | * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is |
Vagrant Cascadian | 259b1fb | 2016-10-23 20:45:19 -0700 | [diff] [blame] | 171 | * defined, then it will hang instead of resetting. |
Simon Glass | 509dbf9 | 2015-02-27 22:06:32 -0700 | [diff] [blame] | 172 | * |
| 173 | * This function can be used instead of panic() when your board does not |
| 174 | * already use printf(), * to keep code size small. |
| 175 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 176 | * @str: string to display, which should not include \n |
Simon Glass | 509dbf9 | 2015-02-27 22:06:32 -0700 | [diff] [blame] | 177 | */ |
| 178 | void panic_str(const char *str) __attribute__ ((noreturn)); |
| 179 | |
| 180 | /** |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 181 | * Format a string and place it in a buffer |
| 182 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 183 | * @buf: The buffer to place the result into |
| 184 | * @fmt: The format string to use |
| 185 | * @...: Arguments for the format string |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 186 | * |
| 187 | * The function returns the number of characters written |
| 188 | * into @buf. |
| 189 | * |
| 190 | * See the vsprintf() documentation for format string extensions over C99. |
| 191 | */ |
Simon Glass | f7ae6806 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 192 | int sprintf(char *buf, const char *fmt, ...) |
| 193 | __attribute__ ((format (__printf__, 2, 3))); |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * Format a string and place it in a buffer (va_list version) |
| 197 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 198 | * @buf: The buffer to place the result into |
| 199 | * @fmt: The format string to use |
| 200 | * @args: Arguments for the format string |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 201 | * Return: the number of characters which have been written into |
Heinrich Schuchardt | 2066253 | 2017-09-06 17:55:13 +0200 | [diff] [blame] | 202 | * the @buf not including the trailing '\0'. |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 203 | * |
| 204 | * If you're not already dealing with a va_list consider using scnprintf(). |
| 205 | * |
| 206 | * See the vsprintf() documentation for format string extensions over C99. |
| 207 | */ |
Simon Glass | f7ae6806 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 208 | int vsprintf(char *buf, const char *fmt, va_list args); |
Simon Glass | 978739d | 2021-10-14 12:48:06 -0600 | [diff] [blame] | 209 | |
| 210 | /** |
| 211 | * simple_itoa() - convert an unsigned integer to a string |
| 212 | * |
| 213 | * This returns a static string containing the decimal representation of the |
Simon Glass | 1f46718 | 2021-10-14 12:48:07 -0600 | [diff] [blame] | 214 | * given value. The returned value may be overwritten by other calls to other |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 215 | * simple... functions, so should be used immediately |
Simon Glass | 978739d | 2021-10-14 12:48:06 -0600 | [diff] [blame] | 216 | * |
| 217 | * @val: Value to convert |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 218 | * Return: string containing the decimal representation of @val |
Simon Glass | 978739d | 2021-10-14 12:48:06 -0600 | [diff] [blame] | 219 | */ |
| 220 | char *simple_itoa(ulong val); |
Simon Glass | f7ae6806 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 221 | |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 222 | /** |
Simon Glass | 1f46718 | 2021-10-14 12:48:07 -0600 | [diff] [blame] | 223 | * simple_xtoa() - convert an unsigned integer to a hex string |
| 224 | * |
| 225 | * This returns a static string containing the hexadecimal representation of the |
| 226 | * given value. The returned value may be overwritten by other calls to other |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 227 | * simple... functions, so should be used immediately |
Simon Glass | 1f46718 | 2021-10-14 12:48:07 -0600 | [diff] [blame] | 228 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 229 | * @num: Value to convert |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 230 | * Return: string containing the hexecimal representation of @val |
Simon Glass | 1f46718 | 2021-10-14 12:48:07 -0600 | [diff] [blame] | 231 | */ |
| 232 | char *simple_xtoa(ulong num); |
| 233 | |
| 234 | /** |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 235 | * Format a string and place it in a buffer |
| 236 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 237 | * @buf: The buffer to place the result into |
| 238 | * @size: The size of the buffer, including the trailing null space |
| 239 | * @fmt: The format string to use |
| 240 | * @...: Arguments for the format string |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 241 | * |
| 242 | * The return value is the number of characters written into @buf not including |
| 243 | * the trailing '\0'. If @size is == 0 the function returns 0. |
| 244 | * |
| 245 | * See the vsprintf() documentation for format string extensions over C99. |
| 246 | */ |
Sonny Rao | cd55bde | 2011-11-02 09:52:08 +0000 | [diff] [blame] | 247 | int scnprintf(char *buf, size_t size, const char *fmt, ...) |
| 248 | __attribute__ ((format (__printf__, 3, 4))); |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 249 | |
| 250 | /** |
| 251 | * Format a string and place it in a buffer (base function) |
| 252 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 253 | * @buf: The buffer to place the result into |
| 254 | * @size: The size of the buffer, including the trailing null space |
| 255 | * @fmt: The format string to use |
| 256 | * @args: Arguments for the format string |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 257 | * Return: The number characters which would be generated for the given |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 258 | * input, excluding the trailing '\0', as per ISO C99. Note that fewer |
| 259 | * characters may be written if this number of characters is >= size. |
| 260 | * |
| 261 | * This function follows C99 vsnprintf, but has some extensions: |
| 262 | * %pS output the name of a text symbol |
| 263 | * %pF output the name of a function pointer |
| 264 | * %pR output the address range in a struct resource |
| 265 | * |
| 266 | * The function returns the number of characters which would be |
| 267 | * generated for the given input, excluding the trailing '\0', |
| 268 | * as per ISO C99. |
| 269 | * |
| 270 | * Call this function if you are already dealing with a va_list. |
| 271 | * You probably want snprintf() instead. |
| 272 | */ |
Sonny Rao | cd55bde | 2011-11-02 09:52:08 +0000 | [diff] [blame] | 273 | int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 274 | |
| 275 | /** |
| 276 | * Format a string and place it in a buffer (va_list version) |
| 277 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 278 | * @buf: The buffer to place the result into |
| 279 | * @size: The size of the buffer, including the trailing null space |
| 280 | * @fmt: The format string to use |
| 281 | * @args: Arguments for the format string |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 282 | * Return: the number of characters which have been written into |
Simon Glass | 71d4f18 | 2011-11-02 09:52:09 +0000 | [diff] [blame] | 283 | * the @buf not including the trailing '\0'. If @size is == 0 the function |
| 284 | * returns 0. |
| 285 | * |
| 286 | * If you're not already dealing with a va_list consider using scnprintf(). |
| 287 | * |
| 288 | * See the vsprintf() documentation for format string extensions over C99. |
| 289 | */ |
Sonny Rao | cd55bde | 2011-11-02 09:52:08 +0000 | [diff] [blame] | 290 | int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); |
Sonny Rao | cd55bde | 2011-11-02 09:52:08 +0000 | [diff] [blame] | 291 | |
Simon Glass | b09cfd8 | 2013-06-11 11:14:38 -0700 | [diff] [blame] | 292 | /** |
| 293 | * print_grouped_ull() - print a value with digits grouped by ',' |
| 294 | * |
| 295 | * This prints a value with grouped digits, like 12,345,678 to make it easier |
| 296 | * to read. |
| 297 | * |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 298 | * @int_val: Value to print |
| 299 | * @digits: Number of digiits to print |
Simon Glass | b09cfd8 | 2013-06-11 11:14:38 -0700 | [diff] [blame] | 300 | */ |
| 301 | void print_grouped_ull(unsigned long long int_val, int digits); |
| 302 | |
Heiko Schocher | 7e5a16c | 2015-04-27 07:42:05 +0200 | [diff] [blame] | 303 | bool str2off(const char *p, loff_t *num); |
| 304 | bool str2long(const char *p, ulong *num); |
Simon Glass | f5c208d | 2019-11-14 12:57:20 -0700 | [diff] [blame] | 305 | |
| 306 | /** |
| 307 | * strmhz() - Convert a value to a Hz string |
| 308 | * |
| 309 | * This creates a string indicating the number of MHz of a value. For example, |
| 310 | * 2700000 produces "2.7". |
| 311 | * @buf: Buffer to hold output string, which must be large enough |
| 312 | * @hz: Value to convert |
| 313 | */ |
| 314 | char *strmhz(char *buf, unsigned long hz); |
Simon Glass | 811a260 | 2020-04-08 08:32:56 -0600 | [diff] [blame] | 315 | |
| 316 | /** |
| 317 | * str_to_upper() - Convert a string to upper case |
| 318 | * |
| 319 | * This simply uses toupper() on each character of the string. |
| 320 | * |
| 321 | * @in: String to convert (must be large enough to hold the output string) |
| 322 | * @out: Buffer to put converted string |
| 323 | * @len: Number of bytes available in @out (SIZE_MAX for all) |
| 324 | */ |
| 325 | void str_to_upper(const char *in, char *out, size_t len); |
| 326 | |
Andrii Anisov | 6e29ac4 | 2020-08-06 12:42:52 +0300 | [diff] [blame] | 327 | /** |
Simon Glass | 6a9de55 | 2023-01-17 10:47:14 -0700 | [diff] [blame] | 328 | * str_to_list() - Convert a string to a list of string pointers |
| 329 | * |
| 330 | * Splits a string containing space-delimited substrings into a number of |
| 331 | * separate strings, e.g. "this is" becomes {"this", "is", NULL}. If @instr is |
| 332 | * empty then this returns just {NULL}. The string should have only a single |
| 333 | * space between items, with no leading or trailing spaces. |
| 334 | * |
| 335 | * @instr: String to process (this is alloced by this function) |
| 336 | * Returns: List of string pointers, terminated by NULL. Each entry points to |
| 337 | * a string. If @instr is empty, the list consists just of a single NULL entry. |
| 338 | * Note that the first entry points to the alloced string. |
| 339 | * Returns NULL if out of memory |
| 340 | */ |
| 341 | const char **str_to_list(const char *instr); |
| 342 | |
| 343 | /** |
| 344 | * str_free_list() - Free a string list |
| 345 | * |
| 346 | * @ptr: String list to free, as created by str_to_list(). This can also be |
| 347 | * NULL, in which case the function does nothing |
| 348 | */ |
| 349 | void str_free_list(const char **ptr); |
| 350 | |
| 351 | /** |
Samuel Dionne-Riel | de46493 | 2021-12-20 18:19:16 -0500 | [diff] [blame] | 352 | * vsscanf - Unformat a buffer into a list of arguments |
Simon Glass | b2c6f09 | 2022-04-24 23:30:56 -0600 | [diff] [blame] | 353 | * @inp: input buffer |
| 354 | * @fmt0: format of buffer |
| 355 | * @ap: arguments |
Samuel Dionne-Riel | de46493 | 2021-12-20 18:19:16 -0500 | [diff] [blame] | 356 | */ |
| 357 | int vsscanf(const char *inp, char const *fmt0, va_list ap); |
| 358 | |
| 359 | /** |
Andrii Anisov | 6e29ac4 | 2020-08-06 12:42:52 +0300 | [diff] [blame] | 360 | * sscanf - Unformat a buffer into a list of arguments |
| 361 | * @buf: input buffer |
| 362 | * @fmt: formatting of buffer |
| 363 | * @...: resulting arguments |
| 364 | */ |
| 365 | int sscanf(const char *buf, const char *fmt, ...); |
| 366 | |
Simon Glass | f7ae6806 | 2011-11-02 09:52:07 +0000 | [diff] [blame] | 367 | #endif |