[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#1060420: less: Fix build failure on GNU/Hurd



Source: less
Source-Version: 590-2
Severity: important
Tags: patch
Forwarded: https://github.com/gwsw/less/pull/469
X-Debbugs-Cc: debian-hurd@lists.debian.org

Hi!

This package has been failing to build for a while on GNU/Hurd, due to
the assumption that PATH_MAX is defined on all systems, which is not
the case on GNU/Hurd as it tries to impose no arbitrary limits
gratuitously.

I've prepared a patch fixing this and submitted that upstream, and
adapted that for the current version in Debian, which I'm attaching.

Thanks,
Guillem
From d29a630e1a112613e20bff4917fee879951a6112 Mon Sep 17 00:00:00 2001
From: Guillem Jover <guillem@hadrons.org>
Date: Thu, 11 Jan 2024 02:18:07 +0100
Subject: [PATCH] Do not assume PATH_MAX is defined
Origin: vendor
Forwarded: https://github.com/gwsw/less/pull/469

On systems such as GNU/Hurd, PATH_MAX is not defined, because the system
intends to impose no arbitrary limits. In other systems though it might
be defined but to a very large value.

We can use realpath() with its POSIX.1-2008 semantics, where passing a
NULL argument will make it allocate the destination buffer, but not all
systems support these semantics yet.

For now, instead of complicating the code to cope with realpath()
limitations on some systems, we simply handle the case where PATH_MAX
is not defined, where realpath() should always support these semantics.
---
 filename.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

--- a/filename.c
+++ b/filename.c
@@ -800,10 +800,25 @@ lrealpath(path)
 	char *path;
 {
 #if HAVE_REALPATH
+	/*
+	 * Not all systems support the POSIX.1-2008 realpath() behavior of
+	 * allocating when passing a NULL argument. And PATH_MAX is not
+	 * required to be defined, or might contain an exceedinly big value.
+	 * We assume that if it is not defined (such as on GNU/Hurd), then
+	 * realpath() accepts NULL.
+	 */
+#ifndef PATH_MAX
+		char *rpath;
+
+		rpath = realpath(path, NULL);
+		if (rpath != NULL)
+			return rpath;
+#else
 	char rpath[PATH_MAX];
 	if (realpath(path, rpath) != NULL)
 		return (save(rpath));
 #endif
+#endif
 	return (save(path));
 }
 

Reply to: