hack.diff

uqs, 11/15/2009 05:21 PM

Download (1.89 KB)

View differences:

games/hack/hack.unix.c
19 19

  
20 20
#include	<sys/types.h>		/* for time_t and stat */
21 21
#include	<sys/stat.h>
22
#include	<sys/param.h>
22 23
#include	<time.h>
24
#include	<err.h>
23 25

  
24 26
static struct tm	*getlt(void);
25 27
static bool		 veryold(int);
......
95 97
void
96 98
gethdate(const char *name)
97 99
{
98
/* old version - for people short of space */
99
char *np;
100

  
101
	name = "/usr/games/hide/hack";
102
	if(stat(name, &hbuf))
103
		error("Cannot get status of %s.",
104
			(np = rindex(name, '/')) ? np+1 : name);
100
	char *p, *np, *path;
101
	char filename[MAXPATHLEN+1];
102

  
103
	if (strchr(name, '/') != NULL || (p = getenv("PATH")) == NULL)
104
		p = "";
105
	np = path = strdup(p);	/* Make a copy for strsep. */
106
	if (path == NULL)
107
		err(1, NULL);
108

  
109
	for (;;) {
110
		if ((p = strsep(&np, ":")) == NULL)
111
			break;
112
		if (*p == '\0')			/* :: */
113
			(void) strlcpy(filename, name, sizeof(filename));
114
		else
115
			(void) snprintf(filename, sizeof(filename),
116
			    "%s/%s", p, name);
117

  
118
		if (stat(filename, &hbuf) == 0) {
119
			free(path);
120
			return;
121
		}
122
	}
123
	error("Cannot get status of %s.",
124
		(p = strrchr(name, '/')) ? p+1 : name);
125
	free(path);
105 126
}
106 127

  
107 128
bool
108
-