shithub: riscv

Download patch

ref: 32dfbc7c50873ea4167a7e5352e2fd29f6304d37
parent: 48b49361d8830d535e6dd3e696d58f856b2cd95f
author: cinap_lenrek <[email protected]>
date: Mon Nov 7 19:34:59 EST 2016

devcons: simplify putstrn0()

--- a/sys/src/9/port/devcons.c
+++ b/sys/src/9/port/devcons.c
@@ -114,10 +114,8 @@
 {
 	int m;
 	char *t;
+	int (*wq)(Queue*, void*, int);
 
-	if(!islo())
-		usewrite = 0;
-
 	/*
 	 *  how many different output devices do we need?
 	 */
@@ -132,12 +130,10 @@
 	 *  if there's a serial line being used as a console,
 	 *  put the message there.
 	 */
-	if(kprintoq != nil && !qisclosed(kprintoq)){
-		if(usewrite)
-			qwrite(kprintoq, str, n);
-		else
-			qiwrite(kprintoq, str, n);
-	}else if(screenputs != nil)
+	wq = usewrite && islo() ? qwrite : qiwrite;
+	if(kprintoq != nil && !qisclosed(kprintoq))
+		(*wq)(kprintoq, str, n);
+	else if(screenputs != nil)
 		screenputs(str, n);
 
 	if(serialoq == nil){
@@ -149,20 +145,12 @@
 		t = memchr(str, '\n', n);
 		if(t != nil) {
 			m = t-str;
-			if(usewrite){
-				qwrite(serialoq, str, m);
-				qwrite(serialoq, "\r\n", 2);
-			} else {
-				qiwrite(serialoq, str, m);
-				qiwrite(serialoq, "\r\n", 2);
-			}
+			(*wq)(serialoq, str, m);
+			(*wq)(serialoq, "\r\n", 2);
 			n -= m+1;
 			str = t+1;
 		} else {
-			if(usewrite)
-				qwrite(serialoq, str, n);
-			else
-				qiwrite(serialoq, str, n);
+			(*wq)(serialoq, str, n);
 			break;
 		}
 	}