| 9 |
|
|
| 10 |
|
#include "copyright.h" |
| 11 |
|
|
| 12 |
< |
#include "standard.h" |
| 12 |
> |
#include <string.h> |
| 13 |
> |
#include <ctype.h> |
| 14 |
> |
#ifndef _WIN32 /* XXX was NIX, do we still compile on Amiga? */ |
| 15 |
> |
#include <pwd.h> |
| 16 |
> |
#include <sys/types.h> |
| 17 |
> |
#endif |
| 18 |
|
|
| 19 |
|
#include "paths.h" |
| 20 |
|
|
| 16 |
– |
#ifndef NIX |
| 17 |
– |
#include <pwd.h> |
| 18 |
– |
extern struct passwd *getpwnam(); |
| 19 |
– |
#endif |
| 21 |
|
|
| 22 |
|
|
| 23 |
+ |
#ifdef _WIN32 |
| 24 |
+ |
static char * |
| 25 |
+ |
core_getpath /* wrapped below: expand fname, return full path */ |
| 26 |
+ |
#else |
| 27 |
|
char * |
| 28 |
< |
getpath(fname, searchpath, mode) /* expand fname, return full path */ |
| 29 |
< |
register char *fname; |
| 30 |
< |
register char *searchpath; |
| 31 |
< |
int mode; |
| 28 |
> |
getpath /* expand fname, return full path */ |
| 29 |
> |
#endif |
| 30 |
> |
( |
| 31 |
> |
register char *fname, |
| 32 |
> |
register char *searchpath, |
| 33 |
> |
int mode |
| 34 |
> |
) |
| 35 |
|
{ |
| 36 |
< |
#ifndef NIX |
| 36 |
> |
#ifndef _WIN32 /* XXX was NIX, do we still compile on Amiga? */ |
| 37 |
|
struct passwd *pwent; |
| 38 |
|
#endif |
| 39 |
< |
static char pname[MAXPATH]; |
| 39 |
> |
static char pname[PATH_MAX]; |
| 40 |
|
register char *cp; |
| 41 |
|
|
| 42 |
< |
if (fname == NULL) |
| 35 |
< |
return(NULL); |
| 42 |
> |
if (fname == NULL) { return(NULL); } |
| 43 |
|
|
| 44 |
|
pname[0] = '\0'; /* check for full specification */ |
| 45 |
< |
switch (*fname) { |
| 46 |
< |
CASEDIRSEP: /* relative to root */ |
| 47 |
< |
case '.': /* relative to cwd */ |
| 48 |
< |
strcpy(pname, fname); |
| 49 |
< |
break; |
| 50 |
< |
#ifndef NIX |
| 51 |
< |
case '~': /* relative to home directory */ |
| 52 |
< |
fname++; |
| 53 |
< |
if (*fname == '\0' || ISDIRSEP(*fname)) { /* ours */ |
| 54 |
< |
if ((cp = getenv("HOME")) == NULL) |
| 55 |
< |
return(NULL); |
| 56 |
< |
strcpy(pname, cp); |
| 57 |
< |
strcat(pname, fname); |
| 58 |
< |
break; |
| 59 |
< |
} |
| 60 |
< |
cp = pname; /* user */ |
| 54 |
< |
do |
| 55 |
< |
*cp++ = *fname++; |
| 56 |
< |
while (*fname && !ISDIRSEP(*fname)); |
| 57 |
< |
*cp = '\0'; |
| 58 |
< |
if ((pwent = getpwnam(pname)) == NULL) |
| 59 |
< |
return(NULL); |
| 60 |
< |
strcpy(pname, pwent->pw_dir); |
| 61 |
< |
strcat(pname, fname); |
| 62 |
< |
break; |
| 45 |
> |
|
| 46 |
> |
if (ISABS(fname)) { /* Can't use CASEDIRSEP below on Windows */ |
| 47 |
> |
strncpy(pname, fname, sizeof(pname)-1); |
| 48 |
> |
} else { |
| 49 |
> |
switch (*fname) { |
| 50 |
> |
/* XXX This doesn't work on Windows */ |
| 51 |
> |
/* CASEDIRSEP: */ /* relative to root */ |
| 52 |
> |
case '.': /* relative to cwd */ |
| 53 |
> |
strncpy(pname, fname, sizeof(pname)-1); |
| 54 |
> |
break; |
| 55 |
> |
case '~': /* relative to home directory */ |
| 56 |
> |
fname++; |
| 57 |
> |
if (*fname == '\0' || ISDIRSEP(*fname)) { /* ours */ |
| 58 |
> |
if ((cp = getenv("HOME")) == NULL) |
| 59 |
> |
#ifdef _WIN32 /* Windows sometimes uses a different var name */ |
| 60 |
> |
if ((cp = getenv("HOMEDIR")) == NULL) |
| 61 |
|
#endif |
| 62 |