From 3f67aea0ff9b58f903f20ffc8bba7a9607caed76 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 10 Feb 2023 12:41:00 -0500 Subject: Move find_program to common (refactored as mstat_find_program) --- mstat_plot.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'mstat_plot.c') diff --git a/mstat_plot.c b/mstat_plot.c index b71ef69..1357f48 100644 --- a/mstat_plot.c +++ b/mstat_plot.c @@ -29,34 +29,6 @@ struct Option { } 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); } -- cgit