[git commit branch/0.9.33] __stdio_WRITE: make code more readable. No code changes

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Mon Mar 26 11:21:50 UTC 2012


commit: http://git.uclibc.org/uClibc/commit/?id=06e3b3e5ff09ca7d295f9bf670cf77297f543cda
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/0.9.33

Pulled assignments out of ifs.
do {...} while (1); is a weird method of writing "loop forever",
thus rewrote it.
No code changes: objdump output is the same.

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 libc/stdio/_WRITE.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/libc/stdio/_WRITE.c b/libc/stdio/_WRITE.c
index 10b3b95..4011b71 100644
--- a/libc/stdio/_WRITE.c
+++ b/libc/stdio/_WRITE.c
@@ -42,13 +42,10 @@ size_t attribute_hidden __stdio_WRITE(register FILE *stream,
 
 	todo = bufsize;
 
-	do {
-		if (todo == 0) {		/* Done? */
-			__STDIO_STREAM_VALIDATE(stream);
-			return bufsize;
-		}
+	while (todo != 0) {
 		stodo = (todo <= SSIZE_MAX) ? todo : SSIZE_MAX;
-		if ((rv = __WRITE(stream, (char *) buf, stodo)) >= 0) {
+		rv = __WRITE(stream, (char *) buf, stodo);
+		if (rv >= 0) {
 #ifdef __UCLIBC_MJN3_ONLY__
 #warning TODO: Make custom stream write return check optional.
 #endif
@@ -69,17 +66,19 @@ size_t attribute_hidden __stdio_WRITE(register FILE *stream,
 			__STDIO_STREAM_SET_ERROR(stream);
 
 #ifdef __STDIO_BUFFERS
-			if ((stodo = __STDIO_STREAM_BUFFER_SIZE(stream)) != 0) {
+			stodo = __STDIO_STREAM_BUFFER_SIZE(stream);
+			if (stodo != 0) {
 				unsigned char *s;
 
 				if (stodo > todo) {
 					stodo = todo;
 				}
 
-				s  = stream->__bufstart;
+				s = stream->__bufstart;
 
 				do {
-					if (((*s = *buf) == '\n')
+					*s = *buf;
+					if ((*s == '\n')
 						&& __STDIO_STREAM_IS_LBF(stream)
 						) {
 						break;
@@ -94,8 +93,11 @@ size_t attribute_hidden __stdio_WRITE(register FILE *stream,
 			}
 #endif /* __STDIO_BUFFERS */
 
-			__STDIO_STREAM_VALIDATE(stream);
-			return bufsize - todo;
+			bufsize -= todo;
+			break;
 		}
-	} while (1);
+	}
+
+	__STDIO_STREAM_VALIDATE(stream);
+	return bufsize;
 }


More information about the uClibc-cvs mailing list