git: a5948d40ad06 - main - stand: Add interp_has_builtin_cmd to see if we have a command

From: Warner Losh <imp_at_FreeBSD.org>
Date: Thu, 01 Sep 2022 17:11:20 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=a5948d40ad060140bf5b995f5409458a18ced0ce

commit a5948d40ad060140bf5b995f5409458a18ced0ce
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2022-09-01 17:06:01 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2022-09-01 17:08:19 +0000

    stand: Add interp_has_builtin_cmd to see if we have a command
    
    interp_has_builtin_cmd() will try to lookup the passed in command and
    returns true if it was found, false otherwise.
    
    Sponsored by:           Netflix
    Differential Revision:  https://reviews.freebsd.org/D36364
---
 stand/common/bootstrap.h | 1 +
 stand/common/interp.c    | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/stand/common/bootstrap.h b/stand/common/bootstrap.h
index 9c62a49b0da7..cb1c96dc3b69 100644
--- a/stand/common/bootstrap.h
+++ b/stand/common/bootstrap.h
@@ -52,6 +52,7 @@ extern char	command_errbuf[COMMAND_ERRBUFSZ];
 void	interact(void);
 void	interp_emit_prompt(void);
 int	interp_builtin_cmd(int argc, char *argv[]);
+bool	interp_has_builtin_cmd(const char *cmd);
 
 /* Called by interp.c for interp_*.c embedded interpreters */
 int	interp_include(const char *);	/* Execute commands from filename */
diff --git a/stand/common/interp.c b/stand/common/interp.c
index 227e7ad91e29..8b779fb7a5e9 100644
--- a/stand/common/interp.c
+++ b/stand/common/interp.c
@@ -190,3 +190,12 @@ interp_builtin_cmd(int argc, char *argv[])
 	}
 	return (result);
 }
+
+/*
+ * Return true if the builtin command exists
+ */
+bool
+interp_has_builtin_cmd(const char *cmd)
+{
+	return (interp_lookup_cmd(cmd) != NULL);
+}