bug-global
[Top][All Lists]
Advanced

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

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


From: Punit Agrawal
Subject: [RFC PATCH 3/6] libutil: Remove usage of PATH_MAX from getrealpath
Date: Mon, 23 Jan 2017 22:43:36 +0000

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]