shithub: qk1

Download patch

ref: a2bf5224f6a466910d1cd308e4c173dc50456d30
parent: e2e4c5b3848a7fe20a3fed5a5dda4d2cab0d129c
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Feb 2 23:04:47 EST 2024

fs: don't dup, reopen pak instead

--- a/fs.c
+++ b/fs.c
@@ -25,7 +25,6 @@
 };
 struct Pak{
 	char f[Nfspath];
-	FILE *bf;
 	Lump *l;
 	Lump *e;
 };
@@ -337,11 +336,6 @@
 static void
 closelmp(FILE *bf)
 {
-	Paklist *pl;
-
-	for(pl=pkl; pl!=nil; pl=pl->pl)
-		if(pl->p && pl->p->bf == bf)
-			return;
 	fclose(bf);
 }
 
@@ -353,7 +347,6 @@
 	Paklist *pl;
 	Pak *p;
 	Lump *l;
-	int fd;
 
 	fs_lmpfrom = nil;
 	for(pl = pkl; pl != nil; pl = pl->pl){
@@ -370,12 +363,8 @@
 		for(l = p->l; l < p->e; l++){
 			if(strcmp(l->f, f) != 0)
 				continue;
-			if((fd = sys_dup(fileno(p->bf))) < 0)
+			if((bf = fopen(p->f, "rb")) == nil)
 				break;
-			if((bf = fdopen(fd, "rb")) == nil){
-				close(fd);
-				break;
-			}
 			fseek(bf, l->ofs, SEEK_SET);
 			if(len != nil)
 				*len = l->len;
@@ -855,7 +844,6 @@
 	l = Hunk_Alloc(nlmp * sizeof *l);
 	p = Hunk_Alloc(sizeof *p);
 	snprint(p->f, sizeof(p->f), "%s", f);
-	p->bf = bf;
 	p->l = l;
 	p->e = l + nlmp;
 	fseek(bf, ofs, SEEK_SET);
@@ -873,6 +861,7 @@
 	}
 	if(crcn != Npak0crc)
 		notid1 = 1;
+	fclose(bf);
 	return p;
 }
 
--- a/plan9/platform.h
+++ b/plan9/platform.h
@@ -44,8 +44,6 @@
 static double ln2c;
 #define exp2f(x) (exp((x) * (ln2c ? ln2c : (ln2c = log(2.0)))))
 
-#define sys_dup(d) dup((d), -1)
-
 int qctz(unsigned);
 
 float DotProduct(const float v1[3], const float v2[3]);
--- a/posix/platform.h
+++ b/posix/platform.h
@@ -59,8 +59,6 @@
 extern char lasterr[256];
 #define werrstr(fmt...) do{snprint(lasterr, sizeof(lasterr), fmt); }while(0)
 
-#define sys_dup(d) dup((d))
-
 char *seprint(char *, char *, char *, ...);
 
 #define DotProduct(x,y) DotProduct_((x),(y))
--- a/sys_macos.c
+++ b/sys_macos.c
@@ -23,13 +23,6 @@
 	return -1;
 }
 
-int
-dup(int a)
-{
-	USED(a);
-	return -1;
-}
-
 bool
 isdisabled(char *s)
 {