File w3m-history-crossdev.patch of Package w3m

---
 history.c |   28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

Index: w3m-0.5.3/history.c
===================================================================
--- w3m-0.5.3.orig/history.c
+++ w3m-0.5.3/history.c
@@ -68,11 +68,13 @@ loadHistory(Hist *hist)
 void
 saveHistory(Hist *hist, size_t size)
 {
-    FILE *f;
+    FILE *f, *h = NULL;
     HistItem *item;
     char *tmpf;
 #define FNAMELEN 255
     char fname[FNAMELEN+1] = HISTORY_FILE;
+    char buf[4096];
+    size_t rs, ws, remaining;
 
     if (hist == NULL || hist->list == NULL)
 	return;
@@ -96,7 +98,29 @@ saveHistory(Hist *hist, size_t size)
 	strncat(fname, ".", FNAMELEN -6 - strlen(fname));
 	strncat(fname, Session, FNAMELEN -6 - strlen(fname));
     }
-    rename(tmpf, rcFile(fname));
+    if (rename(tmpf, rcFile(fname)) == -1 && errno == EXDEV) {
+	if ((f = fopen(tmpf, "r")) && (h = fopen(rcFile(fname), "w"))) {
+	    while (1) {
+		rs = fread(buf, 1, sizeof(buf), f);
+		if (rs == 0 || rs > sizeof(buf))
+			break;
+		ws = fwrite(buf, 1, rs, h);
+		if (ws == rs)
+			continue;
+		if (ws == 0 || ws > rs)
+			break;
+		remaining = rs - ws;
+		while (remaining > 0) {
+			ws = fwrite(buf + (rs - remaining), 1, remaining, h);
+			if (ws == 0 || ws > remaining)
+				break;
+			remaining -= ws;
+		}
+	    }
+	}
+	if (f) fclose(f);
+	if (h) fclose(h);
+    }
 }
 #endif				/* USE_HISTORY */