[PATCH 1/4] Make fprintf return number of bytes written

Sascha Hauer s.hauer at pengutronix.de
Fri Nov 11 06:27:38 EST 2011


On Wed, Nov 09, 2011 at 07:39:54PM -0200, Lucas De Marchi wrote:
> Return number of bytes written, like its siblings function. This also
> removes the warning below on gcc >= 4.6.
> 
> common/console.c:333:7: warning: variable ‘i’ set but not used
> [-Wunused-but-set-variable]
> 
> Signed-off-by: Lucas De Marchi <lucas.demarchi at profusion.mobi>
> ---
>  common/console.c        |    4 +++-
>  common/console_simple.c |    4 +++-
>  include/stdio.h         |    2 +-
>  3 files changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/common/console.c b/common/console.c
> index 06e9c29..7f2810e 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -327,7 +327,7 @@ void console_flush(void)
>  }
>  EXPORT_SYMBOL(console_flush);
>  
> -void fprintf (int file, const char *fmt, ...)
> +int fprintf (int file, const char *fmt, ...)
>  {
>  	va_list args;
>  	uint i;
> @@ -343,6 +343,8 @@ void fprintf (int file, const char *fmt, ...)
>  
>  	/* Print the string */
>  	fputs (file, printbuffer);
> +
> +        return i;
>  }

I just applied another patch I suggested earlier which fixes the return
value of the various puts functions. With this I suggest returning the
return value of fputs here instead of a bogus 1.


>From 1856d45fbc2fa01415d97ea868d16ea7a974f66b Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer at pengutronix.de>
Date: Fri, 11 Nov 2011 12:25:53 +0100
Subject: [PATCH] fix fprintf prototype and return value

The puts functions now properly return the number of characters
written. With this we can also fix fprintf.
Also, remove never reached return in fputs.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/console.c |    5 ++---
 include/stdio.h  |    2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/common/console.c b/common/console.c
index e82934b..944dd07 100644
--- a/common/console.c
+++ b/common/console.c
@@ -318,7 +318,6 @@ int fputs(int fd, const char *s)
 		return eputs(s);
 	else
 		return write(fd, s, strlen(s));
-	return 0;
 }
 EXPORT_SYMBOL(fputs);
 
@@ -333,7 +332,7 @@ void console_flush(void)
 }
 EXPORT_SYMBOL(console_flush);
 
-void fprintf (int file, const char *fmt, ...)
+int fprintf(int file, const char *fmt, ...)
 {
 	va_list args;
 	uint i;
@@ -348,7 +347,7 @@ void fprintf (int file, const char *fmt, ...)
 	va_end (args);
 
 	/* Print the string */
-	fputs (file, printbuffer);
+	return fputs(file, printbuffer);
 }
 EXPORT_SYMBOL(fprintf);
 
diff --git a/include/stdio.h b/include/stdio.h
index bfaeb6c..4901bc7 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -54,7 +54,7 @@ int	vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 #define stderr		2
 #define MAX_FILES	128
 
-void	fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
+int	fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
 int	fputs(int file, const char *s);
 int	fputc(int file, const char c);
 int	ftstc(int file);
-- 
1.7.7.1

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list