1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
8 |
|
* getpath.c - function to search for file in a list of directories |
9 |
|
*/ |
10 |
|
|
11 |
< |
#define NULL 0 |
11 |
> |
#include "standard.h" |
12 |
|
|
13 |
< |
#include <pwd.h> |
13 |
> |
#include "paths.h" |
14 |
|
|
15 |
< |
extern char *strcpy(), *strcat(), *getenv(); |
15 |
> |
#ifndef NIX |
16 |
> |
#include <pwd.h> |
17 |
|
extern struct passwd *getpwnam(); |
18 |
+ |
#endif |
19 |
|
|
20 |
|
|
21 |
|
char * |
24 |
|
register char *searchpath; |
25 |
|
int mode; |
26 |
|
{ |
27 |
< |
static char pname[256]; |
27 |
> |
#ifndef NIX |
28 |
|
struct passwd *pwent; |
29 |
+ |
#endif |
30 |
+ |
static char pname[MAXPATH]; |
31 |
|
register char *cp; |
32 |
|
|
33 |
|
if (fname == NULL) |
34 |
|
return(NULL); |
35 |
|
|
36 |
|
switch (*fname) { |
37 |
< |
case '/': /* relative to root */ |
37 |
> |
CASEDIRSEP: /* relative to root */ |
38 |
|
case '.': /* relative to cwd */ |
39 |
|
strcpy(pname, fname); |
40 |
|
return(pname); |
41 |
+ |
#ifndef NIX |
42 |
|
case '~': /* relative to home directory */ |
43 |
|
fname++; |
44 |
< |
if (*fname == '\0' || *fname == '/') { /* ours */ |
44 |
> |
if (*fname == '\0' || ISDIRSEP(*fname)) { /* ours */ |
45 |
|
if ((cp = getenv("HOME")) == NULL) |
46 |
|
return(NULL); |
47 |
|
strcpy(pname, cp); |
51 |
|
cp = pname; /* user */ |
52 |
|
do |
53 |
|
*cp++ = *fname++; |
54 |
< |
while (*fname && *fname != '/'); |
54 |
> |
while (*fname && !ISDIRSEP(*fname)); |
55 |
|
*cp = '\0'; |
56 |
|
if ((pwent = getpwnam(pname)) == NULL) |
57 |
|
return(NULL); |
58 |
|
strcpy(pname, pwent->pw_dir); |
59 |
|
strcat(pname, fname); |
60 |
|
return(pname); |
61 |
+ |
#endif |
62 |
|
} |
63 |
|
|
64 |
|
if (searchpath == NULL) { /* don't search */ |
68 |
|
/* check search path */ |
69 |
|
do { |
70 |
|
cp = pname; |
71 |
< |
while (*searchpath && (*cp = *searchpath++) != ':') |
71 |
> |
while (*searchpath && (*cp = *searchpath++) != PATHSEP) |
72 |
|
cp++; |
73 |
< |
if (cp > pname && cp[-1] != '/') |
74 |
< |
*cp++ = '/'; |
73 |
> |
if (cp > pname && !ISDIRSEP(cp[-1])) |
74 |
> |
*cp++ = DIRSEP; |
75 |
|
strcpy(cp, fname); |
76 |
|
if (access(pname, mode) == 0) /* file accessable? */ |
77 |
|
return(pname); |