aboutsummaryrefslogtreecommitdiff
path: root/editors/nvi/patch-power-of-2
blob: 5f6aaffc0fe678e5aaf3b771cd70d89fb73ecb1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$NetBSD

Get rid of "page sizes must be a power-of-2" warning when loading a file.

--- common/exf.c.orig	2021-07-12 21:21:22.247541289 +0200
+++ common/exf.c
@@ -228,15 +228,17 @@ file_init(SCR *sp, FREF *frp, char *rcv_name, int flags)
 		/*
 		 * XXX
 		 * A seat of the pants calculation: try to keep the file in
-		 * 15 pages or less.  Don't use a page size larger than 10K
+		 * 15 pages or less.  Don't use a page size larger than 16K
 		 * (vi should have good locality) or smaller than 1K.
 		 */
-		psize = ((sb.st_size / 15) + 1023) / 1024;
-		if (psize > 10)
-			psize = 10;
-		if (psize == 0)
-			psize = 1;
-		psize *= 1024;
+		psize = (sb.st_size > 0) ? ffsl(sb.st_size - 1) + 1 : 0;
+		/* Do these very low limits make sense anymore? */
+		if (psize < 10)
+			psize = 10;  /* 1K */
+		if (psize > 14)
+			psize = 14;  /* 16K */
+		/* Keep page size on power of 2 boundary to keep db4 happy. */
+		psize = 1 << psize;
 
 		F_SET(ep, F_DEVSET);
 		ep->mdev = sb.st_dev;