From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pavel Machek Date: Wed, 15 Oct 2014 11:42:00 +0200 Subject: [U-Boot] puts() and newlines (was Re: Discussion topics / issues) In-Reply-To: <20141015084012.GA20015@amd> References: <201410071445.50854.marex@denx.de> <20141010122229.B60DC38352B@gemini.denx.de> <5437E778.3050306@myspectrum.nl> <201410101626.41944.marex@denx.de> <543804AF.9050101@myspectrum.nl> <54384450.3000204@myspectrum.nl> <20141011150346.150C038352A@gemini.denx.de> <20141015084012.GA20015@amd> Message-ID: <20141015094200.GA26232@amd> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Wed 2014-10-15 10:40:12, 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 at 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? Next step is probably diff --git a/include/common.h b/include/common.h index d5020c8..95b2377 100644 --- a/include/common.h +++ b/include/common.h @@ -836,6 +836,9 @@ int tstc(void); /* stdout */ void putc(const char c); void puts(const char *s); +static inline void __puts(const char *s) { puts(s); } +static inline void putsnl(const char *s) { puts(s); putc('\n'); } + int printf(const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2))); int vprintf(const char *fmt, va_list args); Then run sed 's/puts(\(.*\)\\n")/putsnl(\1")/' `find . -name "*.[ch]"` ... to get existing users converted. Then we can convert the rest to to either __puts or putsnl, and finally get rid of putsnl and convert it back to puts. (Patch is >400KB, so I'll not post it here). Best regards, Pavel -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html