/*
* If we have "bunzip2 -q", try using that.
*/
- if (!canRunCommand("bunzip2 -h")) {
+ if (!canRunCommand("bunzip2 -h", NULL)) {
skipping("Can't run bunzip2 program on this platform");
return;
}
/* Return true if this platform can run the "gzip" program. */
int canGzip(void);
-/* Return true if this platform can run the specified command. */
-int canRunCommand(const char *);
+/* Return true if this platform can run the specified command.
+ *
+ * Result can be optionally cached with `*tested`:
+ * - 0 if not tested yet
+ * - <0 if already tested negative
+ * - >0 if already tested positive
+ */
+int canRunCommand(const char *cmd, int *tested);
/* Return true if this platform can run the "lrzip" program. */
int canLrzip(void);
#else
static const char *redirectArgs = ">/dev/null 2>/dev/null"; /* POSIX 'sh' */
#endif
+
+/*
+ * Can this platform run the specified command?
+ */
+int
+canRunCommand(const char *cmd, int *tested)
+{
+ int value = tested ? *tested : 0;
+ if (!value) {
+ value = systemf("%s %s", cmd, redirectArgs) ? -1 : +1;
+ if (tested)
+ *tested = value;
+ }
+ return (value > 0);
+}
+
+#define CAN_RUN_FUNC(Program, Command) \
+ int can##Program(void) { \
+ static int tested = 0; \
+ return canRunCommand((Command), &tested); \
+ }
+
/*
* Can this platform run the bzip2 program?
*/
/*
* Can this platform run the lrzip program?
*/
-int
-canRunCommand(const char *cmd)
-{
- static int tested = 0, value = 0;
- if (!tested) {
- tested = 1;
- if (systemf("%s %s", cmd, redirectArgs) == 0)
- value = 1;
- }
- return (value);
-}
-
int
canLrzip(void)
{