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
_______________________________________________
Bug-global mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-global