From 83ce04d4c38da93a4fc8ace4d7b962d23c7c2f68 Mon Sep 17 00:00:00 2001
From: Jeremie Koenig <jk@jk.fr.eu.org>
Date: Tue, 23 Mar 2010 22:36:01 +0100
Subject: [PATCH 3/9] libbb: reenable xmalloc_realpath()

GNU Hurd does not have a PATH_MAX constant (as prescribed by POSIX when
no such limit exists). As a consequence the realpath() function can be
safely used only with a NULL first argument, which makes it return an
malloc'ed string.
---
 include/libbb.h   |    2 +-
 libbb/xreadlink.c |    4 +---
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/include/libbb.h b/include/libbb.h
index 72d6c7d..794e438 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -339,7 +339,7 @@ void xmove_fd(int, int) FAST_FUNC;
 DIR *xopendir(const char *path) FAST_FUNC;
 DIR *warn_opendir(const char *path) FAST_FUNC;
 
-/* UNUSED: char *xmalloc_realpath(const char *path) FAST_FUNC RETURNS_MALLOC; */
+char *xmalloc_realpath(const char *path) FAST_FUNC RETURNS_MALLOC;
 char *xmalloc_readlink(const char *path) FAST_FUNC RETURNS_MALLOC;
 char *xmalloc_readlink_or_warn(const char *path) FAST_FUNC RETURNS_MALLOC;
 /* !RETURNS_MALLOC: it's a realloc-like function */
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c
index 8d232f1..a6ab1c6 100644
--- a/libbb/xreadlink.c
+++ b/libbb/xreadlink.c
@@ -100,12 +100,11 @@ char* FAST_FUNC xmalloc_readlink_or_warn(const char *path)
 	return buf;
 }
 
-/* UNUSED */
-#if 0
 char* FAST_FUNC xmalloc_realpath(const char *path)
 {
 #if defined(__GLIBC__) && !defined(__UCLIBC__)
 	/* glibc provides a non-standard extension */
+	/* (NB: actually POSIX.1-2008 specifies this behavior as well) */
 	return realpath(path, NULL);
 #else
 	char buf[PATH_MAX+1];
@@ -114,4 +113,3 @@ char* FAST_FUNC xmalloc_realpath(const char *path)
 	return xstrdup(realpath(path, buf));
 #endif
 }
-#endif
-- 
1.7.0.2

