mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "Loïc Minier" <loic.minier@linaro.org>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 3/5] fprintf() returns an int
Date: Fri, 14 Oct 2011 09:04:14 +0200	[thread overview]
Message-ID: <20111014070414.GW13898@pengutronix.de> (raw)
In-Reply-To: <1318543601-20819-4-git-send-email-loic.minier@linaro.org>

On Fri, Oct 14, 2011 at 12:06:39AM +0200, Loïc Minier wrote:
> For consistency, let fprintf return an int just like it's regular libc
> implementation and all the other printf variations barebox has.  This
> also fixes a warning on variable i being never read in the function.
> 
> Signed-off-by: Loïc Minier <loic.minier@linaro.org>
> ---
>  common/console.c |    4 +++-
>  include/stdio.h  |    2 +-
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/common/console.c b/common/console.c
> index 06e9c29..0d2a33b 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;
>  }
>  EXPORT_SYMBOL(fprintf);

fprintf is supposed to return the number of characters printed, that is
the return value of fputs. I know that fputs currently returns a wrong
value, but maybe we can fix this with the following:



From 51a7a01e90cc50c6b41bae60dcf70a50f0ff3486 Mon Sep 17 00:00:00 2001
From: Sascha Hauer <s.hauer@pengutronix.de>
Date: Fri, 14 Oct 2011 08:56:22 +0200
Subject: [PATCH] console: fix return values of puts functions

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/console.c |   14 ++++++++++----
 include/stdio.h  |    6 +++---
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/common/console.c b/common/console.c
index 0d2a33b..6216e88 100644
--- a/common/console.c
+++ b/common/console.c
@@ -292,24 +292,30 @@ int fputc(int fd, char c)
 }
 EXPORT_SYMBOL(fputc);
 
-void console_puts(unsigned int ch, const char *str)
+int console_puts(unsigned int ch, const char *str)
 {
 	const char *s = str;
+	int n = 0;
+
 	while (*s) {
-		if (*s == '\n')
+		if (*s == '\n') {
 			console_putc(ch, '\r');
+			n++;
+		}
 		console_putc(ch, *s);
+		n++;
 		s++;
 	}
+	return n;
 }
 EXPORT_SYMBOL(console_puts);
 
 int fputs(int fd, const char *s)
 {
 	if (fd == 1)
-		puts(s);
+		return puts(s);
 	else if (fd == 2)
-		eputs(s);
+		return eputs(s);
 	else
 		return write(fd, s, strlen(s));
 	return 0;
diff --git a/include/stdio.h b/include/stdio.h
index 0c68fa8..4901bc7 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -17,12 +17,12 @@ int	tstc(void);
 /* stdout */
 void	console_putc(unsigned int ch, const char c);
 int	getc(void);
-void	console_puts(unsigned int ch, const char *s);
+int	console_puts(unsigned int ch, const char *s);
 void	console_flush(void);
 
-static inline void puts(const char *s)
+static inline int puts(const char *s)
 {
-	console_puts(CONSOLE_STDOUT, s);
+	return console_puts(CONSOLE_STDOUT, s);
 }
 
 static inline void putchar(char c)
-- 
1.7.7

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2011-10-14  7:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-13 22:06 [RFC] Fix misc warnings when building sandbox on 64-bits Loïc Minier
2011-10-13 22:06 ` [PATCH 1/5] Only pass -P to cpp when generating ld scripts Loïc Minier
2011-10-13 22:06 ` [PATCH 2/5] Avoid warnings by using format(__printf__) Loïc Minier
2011-10-14  6:50   ` Sascha Hauer
2011-10-13 22:06 ` [PATCH 3/5] fprintf() returns an int Loïc Minier
2011-10-14  7:04   ` Sascha Hauer [this message]
2011-10-13 22:06 ` [PATCH 4/5] Use %p in format for pointers Loïc Minier
2011-10-14  7:18   ` Sascha Hauer
2011-10-14  7:22     ` Sascha Hauer
2011-10-13 22:06 ` [PATCH 5/5] Use size_t for memory offsets Loïc Minier
2011-10-14  7:20   ` Sascha Hauer
2011-10-14  8:59     ` Loïc Minier
2011-10-14 12:11       ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111014070414.GW13898@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=loic.minier@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox