[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
- [RFC PATCH 0/6] Enable building Gnu Global package on Hurd, Punit Agrawal, 2017/01/24
- [RFC PATCH 3/6] libutil: Remove usage of PATH_MAX from getrealpath,
Punit Agrawal <=
- [RFC PATCH 1/6] libutil: Drop extraneous function declarations, Punit Agrawal, 2017/01/24
- [RFC PATCH 2/6] libutil: Staticize locally used functions, Punit Agrawal, 2017/01/24
- [RFC PATCH 5/6] libutil: Convert rootdir to a dynamically allocated array, Punit Agrawal, 2017/01/24
- [RFC PATCH 4/6] libutil: Remove usage of PATH_MAX from has_symlinkloop, Punit Agrawal, 2017/01/24
- [RFC PATCH 6/6] libutil: Drop the requirement for PATH_MAX macro, Punit Agrawal, 2017/01/24
- Re: [RFC PATCH 0/6] Enable building Gnu Global package on Hurd, Shigio YAMAGUCHI, 2017/01/25