shithub: riscv

Download patch

ref: d5d6724805fa7df9cb74d9b05a4eb3bf10d1997c
parent: 37e4ce0ea75ae0e9a71d773d7fc7f16fd3d64fe7
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Aug 3 18:08:10 EDT 2015

devenv: simplify envremove(), cleanup

--- a/sys/src/9/port/devenv.c
+++ b/sys/src/9/port/devenv.c
@@ -192,7 +192,7 @@
 envremove(Chan *c)
 {
 	Egrp *eg;
-	Evalue *e, *ee;
+	Evalue *e;
 
 	if(c->qid.type & QTDIR || !envwriteable(c))
 		error(Eperm);
@@ -199,20 +199,16 @@
 
 	eg = envgrp(c);
 	wlock(eg);
-	e = eg->ent;
-	for(ee = e + eg->nent; e < ee; e++){
-		if(e->qid.path == c->qid.path){
-			free(e->name);
-			free(e->value);
-			*e = ee[-1];
-			eg->nent--;
-			eg->vers++;
-			wunlock(eg);
-			return;
-		}
+	e = envlookup(eg, nil, c->qid.path);
+	if(e == nil){
+		wunlock(eg);
+		error(Enonexist);
 	}
+	free(e->name);
+	free(e->value);
+	*e = eg->ent[--eg->nent];
+	eg->vers++;
 	wunlock(eg);
-	error(Enonexist);
 }
 
 static void
@@ -416,7 +412,7 @@
 	/* determine size */
 	n = 0;
 	e = eg->ent;
-	for(ee = e+eg->nent; e<ee; e++)
+	for(ee = e + eg->nent; e < ee; e++)
 		n += strlen(e->name) + e->len + 2;
 
 	p = malloc(n + 1);