summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-07-07 15:20:29 +0800
committerHerbert Xu <herbert@gondor.apana.org.au>2011-07-07 16:41:14 +0800
commit4f9c19f9ba8dc756e732e0f17c1a2b2433eae467 (patch)
treef8cef04eab98b39fb3d3f618717e536f0795ef51
parent[MAN] Remove spurious space in descriptions of PS1, PS2, PS4 (diff)
downloaddash-4f9c19f9ba8dc756e732e0f17c1a2b2433eae467.tar.gz
dash-4f9c19f9ba8dc756e732e0f17c1a2b2433eae467.zip
[OUTPUT] Make outc an inline function
As "gcc -pedantic" warns, ISO C forbids conditional expressions with
only one void side.  So the (needslow ?  slowpath() : fastpath) code
for outc in the !USE_GLIBC_STDIO case might not be portable.

More importantly, it's hard to read.  Rip it out and replace it
with an inline function which should generate the same code.

Reported-by: Szabolcs Nagy <nsz@port70.net>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--ChangeLog4
-rw-r--r--src/output.h15
2 files changed, 17 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 216fc51..ade43e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
 
 	* Optimize dash -c "command" to avoid a fork.
 
+2011-05-22  Jonathan Nieder <jrnieder@gmail.com>
+
+	* Make outc an inline function.
+
 2011-05-02  Kalle Olavi Niemitalo <kon@iki.fi>
 
 	* Remove spurious space in descriptions of PS1, PS2, PS4.
diff --git a/src/output.h b/src/output.h
index d123301..f853e9d 100644
--- a/src/output.h
+++ b/src/output.h
@@ -97,10 +97,21 @@ freestdout()
 #define OUTPUT_ERR 01		/* error occurred on output */
 
 #ifdef USE_GLIBC_STDIO
-#define outc(c, o)	putc((c), (o)->stream)
+static inline void outc(int ch, struct output *file)
+{
+	putc(ch, file->stream);
+}
 #define doformat(d, f, a)	vfprintf((d)->stream, (f), (a))
 #else
-#define outc(c, file)	((file)->nextc == (file)->end ? outcslow((c), (file)) : (*(file)->nextc = (c), (file)->nextc++))
+static inline void outc(int ch, struct output *file)
+{
+	if (file->nextc == file->end)
+		outcslow(ch, file);
+	else {
+		*file->nextc = ch;
+		file->nextc++;
+	}
+}
 #endif
 #define out1c(c)	outc((c), out1)
 #define out2c(c)	outcslow((c), out2)