2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
11 ulong simple_strtoul(const char *cp, char **endp, unsigned int base);
14 * strict_strtoul - convert a string to an unsigned long strictly
15 * @param cp The string to be converted
16 * @param base The number base to use
17 * @param res The converted result value
18 * @return 0 if conversion is successful and *res is set to the converted
19 * value, otherwise it returns -EINVAL and *res is set to 0.
21 * strict_strtoul converts a string to an unsigned long only if the
22 * string is really an unsigned long string, any string containing
23 * any invalid char at the tail will be rejected and -EINVAL is returned,
24 * only a newline char at the tail is acceptible because people generally
25 * change a module parameter in the following way:
27 * echo 1024 > /sys/module/e1000/parameters/copybreak
29 * echo will append a newline to the tail.
31 * simple_strtoul just ignores the successive invalid characters and
32 * return the converted value of prefix part of the string.
34 * Copied this function from Linux 2.6.38 commit ID:
35 * 521cb40b0c44418a4fd36dc633f575813d59a43d
38 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
39 unsigned long long simple_strtoull(const char *cp, char **endp,
41 long simple_strtol(const char *cp, char **endp, unsigned int base);
44 * panic() - Print a message and reset/hang
46 * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is
47 * defined, then it will hang instead of reseting.
49 * @param fmt: printf() format string for message, which should not include
50 * \n, followed by arguments
52 void panic(const char *fmt, ...)
53 __attribute__ ((format (__printf__, 1, 2), noreturn));
56 * panic_str() - Print a message and reset/hang
58 * Prints a message on the console(s) and then resets. If CONFIG_PANIC_HANG is
59 * defined, then it will hang instead of reseting.
61 * This function can be used instead of panic() when your board does not
62 * already use printf(), * to keep code size small.
64 * @param fmt: string to display, which should not include \n
66 void panic_str(const char *str) __attribute__ ((noreturn));
69 * Format a string and place it in a buffer
71 * @param buf The buffer to place the result into
72 * @param fmt The format string to use
73 * @param ... Arguments for the format string
75 * The function returns the number of characters written
78 * See the vsprintf() documentation for format string extensions over C99.
80 int sprintf(char *buf, const char *fmt, ...)
81 __attribute__ ((format (__printf__, 2, 3)));
84 * Format a string and place it in a buffer (va_list version)
86 * @param buf The buffer to place the result into
87 * @param size The size of the buffer, including the trailing null space
88 * @param fmt The format string to use
89 * @param args Arguments for the format string
90 * @return the number of characters which have been written into
91 * the @buf not including the trailing '\0'. If @size is == 0 the function
94 * If you're not already dealing with a va_list consider using scnprintf().
96 * See the vsprintf() documentation for format string extensions over C99.
98 int vsprintf(char *buf, const char *fmt, va_list args);
99 char *simple_itoa(ulong i);
101 #ifdef CONFIG_SYS_VSNPRINTF
103 * Format a string and place it in a buffer
105 * @param buf The buffer to place the result into
106 * @param size The size of the buffer, including the trailing null space
107 * @param fmt The format string to use
108 * @param ... Arguments for the format string
109 * @return the number of characters which would be
110 * generated for the given input, excluding the trailing null,
111 * as per ISO C99. If the return is greater than or equal to
112 * @size, the resulting string is truncated.
114 * See the vsprintf() documentation for format string extensions over C99.
116 int snprintf(char *buf, size_t size, const char *fmt, ...)
117 __attribute__ ((format (__printf__, 3, 4)));
120 * Format a string and place it in a buffer
122 * @param buf The buffer to place the result into
123 * @param size The size of the buffer, including the trailing null space
124 * @param fmt The format string to use
125 * @param ... Arguments for the format string
127 * The return value is the number of characters written into @buf not including
128 * the trailing '\0'. If @size is == 0 the function returns 0.
130 * See the vsprintf() documentation for format string extensions over C99.
132 int scnprintf(char *buf, size_t size, const char *fmt, ...)
133 __attribute__ ((format (__printf__, 3, 4)));
136 * Format a string and place it in a buffer (base function)
138 * @param buf The buffer to place the result into
139 * @param size The size of the buffer, including the trailing null space
140 * @param fmt The format string to use
141 * @param args Arguments for the format string
142 * @return The number characters which would be generated for the given
143 * input, excluding the trailing '\0', as per ISO C99. Note that fewer
144 * characters may be written if this number of characters is >= size.
146 * This function follows C99 vsnprintf, but has some extensions:
147 * %pS output the name of a text symbol
148 * %pF output the name of a function pointer
149 * %pR output the address range in a struct resource
151 * The function returns the number of characters which would be
152 * generated for the given input, excluding the trailing '\0',
155 * Call this function if you are already dealing with a va_list.
156 * You probably want snprintf() instead.
158 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
161 * Format a string and place it in a buffer (va_list version)
163 * @param buf The buffer to place the result into
164 * @param size The size of the buffer, including the trailing null space
165 * @param fmt The format string to use
166 * @param args Arguments for the format string
167 * @return the number of characters which have been written into
168 * the @buf not including the trailing '\0'. If @size is == 0 the function
171 * If you're not already dealing with a va_list consider using scnprintf().
173 * See the vsprintf() documentation for format string extensions over C99.
175 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
178 * Use macros to silently drop the size parameter. Note that the 'cn'
179 * versions are the same as the 'n' versions since the functions assume
180 * there is always enough buffer space when !CONFIG_SYS_VSNPRINTF
182 #define snprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args)
183 #define scnprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args)
184 #define vsnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args)
185 #define vscnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args)
186 #endif /* CONFIG_SYS_VSNPRINTF */
189 * print_grouped_ull() - print a value with digits grouped by ','
191 * This prints a value with grouped digits, like 12,345,678 to make it easier
194 * @val: Value to print
195 * @digits: Number of digiits to print
197 void print_grouped_ull(unsigned long long int_val, int digits);
199 bool str2off(const char *p, loff_t *num);
200 bool str2long(const char *p, ulong *num);