summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-09-24 17:18:47 -0600
committerEric Blake <ebb9@byu.net>2009-10-08 06:52:18 -0600
commit7a3bc1bf27b07de85b1b4fcaa9e60f591ba5f0d4 (patch)
tree9519b30caa0f6896247570cde99c57b4e6983215
parent00674c747512687605447685730021a02bd5901b (diff)
downloadcoreutils-7a3bc1bf27b07de85b1b4fcaa9e60f591ba5f0d4.tar.xz
stdbuf: improve path search
* src/stdbuf.c (set_program_path): Use gnulib methods for better file name handling. * bootstrap.conf (gnulib_modules): Add xreadlink.
-rw-r--r--bootstrap.conf1
-rw-r--r--src/stdbuf.c28
2 files changed, 12 insertions, 17 deletions
diff --git a/bootstrap.conf b/bootstrap.conf
index e523273fc..9cf3746a2 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -238,6 +238,7 @@ gnulib_modules="
xnanosleep
xprintf
xprintf-posix
+ xreadlink
xstrtod
xstrtoimax
xstrtol
diff --git a/src/stdbuf.c b/src/stdbuf.c
index afb7821f7..05a6b9fe8 100644
--- a/src/stdbuf.c
+++ b/src/stdbuf.c
@@ -24,8 +24,10 @@
#include "system.h"
#include "error.h"
+#include "filenamecat.h"
#include "posixver.h"
#include "quote.h"
+#include "xreadlink.h"
#include "xstrtol.h"
#include "c-ctype.h"
@@ -145,34 +147,26 @@ set_program_path (const char *arg)
}
else
{
- char *path;
- char tmppath[PATH_MAX + 1];
- ssize_t len = readlink ("/proc/self/exe", tmppath, sizeof (tmppath) - 1);
- if (len > 0)
- {
- tmppath[len] = '\0';
- program_path = dir_name (tmppath);
- }
+ char *path = xreadlink ("/proc/self/exe");
+ if (path)
+ program_path = dir_name (path);
else if ((path = getenv ("PATH")))
{
char *dir;
path = xstrdup (path);
for (dir = strtok (path, ":"); dir != NULL; dir = strtok (NULL, ":"))
{
- int req = snprintf (tmppath, sizeof (tmppath), "%s/%s", dir, arg);
- if (req >= sizeof (tmppath))
- {
- error (0, 0, _("path truncated when looking for %s"),
- quote (arg));
- }
- else if (access (tmppath, X_OK) == 0)
+ char *candidate = file_name_concat (dir, arg, NULL);
+ if (access (candidate, X_OK) == 0)
{
- program_path = dir_name (tmppath);
+ program_path = dir_name (candidate);
+ free (candidate);
break;
}
+ free (candidate);
}
- free (path);
}
+ free (path);
}
}