struct printf_spec is a purely internal structure. Avoid excessive casts
when using the write function pointer just to make the compiler happy by
using the right types in the first place.
Change-Id: Ia4f3c79a5283cb76c8aa5f9d1eee758676303382
Signed-off-by: Mathias Krause <minipli@googlemail.com>
Reviewed-on: http://review.coreboot.org/850
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
/** Structure for specifying output methods for different printf clones. */
struct printf_spec {
/* Output function, returns count of printed characters or EOF. */
/** Structure for specifying output methods for different printf clones. */
struct printf_spec {
/* Output function, returns count of printed characters or EOF. */
- int (*write) (void *, size_t, void *);
+ int (*write) (const char *, size_t, void *);
/* Support data - output stream specification, its state, locks, ... */
void *data;
};
/* Support data - output stream specification, its state, locks, ... */
void *data;
};
static int printf_putnchars(const char *buf, size_t count,
struct printf_spec *ps)
{
static int printf_putnchars(const char *buf, size_t count,
struct printf_spec *ps)
{
- return ps->write((void *)buf, count, ps->data);
+ return ps->write(buf, count, ps->data);
*/
static int printf_putchar(int c, struct printf_spec *ps)
{
*/
static int printf_putchar(int c, struct printf_spec *ps)
{
- return ps->write((void *)&ch, 1, ps->data);
+ return ps->write(&ch, 1, ps->data);
*
* @param str Source string to print.
* @param count Size of source string.
*
* @param str Source string to print.
* @param count Size of source string.
- * @param data Structure with destination string, counter of used space
+ * @param _data Structure with destination string, counter of used space
* and total string size.
* @return Number of characters to print (not characters really printed!).
*/
* and total string size.
* @return Number of characters to print (not characters really printed!).
*/
-static int vsnprintf_write(const char *str, size_t count,
- struct vsnprintf_data *data)
+static int vsnprintf_write(const char *str, size_t count, void *_data)
+ struct vsnprintf_data *data = _data;
size_t i;
i = data->size - data->len;
size_t i;
i = data->size - data->len;
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
{
struct vsnprintf_data data = { size, 0, str };
int vsnprintf(char *str, size_t size, const char *fmt, va_list ap)
{
struct vsnprintf_data data = { size, 0, str };
- struct printf_spec ps =
- { (int (*)(void *, size_t, void *))vsnprintf_write, &data };
+ struct printf_spec ps = { vsnprintf_write, &data };
/* Print 0 at end of string - fix case that nothing will be printed. */
if (size > 0)
/* Print 0 at end of string - fix case that nothing will be printed. */
if (size > 0)
int vprintf(const char *fmt, va_list ap)
{
int vprintf(const char *fmt, va_list ap)
{
- struct printf_spec ps =
- { (int (*)(void *, size_t, void *))vprintf_write, NULL };
+ struct printf_spec ps = { vprintf_write, NULL };
return printf_core(fmt, &ps, ap);
}
return printf_core(fmt, &ps, ap);
}