From 2fb1839b7cb30fe4710677d9e78e84b5bc97d9f7 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sun, 12 Feb 2023 17:26:31 -0500 Subject: More stdout message modification * Clear terminal (if possible) and pretty print all fields for each sample * Clean up usage statement(s) * mstat_find_program returns absolute path of "name" on success if "name" begins with "./" * Zero option structure(s) at runtime --- common.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'common.c') diff --git a/common.c b/common.c index f9a8944..0fc55d5 100644 --- a/common.c +++ b/common.c @@ -591,11 +591,22 @@ int mstat_find_program(const char *name, char *where) { path = strdup(pathtmp); path_orig = path; + if (!strncmp(name, "./", 2)) { + strncpy(nametmp, realpath(name, NULL), PATH_MAX - 1); + if (access(nametmp, X_OK) < 0) { + return 1; + } + if (where) { + strcpy(where, nametmp); + } + return 0; + } + char *last_element = strrchr(name, '/'); if (last_element) { - strncpy(nametmp, last_element + 1, sizeof(nametmp) - 1); + strncat(nametmp, last_element + 1, sizeof(nametmp) - 1); } else { - strncpy(nametmp, name, sizeof(nametmp) - 1); + strncat(nametmp, name, sizeof(nametmp) - 1); } while ((token = strsep(&path, ":")) != NULL) { -- cgit