shithub: riscv

Download patch

ref: 7327bd43c039d0ce2f4052afac04204718d9e69c
parent: 37567f07d18aa69824d41dca45ecdbd46e583f2a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun May 7 14:13:37 EDT 2017

kernel: fix namelenerror(), avoid memrchr() and make it static

make sure the loop terminates and doesnt get stuck at
name == aname. avoid memrchr() as it conflicts with
libc on unix (drawterm). declare namelenerror() as
static.

--- a/sys/src/9/port/chan.c
+++ b/sys/src/9/port/chan.c
@@ -1204,19 +1204,7 @@
 	}
 }
 
-void*
-memrchr(void *va, int c, long n)
-{
-	uchar *a, *e;
-
-	a = va;
-	for(e=a+n-1; e>a; e--)
-		if(*e == c)
-			return e;
-	return nil;
-}
-
-void
+static void
 namelenerror(char *aname, int len, char *err)
 {
 	char *ename, *name, *next;
@@ -1237,9 +1225,11 @@
 		next = ename;
 		do{
 			name = next;
-			next = memrchr(aname, '/', name-aname);
-			if(next == nil)
-				next = aname;
+			if(next == aname)
+				break;
+			while(next > aname)
+				if(*--next == '/')
+					break;
 			len = ename-next;
 		}while(len < ERRMAX/3 || len + errlen < 2*ERRMAX/3);