blob: 2ac41d1923069bcda08fd5cba4bb8067899a3f32 [file] [log] [blame]
Simon Glassf7ae68062011-11-02 09:52:07 +00001/*
2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Simon Glassf7ae68062011-11-02 09:52:07 +00006 */
7
8#ifndef __VSPRINTF_H
9#define __VSPRINTF_H
10
11ulong simple_strtoul(const char *cp, char **endp, unsigned int base);
Simon Glass71d4f182011-11-02 09:52:09 +000012
13/**
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.
20 *
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:
26 *
27 * echo 1024 > /sys/module/e1000/parameters/copybreak
28 *
29 * echo will append a newline to the tail.
30 *
31 * simple_strtoul just ignores the successive invalid characters and
32 * return the converted value of prefix part of the string.
33 *
34 * Copied this function from Linux 2.6.38 commit ID:
35 * 521cb40b0c44418a4fd36dc633f575813d59a43d
36 *
37 */
Simon Glassf7ae68062011-11-02 09:52:07 +000038int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
39unsigned long long simple_strtoull(const char *cp, char **endp,
40 unsigned int base);
41long simple_strtol(const char *cp, char **endp, unsigned int base);
42void panic(const char *fmt, ...)
43 __attribute__ ((format (__printf__, 1, 2), noreturn));
Simon Glass71d4f182011-11-02 09:52:09 +000044
45/**
46 * Format a string and place it in a buffer
47 *
48 * @param buf The buffer to place the result into
49 * @param fmt The format string to use
50 * @param ... Arguments for the format string
51 *
52 * The function returns the number of characters written
53 * into @buf.
54 *
55 * See the vsprintf() documentation for format string extensions over C99.
56 */
Simon Glassf7ae68062011-11-02 09:52:07 +000057int sprintf(char *buf, const char *fmt, ...)
58 __attribute__ ((format (__printf__, 2, 3)));
Simon Glass71d4f182011-11-02 09:52:09 +000059
60/**
61 * Format a string and place it in a buffer (va_list version)
62 *
63 * @param buf The buffer to place the result into
64 * @param size The size of the buffer, including the trailing null space
65 * @param fmt The format string to use
66 * @param args Arguments for the format string
67 * @return the number of characters which have been written into
68 * the @buf not including the trailing '\0'. If @size is == 0 the function
69 * returns 0.
70 *
71 * If you're not already dealing with a va_list consider using scnprintf().
72 *
73 * See the vsprintf() documentation for format string extensions over C99.
74 */
Simon Glassf7ae68062011-11-02 09:52:07 +000075int vsprintf(char *buf, const char *fmt, va_list args);
76char *simple_itoa(ulong i);
77
Sonny Raocd55bde2011-11-02 09:52:08 +000078#ifdef CONFIG_SYS_VSNPRINTF
Simon Glass71d4f182011-11-02 09:52:09 +000079/**
80 * Format a string and place it in a buffer
81 *
82 * @param buf The buffer to place the result into
83 * @param size The size of the buffer, including the trailing null space
84 * @param fmt The format string to use
85 * @param ... Arguments for the format string
86 * @return the number of characters which would be
87 * generated for the given input, excluding the trailing null,
88 * as per ISO C99. If the return is greater than or equal to
89 * @size, the resulting string is truncated.
90 *
91 * See the vsprintf() documentation for format string extensions over C99.
92 */
Sonny Raocd55bde2011-11-02 09:52:08 +000093int snprintf(char *buf, size_t size, const char *fmt, ...)
94 __attribute__ ((format (__printf__, 3, 4)));
Simon Glass71d4f182011-11-02 09:52:09 +000095
96/**
97 * Format a string and place it in a buffer
98 *
99 * @param buf The buffer to place the result into
100 * @param size The size of the buffer, including the trailing null space
101 * @param fmt The format string to use
102 * @param ... Arguments for the format string
103 *
104 * The return value is the number of characters written into @buf not including
105 * the trailing '\0'. If @size is == 0 the function returns 0.
106 *
107 * See the vsprintf() documentation for format string extensions over C99.
108 */
Sonny Raocd55bde2011-11-02 09:52:08 +0000109int scnprintf(char *buf, size_t size, const char *fmt, ...)
110 __attribute__ ((format (__printf__, 3, 4)));
Simon Glass71d4f182011-11-02 09:52:09 +0000111
112/**
113 * Format a string and place it in a buffer (base function)
114 *
115 * @param buf The buffer to place the result into
116 * @param size The size of the buffer, including the trailing null space
117 * @param fmt The format string to use
118 * @param args Arguments for the format string
119 * @return The number characters which would be generated for the given
120 * input, excluding the trailing '\0', as per ISO C99. Note that fewer
121 * characters may be written if this number of characters is >= size.
122 *
123 * This function follows C99 vsnprintf, but has some extensions:
124 * %pS output the name of a text symbol
125 * %pF output the name of a function pointer
126 * %pR output the address range in a struct resource
127 *
128 * The function returns the number of characters which would be
129 * generated for the given input, excluding the trailing '\0',
130 * as per ISO C99.
131 *
132 * Call this function if you are already dealing with a va_list.
133 * You probably want snprintf() instead.
134 */
Sonny Raocd55bde2011-11-02 09:52:08 +0000135int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
Simon Glass71d4f182011-11-02 09:52:09 +0000136
137/**
138 * Format a string and place it in a buffer (va_list version)
139 *
140 * @param buf The buffer to place the result into
141 * @param size The size of the buffer, including the trailing null space
142 * @param fmt The format string to use
143 * @param args Arguments for the format string
144 * @return the number of characters which have been written into
145 * the @buf not including the trailing '\0'. If @size is == 0 the function
146 * returns 0.
147 *
148 * If you're not already dealing with a va_list consider using scnprintf().
149 *
150 * See the vsprintf() documentation for format string extensions over C99.
151 */
Sonny Raocd55bde2011-11-02 09:52:08 +0000152int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
153#else
154/*
155 * Use macros to silently drop the size parameter. Note that the 'cn'
156 * versions are the same as the 'n' versions since the functions assume
157 * there is always enough buffer space when !CONFIG_SYS_VSNPRINTF
158 */
159#define snprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args)
160#define scnprintf(buf, size, fmt, args...) sprintf(buf, fmt, ##args)
161#define vsnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args)
162#define vscnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args)
163#endif /* CONFIG_SYS_VSNPRINTF */
164
Simon Glassb09cfd82013-06-11 11:14:38 -0700165/**
166 * print_grouped_ull() - print a value with digits grouped by ','
167 *
168 * This prints a value with grouped digits, like 12,345,678 to make it easier
169 * to read.
170 *
171 * @val: Value to print
172 * @digits: Number of digiits to print
173 */
174void print_grouped_ull(unsigned long long int_val, int digits);
175
Simon Glassf7ae68062011-11-02 09:52:07 +0000176#endif