aboutsummaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2023-02-12 17:26:31 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2023-02-12 17:26:31 -0500
commit2fb1839b7cb30fe4710677d9e78e84b5bc97d9f7 (patch)
tree9204ceb4c6d4143ef991ef31135c3333af6dbfe0 /common.c
parentddc018b7860211b250ecd5ca80912497e09f1d36 (diff)
downloadmstat-2fb1839b7cb30fe4710677d9e78e84b5bc97d9f7.tar.gz
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
Diffstat (limited to 'common.c')
-rw-r--r--common.c15
1 files changed, 13 insertions, 2 deletions
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) {