shithub: mq

Download patch

ref: 2febe85dcc87dfe6356cc851c5f0825bdfcefb91
parent: 5bfe2048d6464352c3dede863058f2d17b01b0eb
author: kvik <kvik@a-b.xyz>
date: Fri Sep 11 14:18:50 EDT 2020

mq-cat: rewrite ugly loop

--- a/src/mq-cat.c
+++ b/src/mq-cat.c
@@ -99,13 +99,13 @@
 		if((n = read(orderfd, name, sizeof(name)-1)) == 0)
 			break;
 		buf[n] = 0;
-		for(i = 0, s = streams; i < nstreams; i++, s++)
-			if(strcmp(s->name, name) == 0)
-			if(s->fd != -1){
-				if(rdwr(s->fd, 1) == 0)
+		for(i = 0, s = streams; i < nstreams; i++, s++){
+			if(strcmp(s->name, name) != 0 || s->fd == -1)
+				continue;
+			if(rdwr(s->fd, 1) == 0)
 					s->fd = -1;
-				break;
-			}
+			break;
+		}
 	}
 	exits(nil);
 }