mirror of
https://github.com/troglobit/libite.git
synced 2026-10-02 13:52:51 +07:00
Add whichp() predicate function to which()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
@@ -288,10 +288,12 @@ Generic Functions
|
||||
optional listing of file and directory permissions if `show_perms` is
|
||||
set. The `path` argument should be a directory.
|
||||
|
||||
- `which(cmd)`
|
||||
- `which(cmd)`, `whichp(cmd)`
|
||||
|
||||
C implementation of UNIX which(1). Returns a malloc'ed string with the
|
||||
full path to `cmd` on success, otherwise `NULL`.
|
||||
|
||||
`whichp()` is a predicate function, returns `TRUE` or `FALSE`.
|
||||
|
||||
|
||||
GNU Functions
|
||||
|
||||
@@ -86,6 +86,7 @@ void progress (int percent, int max_width);
|
||||
void progress_simple(int percent);
|
||||
|
||||
char *which (const char *cmd);
|
||||
int whichp (const char *cmd);
|
||||
|
||||
#ifndef touch
|
||||
#include <sys/stat.h> /* utimensat() */
|
||||
|
||||
@@ -81,6 +81,22 @@ char *which(const char *cmd)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Like which(), above, but only answers TRUE(1)/FALSE(0)
|
||||
*/
|
||||
int whichp(const char *cmd)
|
||||
{
|
||||
char *path;
|
||||
|
||||
path = which(cmd);
|
||||
if (path) {
|
||||
free(path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: t
|
||||
|
||||
Reference in New Issue
Block a user