aboutsummaryrefslogtreecommitdiffstats
path: root/src/stdbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdbuf.c')
-rw-r--r--src/stdbuf.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/stdbuf.c b/src/stdbuf.c
index 007cc2194..393071354 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"
@@ -35,9 +37,6 @@
#define AUTHORS proper_name_utf8 ("Padraig Brady", "P\303\241draig Brady")
-/* Internal error */
-enum { EXIT_CANCELED = 125 };
-
static char *program_path;
extern char **environ;
@@ -125,7 +124,7 @@ for e.g.) then that will override corresponding settings changed by `stdbuf'.\n\
Also some filters (like `dd' and `cat' etc.) don't use streams for I/O,\n\
and are thus unaffected by `stdbuf' settings.\n\
"), stdout);
- emit_bug_reporting_address ();
+ emit_ancillary_info ();
}
exit (status);
}
@@ -145,34 +144,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);
}
}