2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
12 #include <linux/types.h>
14 ulong simple_strtoul(const char *cp, char **endp, unsigned int base);
17 * strict_strtoul - convert a string to an unsigned long strictly
18 * @param cp The string to be converted
19 * @param base The number base to use
20 * @param res The converted result value
21 * @return 0 if conversion is successful and *res is set to the converted
22 * value, otherwise it returns -EINVAL and *res is set to 0.
24 * strict_strtoul converts a string to an unsigned long only if the
25 * string is really an unsigned long string, any string containing
26 * any invalid char at the tail will be rejected and -EINVAL is returned,
27 * only a newline char at the tail is acceptible because people generally
28 * change a module parameter in the following way:
30 * echo 1024 > /sys/module/e1000/parameters/copybreak
32 * echo will append a newline to the tail.
34 * simple_strtoul just ignores the successive invalid characters and
35 * return the converted value of prefix part of the string.
37 * Copied this function from Linux 2.6.38 commit ID:
38 * 521cb40b0c44418a4fd36dc633f575813d59a43d
41 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
42 unsigned long long simple_strtoull(const char *cp, char **endp,
44 long simple_strtol(const char *cp, char **endp, unsigned int base);
47 * trailing_strtol() - extract a trailing integer from a string
49 * Given a string this finds a trailing number on the string and returns it.
50 * For example, "abc123" would return 123.
52 * @str: String to exxamine
53 * @return training number if found, else -1
55 long trailing_strtol(const char *str);
58 * trailing_strtoln() - extract a trailing integer from a fixed-length string
60 * Given a fixed-length string this finds a trailing number on the string
61 * and returns it. For example, "abc123" would return 123. Only the
62 * characters between @str and @end - 1 are examined. If @end is NULL, it is
63 * set to str + strlen(str).
65 * @str: String to exxamine
66 * @end: Pointer to end of string to examine, or NULL to use the
68 * @return training number if found, else -1
70 long trailing_strtoln(const char *str, const char *end);
73 * panic() - Print a message and reset/hang
75 * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is
76 * defined, then it will hang instead of resetting.
78 * @param fmt: printf() format string for message, which should not include
79 * \n, followed by arguments
81 void panic(const char *fmt, ...)
82 __attribute__ ((format (__printf__, 1, 2), noreturn));
85 * panic_str() - Print a message and reset/hang
87 * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is
88 * defined, then it will hang instead of resetting.
90 * This function can be used instead of panic() when your board does not
91 * already use printf(), * to keep code size small.
93 * @param fmt: string to display, which should not include \n
95 void panic_str(const char *str) __attribute__ ((noreturn));
98 * Format a string and place it in a buffer
100 * @param buf The buffer to place the result into
101 * @param fmt The format string to use
102 * @param ... Arguments for the format string
104 * The function returns the number of characters written
107 * See the vsprintf() documentation for format string extensions over C99.
109 int sprintf(char *buf, const char *fmt, ...)
110 __attribute__ ((format (__printf__, 2, 3)));
113 * Format a string and place it in a buffer (va_list version)
115 * @param buf The buffer to place the result into
116 * @param fmt The format string to use
117 * @param args Arguments for the format string
118 * @return the number of characters which have been written into
119 * the @buf not including the trailing '\0'.
121 * If you're not already dealing with a va_list consider using scnprintf().
123 * See the vsprintf() documentation for format string extensions over C99.
125 int vsprintf(char *buf, const char *fmt, va_list args);
126 char *simple_itoa(ulong i);
129 * Format a string and place it in a buffer
131 * @param buf The buffer to place the result into
132 * @param size The size of the buffer, including the trailing null space
133 * @param fmt The format string to use
134 * @param ... Arguments for the format string
135 * @return the number of characters which would be
136 * generated for the given input, excluding the trailing null,
137 * as per ISO C99. If the return is greater than or equal to
138 * @size, the resulting string is truncated.
140 * See the vsprintf() documentation for format string extensions over C99.
142 int snprintf(char *buf, size_t size, const char *fmt, ...)
143 __attribute__ ((format (__printf__, 3, 4)));
146 * Format a string and place it in a buffer
148 * @param buf The buffer to place the result into
149 * @param size The size of the buffer, including the trailing null space
150 * @param fmt The format string to use
151 * @param ... Arguments for the format string
153 * The return value is the number of characters written into @buf not including
154 * the trailing '\0'. If @size is == 0 the function returns 0.
156 * See the vsprintf() documentation for format string extensions over C99.
158 int scnprintf(char *buf, size_t size, const char *fmt, ...)
159 __attribute__ ((format (__printf__, 3, 4)));
162 * Format a string and place it in a buffer (base function)
164 * @param buf The buffer to place the result into
165 * @param size The size of the buffer, including the trailing null space
166 * @param fmt The format string to use
167 * @param args Arguments for the format string
168 * @return The number characters which would be generated for the given
169 * input, excluding the trailing '\0', as per ISO C99. Note that fewer
170 * characters may be written if this number of characters is >= size.
172 * This function follows C99 vsnprintf, but has some extensions:
173 * %pS output the name of a text symbol
174 * %pF output the name of a function pointer
175 * %pR output the address range in a struct resource
177 * The function returns the number of characters which would be
178 * generated for the given input, excluding the trailing '\0',
181 * Call this function if you are already dealing with a va_list.
182 * You probably want snprintf() instead.
184 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
187 * Format a string and place it in a buffer (va_list version)
189 * @param buf The buffer to place the result into
190 * @param size The size of the buffer, including the trailing null space
191 * @param fmt The format string to use
192 * @param args Arguments for the format string
193 * @return the number of characters which have been written into
194 * the @buf not including the trailing '\0'. If @size is == 0 the function
197 * If you're not already dealing with a va_list consider using scnprintf().
199 * See the vsprintf() documentation for format string extensions over C99.
201 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
204 * print_grouped_ull() - print a value with digits grouped by ','
206 * This prints a value with grouped digits, like 12,345,678 to make it easier
209 * @val: Value to print
210 * @digits: Number of digiits to print
212 void print_grouped_ull(unsigned long long int_val, int digits);
214 bool str2off(const char *p, loff_t *num);
215 bool str2long(const char *p, ulong *num);