aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2023-02-10 12:41:00 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2023-02-10 12:41:00 -0500
commit3f67aea0ff9b58f903f20ffc8bba7a9607caed76 (patch)
treeb57584574aeab1f9be681db1032f6c51f4610401
parente07d09df965c65fb59029a3af01b4d0727b4ae21 (diff)
downloadmstat-3f67aea0ff9b58f903f20ffc8bba7a9607caed76.tar.gz
Move find_program to common (refactored as mstat_find_program)
-rw-r--r--mstat_plot.c30
1 files changed, 1 insertions, 29 deletions
diff --git a/mstat_plot.c b/mstat_plot.c
index b71ef69..1357f48 100644
--- a/mstat_plot.c
+++ b/mstat_plot.c
@@ -30,34 +30,6 @@ struct Option {
/**
- * Determine if `name` is available on `PATH`
- * @param name of executable
- * @return 0 on success. >0 on error
- */
-static int find_program(const char *name) {
- char *path;
- char *pathtmp;
- char *token;
- char pathtest[PATH_MAX] = {0};
-
- pathtmp = getenv("PATH");
- if (!pathtmp) {
- return 1;
- }
- path = strdup(pathtmp);
-
- while ((token = strsep(&path, ":")) != NULL) {
- snprintf(pathtest, PATH_MAX - 1, "%s/%s", token, name);
- if (access(pathtest, F_OK | X_OK) == 0) {
- free(path);
- return 0;
- }
- }
- free(path);
- return 1;
-}
-
-/**
* Open a new gnuplot handle
* @return stream on success, or NULL on error
*/
@@ -348,7 +320,7 @@ int main(int argc, char *argv[]) {
printf("%s min(%.2lf) max(%.2lf)\n", field[i], mem_min, mem_max);
}
- if (find_program("gnuplot")) {
+ if (mstat_find_program("gnuplot", NULL)) {
fprintf(stderr, "To render plots please install gnuplot\n");
exit(1);
}