diff -Paur --no-dereference -- mdocml.upstream/apropos.1 mdocml/apropos.1
--- mdocml.upstream/apropos.1
+++ mdocml/apropos.1
@@ -74,7 +74,7 @@
 If the standard output is a terminal device and
 .Fl c
 is not specified, use
-.Xr more 1
+.Xr pager 1
 to paginate them.
 In
 .Fl a
@@ -93,7 +93,7 @@
 In
 .Fl a
 mode, copy the formatted manual pages to the standard output without using
-.Xr more 1
+.Xr pager 1
 to paginate them.
 .It Fl f
 Search for all words in
@@ -342,7 +342,7 @@
 Any non-empty value of the environment variable
 .Ev MANPAGER
 will be used instead of the standard pagination program,
-.Xr more 1 .
+.Xr pager 1 .
 .It Ev MANPATH
 The standard search path used by
 .Xr man 1
@@ -365,7 +365,7 @@
 .Ev MANPAGER
 is not defined.
 If neither PAGER nor MANPAGER is defined,
-.Pa /usr/bin/more Fl s
+.Pa pager Fl R
 will be used.
 .El
 .Sh FILES
diff -Paur --no-dereference -- mdocml.upstream/compat_fts.c mdocml/compat_fts.c
--- mdocml.upstream/compat_fts.c
+++ mdocml/compat_fts.c
@@ -100,7 +100,12 @@
 	 * Start out with 1K of path space, and enough, in any case,
 	 * to hold the user's paths.
 	 */
+	/* PATCH: Sortix doesn't have PATH_MAX. */
+#ifdef PATH_MAX
 	if (fts_palloc(sp, MAXIMUM(fts_maxarglen(argv), PATH_MAX)))
+#else
+	if (fts_palloc(sp, MAXIMUM(fts_maxarglen(argv), 32768)))
+#endif
 		goto mem1;
 
 	/* Allocate/initialize root's parent. */
@@ -416,7 +421,8 @@
 	size_t dlen, len, maxlen;
 	int nitems, cderrno, descend, level, doadjust;
 	int saved_errno;
-	char *cp;
+	/* PATCH: -Wmaybe-uninitialized */
+	char *cp = NULL;
 
 	/* Set current node pointer. */
 	cur = sp->fts_cur;
diff -Paur --no-dereference -- mdocml.upstream/configure mdocml/configure
--- mdocml.upstream/configure
+++ mdocml/configure
@@ -16,8 +16,7 @@
 
 set -e
 
-[ -e config.log ] && mv config.log config.log.old
-[ -e config.h   ] && mv config.h config.h.old
+# PATCH: Don't clutter the tree with useless old config files.
 
 # Output file descriptor usage:
 # 1 (stdout): config.h, Makefile.local
@@ -33,10 +32,12 @@
 
 OSNAME=
 
-CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | make -f -`
-CFLAGS="-g -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings"
+# PATCH: Respect CC and CFLAGS from the environment.
+[ -z "${CC+x}" ] && CC=`printf "all:\\n\\t@echo \\\$(CC)\\n" | ${MAKE:-make} -f -`
+[ -z "${CFLAGS+x}" ] && CFLAGS="-g"
+CFLAGS="$CFLAGS -std=gnu11 -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings"
 DBLIB=
-STATIC="-static"
+STATIC=
 
 BUILD_DB=1
 BUILD_CGI=0
@@ -60,13 +61,17 @@
 HAVE_OHASH=
 HAVE_MANPATH=
 
-PREFIX="/usr/local"
-BINDIR=
-SBINDIR=
-INCLUDEDIR=
-LIBDIR=
-MANDIR=
-EXAMPLEDIR=
+# PATCH: Properly determine these locations with the below options.
+unset PREFIX
+unset EXEC_PREFIX
+unset BINDIR
+unset SBINDIR
+unset DATAROOTDIR
+unset INCLUDEDIR
+unset LIBDIR
+unset MANDIR
+unset SYSCONFDIR
+unset EXAMPLEDIR
 HOMEBREWDIR=
 
 WWWPREFIX="/var/www"
@@ -89,18 +94,63 @@
 INSTALL_MAN=
 INSTALL_DATA=
 
-# --- manual settings from configure.local -----------------------------
+# PATCH: Implement standard configure script options.
+# --- parse command line options ---------------------------------------
 
-if [ -e ./configure.local ]; then
-	echo "configure.local: reading..." 1>&2
-	echo "configure.local: reading..." 1>&3
-	cat ./configure.local 1>&3
-	. ./configure.local
-else
-	echo "configure.local: no (fully automatic configuration)" 1>&2
-	echo "configure.local: no (fully automatic configuration)" 1>&3
-fi
-echo 1>&3
+dashdash=
+previous_option=
+option_checking=true
+for argument do
+  if test -n "$previous_option"; then
+    eval $previous_option=\$argument
+    previous_option=
+    continue
+  fi
+
+  case $argument in
+  *=?*) parameter=$(expr "X$argument" : '[^=]*=\(.*\)') ;;
+  *=)   parameter= ;;
+  *)    parameter=yes ;;
+  esac
+
+  case $dashdash$argument in
+  --) dashdash=yes ;;
+  --bindir=*) BINDIR=$parameter ;;
+  --bindir) previous_option=BINDIR ;;
+  --datarootdir=*) DATAROOTDIR=$parameter ;;
+  --datarootdir) previous_option=DATAROOTDIR ;;
+  --exampledir=*) EXAMPLEDIR=$parameter ;;
+  --exampledir) previous_option=EXAMPLEDIR ;;
+  --exec-prefix=*) EXEC_PREFIX=$parameter ;;
+  --exec-prefix) previous_option=EXEC_PREFIX ;;
+  --includedir=*) INCLUDEDIR=$parameter ;;
+  --includedir) previous_option=INCLUDEDIR ;;
+  --libdir=*) LIBDIR=$parameter ;;
+  --libdir) previous_option=LIBDIR ;;
+  --mandir=*) MANDIR=$parameter ;;
+  --mandir) previous_option=MANDIR ;;
+  --prefix=*) PREFIX=$parameter ;;
+  --prefix) previous_option=PREFIX ;;
+  --sbindir) previous_option=SBINDIR ;;
+  --sbindir=*) SBINDIR=$parameter ;;
+  --sysconfdir) previous_option=SYSCONFDIR ;;
+  --sysconfdir=*) SYSCONFDIR=$parameter ;;
+  -h | --help | --help=*) exit 0 ;;
+  -V | --version) exit 0 ;;
+  *) echo "$0: ignoring unexpected operand $argument" >&2
+  esac
+done
+
+[ -z ${PREFIX+x}      ] && PREFIX="/usr/local"
+[ -z ${EXEC_PREFIX+x} ] && EXEC_PREFIX="$PREFIX"
+[ -z ${BINDIR+x}      ] && BINDIR="$EXEC_PREFIX/bin"
+[ -z ${SBINDIR+x}     ] && SBINDIR="$EXEC_PREFIX/sbin"
+[ -z ${SYSCONFDIR+x}  ] && SYSCONFDIR="$PREFIX/etc"
+[ -z ${DATAROOTDIR+x} ] && DATAROOTDIR="$PREFIX/share"
+[ -z ${INCLUDEDIR+x}  ] && INCLUDEDIR="$PREFIX/include"
+[ -z ${LIBDIR+x}      ] && LIBDIR="$EXEC_PREFIX/lib"
+[ -z ${MANDIR+x}      ] && MANDIR="$DATAROOTDIR/man"
+[ -z ${EXAMPLEDIR+x}  ] && EXAMPLEDIR="${DATAROOTDIR}/examples/mandoc"
 
 # --- tests for config.h  ----------------------------------------------
 
@@ -135,19 +185,20 @@
 		return 1
 	fi
 
-	if ./test-${1} 1>&3 2>&3; then
+	# PATCH: Tests can't be run when cross-compiling.
+	#if ./test-${1} 1>&3 2>&3; then
 		echo "${1}: yes" 1>&2
 		echo "${1}: yes" 1>&3
 		echo 1>&3
 		eval HAVE_${2}=1
 		rm "test-${1}"
 		return 0
-	else
-		echo "${1}: execution failed with $?" 1>&3
-		echo 1>&3
-		rm "test-${1}"
-		return 1
-	fi
+	#else
+	#	echo "${1}: execution failed with $?" 1>&3
+	#	echo 1>&3
+	#	rm "test-${1}"
+	#	return 1
+	#fi
 }
 
 # Run a complete autoconfiguration test, including the check for
@@ -239,11 +290,12 @@
 # --- manpath ---
 if ismanual manpath "${HAVE_MANPATH}"; then
 	:
-elif manpath 1>&3 2>&3; then
-	echo "manpath: yes" 1>&2
-	echo "manpath: yes" 1>&3
-	echo 1>&3
-	HAVE_MANPATH=1
+# PATCH: The manpath(1) in PATH doesn't make sense when cross-compiling.
+#elif manpath 1>&3 2>&3; then
+#	echo "manpath: yes" 1>&2
+#	echo "manpath: yes" 1>&3
+#	echo 1>&3
+#	HAVE_MANPATH=1
 else
 	echo "manpath: no" 1>&2
 	echo "manpath: no" 1>&3
@@ -298,6 +350,8 @@
 #define BINM_WHATIS "${BINM_WHATIS}"
 #define BINM_MAKEWHATIS "${BINM_MAKEWHATIS}"
 
+#define SYSCONFDIR "${SYSCONFDIR}"
+
 #if !defined(__BEGIN_DECLS)
 #  ifdef __cplusplus
 #  define	__BEGIN_DECLS		extern "C" {
@@ -352,20 +406,14 @@
 
 exec > Makefile.local
 
-[ -z "${BINDIR}"     ] && BINDIR="${PREFIX}/bin"
-[ -z "${SBINDIR}"    ] && SBINDIR="${PREFIX}/sbin"
-[ -z "${INCLUDEDIR}" ] && INCLUDEDIR="${PREFIX}/include/mandoc"
-[ -z "${LIBDIR}"     ] && LIBDIR="${PREFIX}/lib/mandoc"
-[ -z "${MANDIR}"     ] && MANDIR="${PREFIX}/man"
-[ -z "${EXAMPLEDIR}" ] && EXAMPLEDIR="${PREFIX}/share/examples/mandoc"
-
 [ -z "${HTDOCDIR}"   ] && HTDOCDIR="${WWWPREFIX}/htdocs"
 [ -z "${CGIBINDIR}"  ] && CGIBINDIR="${WWWPREFIX}/cgi-bin"
 
-[ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0555"
-[ -z "${INSTALL_LIB}"     ] && INSTALL_LIB="${INSTALL} -m 0444"
-[ -z "${INSTALL_MAN}"     ] && INSTALL_MAN="${INSTALL} -m 0444"
-[ -z "${INSTALL_DATA}"    ] && INSTALL_DATA="${INSTALL} -m 0444"
+# PATCH: System files should be writable by root.
+[ -z "${INSTALL_PROGRAM}" ] && INSTALL_PROGRAM="${INSTALL} -m 0755"
+[ -z "${INSTALL_LIB}"     ] && INSTALL_LIB="${INSTALL} -m 0644"
+[ -z "${INSTALL_MAN}"     ] && INSTALL_MAN="${INSTALL} -m 0644"
+[ -z "${INSTALL_DATA}"    ] && INSTALL_DATA="${INSTALL} -m 0644"
 
 if [ ${BUILD_DB} -eq 0 -a ${BUILD_CGI} -gt 0 ]; then
 	echo "BUILD_CGI=0 (no BUILD_DB)" 1>&2
@@ -391,6 +439,7 @@
 INCLUDEDIR	= ${INCLUDEDIR}
 LIBDIR		= ${LIBDIR}
 MANDIR		= ${MANDIR}
+SYSCONFDIR	= ${SYSCONFDIR}
 EXAMPLEDIR	= ${EXAMPLEDIR}
 WWWPREFIX	= ${WWWPREFIX}
 HTDOCDIR	= ${HTDOCDIR}
@@ -417,4 +466,15 @@
 echo "Makefile.local: written" 1>&2
 echo "Makefile.local: written" 1>&3
 
+# PATCH: Make default configuration file so man works by default.
+exec > man.conf.default
+cat << __HEREDOC__
+_version	BSD.2
+_default	${MANDIR}/
+_whatdb		${MANDIR}/
+__HEREDOC__
+
+echo "man.conf.default: written" 1>&2
+echo "man.conf.default: written" 1>&3
+
 exit 0
diff -Paur --no-dereference -- mdocml.upstream/eqn.c mdocml/eqn.c
--- mdocml.upstream/eqn.c
+++ mdocml/eqn.c
@@ -697,7 +697,8 @@
 {
 	char		 sym[64];
 	struct eqn_box	*cur;
-	const char	*start;
+	/* PATCH: -Wmaybe-uninitialized */
+	const char	*start = NULL;
 	char		*p;
 	size_t		 i, sz;
 	enum eqn_tok	 tok, subtok;
diff -Paur --no-dereference -- mdocml.upstream/main.c mdocml/main.c
--- mdocml.upstream/main.c
+++ mdocml/main.c
@@ -19,7 +19,6 @@
 #include "config.h"
 
 #include <sys/types.h>
-#include <sys/param.h>	/* MACHINE */
 #include <sys/wait.h>
 
 #include <assert.h>
@@ -606,7 +605,38 @@
 	*res = NULL;
 	*ressz = lastsz = 0;
 	while (argc) {
-		for (ipath = 0; ipath < paths->sz; ipath++) {
+		/* PATCH: Support showing a manual page from the filesystem
+		          instead of the database by doing so if the path
+		          contains a directory separator. This behavior
+		          matches that of the Linux man program. */
+		if (strchr(*argv, '/')) {
+			if (access(*argv, R_OK) < 0) {
+				fprintf(stderr,
+				    "%s: %s: %s\n",
+				    progname, *argv, strerror(errno));
+			} else {
+				struct manpage *page;
+				char *sec;
+				char *file;
+				file = mandoc_strdup(*argv);
+				sec = strrchr(file, '.');
+				if (sec && sec[1])
+					sec++;
+				else
+					sec = file + strlen(file) - 1;
+				*res = mandoc_reallocarray(*res, ++*ressz,
+				           sizeof(struct manpage));
+				page = *res + (*ressz - 1);
+				page->file = file;
+				page->names = NULL;
+				page->output = NULL;
+				page->ipath = 0;
+				page->bits = NAME_FILE & NAME_MASK;
+				page->sec = (*sec >= '1' && *sec <= '9') ?
+				            *sec - '1' + 1 : 10;
+				page->form = FORM_SRC;
+			}
+		} else for (ipath = 0; ipath < paths->sz; ipath++) {
 			if (cfg->sec != NULL) {
 				if (fs_lookup(paths, ipath, cfg->sec,
 				    cfg->arch, *argv, res, ressz) &&
@@ -989,7 +1019,7 @@
 	if (pager == NULL || *pager == '\0')
 		pager = getenv("PAGER");
 	if (pager == NULL || *pager == '\0')
-		pager = "/usr/bin/more -s";
+		pager = "pager -R";
 	cp = mandoc_strdup(pager);
 
 	/*
@@ -1014,7 +1044,7 @@
 	/* Hand over to the pager. */
 
 	execvp(argv[0], argv);
-	fprintf(stderr, "%s: exec: %s\n",
-	    progname, strerror(errno));
+	fprintf(stderr, "%s: exec: %s: %s\n",
+	    progname, argv[0], strerror(errno));
 	exit((int)MANDOCLEVEL_SYSERR);
 }
diff -Paur --no-dereference -- mdocml.upstream/Makefile mdocml/Makefile
--- mdocml.upstream/Makefile
+++ mdocml/Makefile
@@ -294,6 +294,7 @@
 
 distclean: clean
 	rm -f Makefile.local config.h config.h.old config.log config.log.old
+	rm -f man.conf.default
 
 clean:
 	rm -f libmandoc.a $(LIBMANDOC_OBJS) $(COMPAT_OBJS)
@@ -312,6 +313,8 @@
 	mkdir -p $(DESTDIR)$(MANDIR)/man1
 	mkdir -p $(DESTDIR)$(MANDIR)/man3
 	mkdir -p $(DESTDIR)$(MANDIR)/man7
+	mkdir -p $(DESTDIR)$(SYSCONFDIR)
+	mkdir -p $(DESTDIR)$(SYSCONFDIR)/default
 	$(INSTALL_PROGRAM) mandoc demandoc $(DESTDIR)$(BINDIR)
 	ln -f $(DESTDIR)$(BINDIR)/mandoc $(DESTDIR)$(BINDIR)/$(BINM_MAN)
 	$(INSTALL_LIB) libmandoc.a $(DESTDIR)$(LIBDIR)
@@ -328,6 +331,7 @@
 	$(INSTALL_MAN) tbl.7 $(DESTDIR)$(MANDIR)/man7/${MANM_TBL}.7
 	$(INSTALL_MAN) mandoc_char.7 $(DESTDIR)$(MANDIR)/man7
 	$(INSTALL_DATA) example.style.css $(DESTDIR)$(EXAMPLEDIR)
+	$(INSTALL_DATA) man.conf.default $(DESTDIR)$(SYSCONFDIR)/default/man.conf
 
 db-install: base-build
 	mkdir -p $(DESTDIR)$(BINDIR)
diff -Paur --no-dereference -- mdocml.upstream/man.1 mdocml/man.1
--- mdocml.upstream/man.1
+++ mdocml/man.1
@@ -85,7 +85,7 @@
 for a description of the contents of this file.
 .It Fl c
 Copy the manual page to the standard output instead of using
-.Xr more 1
+.Xr pager 1
 to paginate it.
 This is done by default if the standard output is not a terminal device.
 .It Fl f
@@ -359,7 +359,7 @@
 Any non-empty value of the environment variable
 .Ev MANPAGER
 will be used instead of the standard pagination program,
-.Xr more 1 .
+.Xr pager 1 .
 .It Ev MANPATH
 The standard search path used by
 .Nm
@@ -381,7 +381,7 @@
 .Ev MANPAGER
 is not defined.
 If neither PAGER nor MANPAGER is defined,
-.Pa /usr/bin/more Fl s
+.Pa pager Fl R
 will be used.
 .El
 .Sh FILES
diff -Paur --no-dereference -- mdocml.upstream/mandoc.1 mdocml/mandoc.1
--- mdocml.upstream/mandoc.1
+++ mdocml/mandoc.1
@@ -58,13 +58,13 @@
 If the standard output is a terminal device and
 .Fl c
 is not specified, use
-.Xr more 1
+.Xr pager 1
 to paginate the output, just like
 .Xr man 1
 would.
 .It Fl c
 Copy the formatted manual pages to the standard output without using
-.Xr more 1
+.Xr pager 1
 to paginate them.
 This is the default.
 It can be specified to override
@@ -500,13 +500,13 @@
 Any non-empty value of the environment variable
 .Ev MANPAGER
 will be used instead of the standard pagination program,
-.Xr more 1 .
+.Xr pager 1 .
 .It Ev PAGER
 Specifies the pagination program to use when
 .Ev MANPAGER
 is not defined.
 If neither PAGER nor MANPAGER is defined,
-.Pa /usr/bin/more Fl s
+.Pa pager Fl R
 will be used.
 .El
 .Sh EXIT STATUS
diff -Paur --no-dereference -- mdocml.upstream/mandocdb.c mdocml/mandocdb.c
--- mdocml.upstream/mandocdb.c
+++ mdocml/mandocdb.c
@@ -576,7 +576,9 @@
 static int
 treescan(void)
 {
-	char		 buf[PATH_MAX];
+	/* PATCH: Use realpath without a destination buffer so it's well-defined
+	          when PATH_MAX doesn't exist, like on Sortix. */
+	char		*buf;
 	FTS		*f;
 	FTSENT		*ff;
 	struct mlink	*mlink;
@@ -608,7 +610,7 @@
 		 * then get handled just like regular files.
 		 */
 		case FTS_SL:
-			if (NULL == realpath(path, buf)) {
+			if (NULL == (buf = realpath(path, NULL))) {
 				if (warnings)
 					say(path, "&realpath");
 				continue;
@@ -620,8 +622,10 @@
 			) {
 				if (warnings) say("",
 				    "%s: outside base directory", buf);
+				free(buf);
 				continue;
 			}
+			free(buf);
 			/* Use logical inode to avoid mpages dupe. */
 			if (-1 == stat(path, ff->fts_statp)) {
 				if (warnings)
@@ -782,7 +786,7 @@
 static void
 filescan(const char *file)
 {
-	char		 buf[PATH_MAX];
+	char		*buf;
 	struct stat	 st;
 	struct mlink	*mlink;
 	char		*p, *start;
@@ -813,7 +817,7 @@
 	 * We have to resolve the file name to the real path
 	 * in any case for the base directory check.
 	 */
-	if (NULL == realpath(file, buf)) {
+	if (NULL == (buf = realpath(file, NULL))) {
 		exitcode = (int)MANDOCLEVEL_BADARG;
 		say(file, "&realpath");
 		return;
@@ -830,6 +834,7 @@
 	else {
 		exitcode = (int)MANDOCLEVEL_BADARG;
 		say("", "%s: outside base directory", buf);
+		free(buf);
 		return;
 	}
 
@@ -846,10 +851,12 @@
 		if (-1 == stat(buf, &st)) {
 			exitcode = (int)MANDOCLEVEL_BADARG;
 			say(file, "&stat");
+			free(buf);
 			return;
 		}
 		if (strlcpy(buf, file, sizeof(buf)) >= sizeof(buf)) {
 			say(file, "Filename too long");
+			free(buf);
 			return;
 		}
 		start = buf;
@@ -863,6 +870,7 @@
 	    sizeof(mlink->file)) {
 		say(start, "Filename too long");
 		free(mlink);
+		free(buf);
 		return;
 	}
 
@@ -913,6 +921,8 @@
 		*p = '\0';
 	}
 	mlink_add(mlink, &st);
+
+	free(buf);
 }
 
 static void
@@ -2429,6 +2439,7 @@
 	static int	 getcwd_status;  /* 1 = ok, 2 = failure */
 	static int	 chdir_status;  /* 1 = changed directory */
 	char		*cp;
+	char            *buf;
 
 	/*
 	 * Remember the original working directory, if possible.
@@ -2475,13 +2486,20 @@
 	 * pathname and append a trailing slash, such that
 	 * we can reliably check whether files are inside.
 	 */
-	if (NULL == realpath(targetdir, basedir)) {
+	if (NULL == (buf = realpath(targetdir, NULL))) {
 		if (report_baddir || errno != ENOENT) {
 			exitcode = (int)MANDOCLEVEL_BADARG;
 			say("", "&%s: realpath", targetdir);
 		}
 		return(0);
-	} else if (-1 == chdir(basedir)) {
+	}
+	if (sizeof(basedir) <= strlcpy(basedir, buf, sizeof(basedir))) {
+		exitcode = (int)MANDOCLEVEL_SYSERR;
+		say("", "Filename too long");
+		return 0;
+	}
+	free(buf);
+	if (-1 == chdir(basedir)) {
 		if (report_baddir || errno != ENOENT) {
 			exitcode = (int)MANDOCLEVEL_BADARG;
 			say("", "&chdir");
diff -Paur --no-dereference -- mdocml.upstream/manpage.c mdocml/manpage.c
--- mdocml.upstream/manpage.c
+++ mdocml/manpage.c
@@ -177,7 +177,7 @@
 		cmd = NULL != getenv("MANPAGER") ?
 			getenv("MANPAGER") :
 			(NULL != getenv("PAGER") ?
-			 getenv("PAGER") : "more");
+			 getenv("PAGER") : "pager");
 		execlp(cmd, cmd, (char *)NULL);
 		perror(cmd);
 		exit(EXIT_FAILURE);
diff -Paur --no-dereference -- mdocml.upstream/manpath.c mdocml/manpath.c
--- mdocml.upstream/manpath.c
+++ mdocml/manpath.c
@@ -26,11 +26,13 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "mandoc_aux.h"
 #include "manpath.h"
 
-#define MAN_CONF_FILE	"/etc/man.conf"
+#define MAN_CONF_FILE	SYSCONFDIR "/man.conf"
+#define MAN_CONF_DEF	SYSCONFDIR "/default/man.conf"
 #define MAN_CONF_KEY	"_whatdb"
 
 static	void	 manpath_add(struct manpaths *, const char *, int);
@@ -99,6 +101,13 @@
 
 	/* MANPATH and man.conf(5) cooperate. */
 	defp = getenv("MANPATH");
+	/* PATCH: Use /etc/default/man.conf if no /etc/man.conf. It lets us
+	          ship default configuration while the main file belongs to the
+	          system administrator. */
+	if (NULL == file && access(MAN_CONF_FILE, F_OK) != -1)
+		file = MAN_CONF_FILE;
+	if (NULL == file && access(MAN_CONF_DEF, F_OK) != -1)
+		file = MAN_CONF_DEF;
 	if (NULL == file)
 		file = MAN_CONF_FILE;
 
@@ -159,12 +168,13 @@
 static void
 manpath_add(struct manpaths *dirs, const char *dir, int complain)
 {
-	char		 buf[PATH_MAX];
 	struct stat	 sb;
 	char		*cp;
 	size_t		 i;
 
-	if (NULL == (cp = realpath(dir, buf))) {
+	/* PATCH: Use realpath without a destination buffer so it's well-defined
+	          when PATH_MAX doesn't exist, like on Sortix. */
+	if (NULL == (cp = realpath(dir, NULL))) {
 		if (complain) {
 			fputs("manpath: ", stderr);
 			perror(dir);
@@ -173,21 +183,24 @@
 	}
 
 	for (i = 0; i < dirs->sz; i++)
-		if (0 == strcmp(dirs->paths[i], dir))
+		if (0 == strcmp(dirs->paths[i], dir)) {
+			free(cp);
 			return;
+		}
 
 	if (stat(cp, &sb) == -1) {
 		if (complain) {
 			fputs("manpath: ", stderr);
 			perror(dir);
 		}
+		free(cp);
 		return;
 	}
 
 	dirs->paths = mandoc_reallocarray(dirs->paths,
 	    dirs->sz + 1, sizeof(char *));
 
-	dirs->paths[dirs->sz++] = mandoc_strdup(cp);
+	dirs->paths[dirs->sz++] = cp;
 }
 
 void
diff -Paur --no-dereference -- mdocml.upstream/read.c mdocml/read.c
--- mdocml.upstream/read.c
+++ mdocml/read.c
@@ -847,7 +847,8 @@
 			exit((int)MANDOCLEVEL_SYSERR);
 		}
 		execlp("gunzip", "gunzip", "-c", file, NULL);
-		perror("exec");
+		/* PATCH: Mention which program failed to run. */
+		perror("exec: gunzip");
 		exit((int)MANDOCLEVEL_SYSERR);
 	default:
 		close(pfd[1]);
