From c91833b608a45e8bca8bd985725ce3bfa716466a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ulrich=20Sp=C3=B6rlein?= Date: Sun, 15 Nov 2009 17:17:02 +0100 Subject: [PATCH] hack(6): fix very old mis-merge by restoring code from OpenBSD If you look at the CVS history for this file, you will see that the code in question tried to find the provided name in the path, not just a fixed location (that could be coded more easily). Restore the OpenBSD version of this code, which was cleaned up, already --- games/hack/hack.unix.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/games/hack/hack.unix.c b/games/hack/hack.unix.c index 318d88b353..6810cba5cd 100644 --- a/games/hack/hack.unix.c +++ b/games/hack/hack.unix.c @@ -19,7 +19,9 @@ #include /* for time_t and stat */ #include +#include #include +#include static struct tm *getlt(void); static bool veryold(int); @@ -95,13 +97,32 @@ struct stat buf, hbuf; void gethdate(const char *name) { -/* old version - for people short of space */ -char *np; - - name = "/usr/games/hide/hack"; - if(stat(name, &hbuf)) - error("Cannot get status of %s.", - (np = rindex(name, '/')) ? np+1 : name); + char *p, *np, *path; + char filename[MAXPATHLEN+1]; + + if (strchr(name, '/') != NULL || (p = getenv("PATH")) == NULL) + p = ""; + np = path = strdup(p); /* Make a copy for strsep. */ + if (path == NULL) + err(1, NULL); + + for (;;) { + if ((p = strsep(&np, ":")) == NULL) + break; + if (*p == '\0') /* :: */ + (void) strlcpy(filename, name, sizeof(filename)); + else + (void) snprintf(filename, sizeof(filename), + "%s/%s", p, name); + + if (stat(filename, &hbuf) == 0) { + free(path); + return; + } + } + error("Cannot get status of %s.", + (p = strrchr(name, '/')) ? p+1 : name); + free(path); } bool -- 2.41.0