[RFC PATCH 3/6] libutil: Remove usage of PATH_MAX from getrealpath

Punit Agrawal <[email protected]>
Newsgroups gmane.comp.gnu.global.bugs
Message-ID <[email protected]>
When realpath is given a NULL argument, it returns a buffer allocated
with malloc containing the path. Update getrealpath function to rely
on this behaviour instead of using PATH_MAX.

While making this change, verify that callers of getrealpath
responsibly free the returned buffer once they no longer have use for
it.
---
 libutil/find.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libutil/find.c b/libutil/find.c
index f366004..a009538 100644
--- a/libutil/find.c
+++ b/libutil/find.c
@@ -490,11 +490,11 @@ static int current_entry;			/**< current entry of the stack */
 static char *
 getrealpath(const char *dir)
 {
-	char real[PATH_MAX];
+	char *real;
 
-	if (realpath(dir, real) == NULL)
+	if ((real = realpath(dir, NULL)) == NULL)
 		die("cannot get real path of '%s'.", trimpath(dir));
-	return check_strdup(real);
+	return real;
 }
 /**
  * has_symlinkloop: whether or not dir has a symbolic link loops.
-- 
2.11.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.