diff mbox

[U-Boot] puts() and newlines (was Re: Discussion topics / issues)

Message ID 20141015084012.GA20015@amd
State Not Applicable
Delegated to: Tom Rini
Headers show

Commit Message

Pavel Machek Oct. 15, 2014, 8:40 a.m. UTC
Hi!

> First, we have a compatibility problem here.  GCC assumes that puts()
> will add a newline character after the string; U-Boot puts() does NOT
> do this.  So the GCC auto-converted printf()s will all be wrong, as
> they are missing the newline. [1]

> [1] One might argue that this is a bug in U-Boot and should be fixed,
> but that is another topic.

I believe we should fix that, yes.

I did quick grep,

pavel@duo:~/wagabuibui/u-boot$ grep -ri puts . | wc -l
4287

and that is probably too much to change in one go. So what about this?

Best regards,
    	    	     	      	 	       	      	   	 Pavel
---

Introduce __puts() that puts strings without trailing newline. Plan is
to move the existing puts() users into __puts(), when no puts() users
are left, fix the puts() to add the newline, and move users that want
newline back to puts().

Signed-off-by: Pavel Machek <pavel@denx.de>

Comments

Tom Rini Oct. 20, 2014, 3:51 p.m. UTC | #1
On Wed, Oct 15, 2014 at 10:40:12AM +0200, Pavel Machek wrote:
> Hi!
> 
> > First, we have a compatibility problem here.  GCC assumes that puts()
> > will add a newline character after the string; U-Boot puts() does NOT
> > do this.  So the GCC auto-converted printf()s will all be wrong, as
> > they are missing the newline. [1]
> 
> > [1] One might argue that this is a bug in U-Boot and should be fixed,
> > but that is another topic.
> 
> I believe we should fix that, yes.
> 
> I did quick grep,
> 
> pavel@duo:~/wagabuibui/u-boot$ grep -ri puts . | wc -l
> 4287
> 
> and that is probably too much to change in one go. So what about this?

I'm thinking, now that we know that with $(CC) -ffreestanding printf is
not converted to puts, we should (a) globally change puts("no newline")
to printf (b) fix puts behavior to conform to standards and correct
puts("newline\n") to puts("newline").  And then let people use whatever
of the print functions they want, while we sort out making people use
debug(...) / error(...) more and come up with a clever output scheme
like we talked about in person.
diff mbox

Patch

--- a/include/common.h
+++ b/include/common.h
@@ -836,6 +836,8 @@  int	tstc(void);
 /* stdout */
 void	putc(const char c);
 void	puts(const char *s);
+static inline void __puts(const char *s) { puts(s); }
+
 int	printf(const char *fmt, ...)
 		__attribute__ ((format (__printf__, 1, 2)));
 int	vprintf(const char *fmt, va_list args);