diff -Paur --no-dereference -- nano.upstream/configure nano/configure
--- nano.upstream/configure
+++ nano/configure
@@ -41989,6 +41989,8 @@
   # Extract the first word of "${ac_tool_prefix}ncursesw5-config", so it can be a program name with args.
 set dummy ${ac_tool_prefix}ncursesw5-config; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+# PATCH: pkg-config must be used instead of the cross unsafe ncursesw5-config.
+ac_cv_prog_NCURSESW_CONFIG=false
 $as_echo_n "checking for $ac_word... " >&6; }
 if ${ac_cv_prog_NCURSESW_CONFIG+:} false; then :
   $as_echo_n "(cached) " >&6
diff -Paur --no-dereference -- nano.upstream/src/files.c nano/src/files.c
--- nano.upstream/src/files.c
+++ nano/src/files.c
@@ -1455,8 +1455,10 @@
 	if (env_dir != NULL)
 		tempdir = check_writable_directory(env_dir);
 
+#ifdef P_tmpdir
 	if (tempdir == NULL)
 		tempdir = check_writable_directory(P_tmpdir);
+#endif
 
 	if (tempdir == NULL)
 		tempdir = copy_of("/tmp/");
diff -Paur --no-dereference -- nano.upstream/src/nano.c nano/src/nano.c
--- nano.upstream/src/nano.c
+++ nano/src/nano.c
@@ -329,7 +329,7 @@
 
 	if (*filename == '\0') {
 		plainname = nmalloc(28);
-		sprintf(plainname, "nano.%u", getpid());
+		sprintf(plainname, "nano.%ji", (intmax_t)getpid());
 	} else
 		plainname = copy_of(filename);
 
@@ -2105,8 +2105,7 @@
 	}
 
 	/* Curses needs TERM; if it is unset, try falling back to a VT220. */
-	if (getenv("TERM") == NULL)
-		putenv("TERM=vt220");
+	setenv("TERM", "vt220", 0);
 
 	/* Enter into curses mode.  Abort if this fails. */
 	if (initscr() == NULL)
diff -Paur --no-dereference -- nano.upstream/src/rcfile.c nano/src/rcfile.c
--- nano.upstream/src/rcfile.c
+++ nano/src/rcfile.c
@@ -575,6 +575,11 @@
  * null-terminate it, and return a pointer to the succeeding text. */
 char *parse_next_regex(char *ptr)
 {
+	char* outptr = ptr;
+	int escaped = 0;
+	char c;
+	size_t bracket = 0;
+
 	char *starting_point = ptr;
 
 	if (*(ptr - 1) != '"') {
@@ -582,11 +587,28 @@
 		return NULL;
 	}
 
-	/* Continue until the end of the line, or until a double quote followed
-	 * by end-of-line or a blank. */
-	while (*ptr != '\0' && (*ptr != '"' ||
-						(ptr[1] != '\0' && !isblank((unsigned char)ptr[1]))))
+	/* PATCH: This fixes issues in the nanorc parser because the Sortix regcomp
+	          does not support \" and \' (just use " and ' instead). */
+	while ((c = *ptr)) {
+		if (!escaped && !bracket && c == '"' &&
+		    (!ptr[1] || isspace((unsigned char) ptr[1])) )
+			break;
+		if (escaped && c != '"' && c != '\'')
+			*outptr++ = '\\';
+		if (c == '\\' && !escaped && !bracket)
+			escaped = 1;
+		else if (c == '[' && !escaped) {
+			bracket++;
+			*outptr++ = c;
+		} else if (bracket && c == ']' && !escaped) {
+			bracket--;
+			*outptr++ = c;
+		} else {
+			*outptr++ = c;
+			escaped = 0;
+		}
 		ptr++;
+	}
 
 	if (*ptr == '\0') {
 		jot_error(N_("Regex strings must begin and end with a \" character"));
@@ -599,7 +621,8 @@
 	}
 
 	/* Null-terminate the regex and skip until the next non-blank. */
-	*ptr++ = '\0';
+	*outptr = '\0';
+	ptr++;
 
 	while (isblank((unsigned char)*ptr))
 		ptr++;
