summaryrefslogtreecommitdiffstats
path: root/usr.bin/help
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2002-05-23 14:58:22 +0000
committerjmallett <jmallett@FreeBSD.org>2002-05-23 14:58:22 +0000
commit408260d79e1740439755505258c766b4c5a4b3d3 (patch)
tree04208f81bf731abee12d36334a8aa004da9af443 /usr.bin/help
parent530e4f719b915faa8f37fb8511d597d3d794f677 (diff)
downloadFreeBSD-src-408260d79e1740439755505258c766b4c5a4b3d3.zip
FreeBSD-src-408260d79e1740439755505258c766b4c5a4b3d3.tar.gz
Handle numeric keys by checking a "default" file. Handle number-less keys
by failing, since comparing up to the length of the key (0) against the begin line for a key in the help file will always succeed, and print what is wholly bogus output.
Diffstat (limited to 'usr.bin/help')
-rw-r--r--usr.bin/help/help.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/usr.bin/help/help.c b/usr.bin/help/help.c
index bba2638..91e7f89 100644
--- a/usr.bin/help/help.c
+++ b/usr.bin/help/help.c
@@ -28,6 +28,11 @@ __FBSDID("$FreeBSD$");
*/
#define _PATH_LIBHELP "/usr/lib/help"
+/*
+ * The file we check if all else fails.
+ */
+#define _PATH_DEFAULT _PATH_LIBHELP "/default"
+
int help(const char *);
int
@@ -98,9 +103,20 @@ help(const char *key)
keynumber = key;
key = keyname;
*p = '\0';
- snprintf(path, sizeof(path), _PATH_LIBHELP "/%s", keybase);
+ /*
+ * Try the default help file if we have a numeric key.
+ * Or else, use the non-numeric part of the key.
+ */
+ if (strlen(keybase) == 0) {
+ strlcpy(path, _PATH_DEFAULT, sizeof(path));
+ } else {
+ snprintf(path, sizeof(path), _PATH_LIBHELP "/%s", keybase);
+ }
free(keybase);
numlen = strlen(keynumber);
+ if (!numlen) {
+ goto fail;
+ }
helpfile = fopen(path, "r");
if (helpfile == NULL) {
OpenPOWER on IntegriCloud