diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-02-12 17:26:31 -0500 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2023-02-12 17:26:31 -0500 |
commit | 2fb1839b7cb30fe4710677d9e78e84b5bc97d9f7 (patch) | |
tree | 9204ceb4c6d4143ef991ef31135c3333af6dbfe0 /common.c | |
parent | ddc018b7860211b250ecd5ca80912497e09f1d36 (diff) | |
download | mstat-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.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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) { |