From 0596b07e2470d9e0444df5ea1a08997367202c18 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= <john@ankarstrom.se>
Date: Sun, 11 Jul 2021 13:04:33 +0200
Subject: Fix dirname function

---
 build.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/build.c b/build.c
index 621daa7..16b53e2 100644
--- a/build.c
+++ b/build.c
@@ -272,11 +272,14 @@ dirname(char *file)
 
 	if(!(dir = malloc(strlen(file)+1)))
 		err(1, "malloc");
+	dir[0] = 0;
 
 	for(i = strlen(file); i >= 0; i--)
-		if(file[i] == '/') break;
-	for(dir[i--] = 0; i >= 0; i--)
-		dir[i] = file[i];
+		if(file[i] == '/'){
+			for(dir[i--] = 0; i >= 0; i--)
+				dir[i] = file[i];
+			break;
+		}
 
 	return dir[0] ? dir : ".";
 }
-- 
cgit v1.2.3