shithub: riscv

Download patch

ref: b4d13efc1e19d9ae0f78e2a018f8b994b036ac97
parent: c4fec93ab9d544a72b189a602103ebed48a9829e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Feb 25 15:14:08 EST 2014

csdial: avoid useless werrstr() call on success (thanks mischief)

--- a/sys/src/libc/9sys/dial.c
+++ b/sys/src/libc/9sys/dial.c
@@ -99,19 +99,20 @@
 	 *  loop through each address from the connection server till
 	 *  we get one that works.
 	 */
-	*besterr = 0;
 	rv = -1;
+	*err = 0;
+	*besterr = 0;
 	seek(fd, 0, 0);
 	while((n = read(fd, buf, sizeof(buf) - 1)) > 0){
 		buf[n] = 0;
 		p = strchr(buf, ' ');
-		if(p == 0)
+		if(p == nil)
 			continue;
 		*p++ = 0;
 		rv = call(buf, p, ds);
 		if(rv >= 0)
 			break;
-		err[0] = '\0';
+		*err = 0;
 		errstr(err, sizeof err);
 		if(strstr(err, "does not exist") == 0)
 			strcpy(besterr, err);
@@ -118,10 +119,10 @@
 	}
 	close(fd);
 
-	if(rv < 0 && *besterr)
-		werrstr("%s", besterr);
-	else
-		werrstr("%s", err);
+	/* restore errstr if any */
+	if(rv < 0 && *err)
+		errstr(*besterr ? besterr : err, sizeof err);
+
 	return rv;
 }