1 |
// -*- C++ -*- |
// -*- C++ -*- |
2 |
/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003 |
/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2003, 2005 |
3 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
4 |
Written by James Clark (jjc@jclark.com) |
Written by James Clark (jjc@jclark.com) |
5 |
|
|
28 |
#include "searchpath.h" |
#include "searchpath.h" |
29 |
#include "nonposix.h" |
#include "nonposix.h" |
30 |
|
|
31 |
|
#ifdef _WIN32 |
32 |
|
# include "relocate.h" |
33 |
|
#else |
34 |
|
# define relocate(path) strsave(path) |
35 |
|
#endif |
36 |
|
|
37 |
search_path::search_path(const char *envvar, const char *standard, |
search_path::search_path(const char *envvar, const char *standard, |
38 |
int add_home, int add_current) |
int add_home, int add_current) |
39 |
{ |
{ |
114 |
if (!end) |
if (!end) |
115 |
end = strchr(p, '\0'); |
end = strchr(p, '\0'); |
116 |
int need_slash = end > p && strchr(DIR_SEPS, end[-1]) == 0; |
int need_slash = end > p && strchr(DIR_SEPS, end[-1]) == 0; |
117 |
char *path = new char[(end - p) + need_slash + namelen + 1]; |
char *origpath = new char[(end - p) + need_slash + namelen + 1]; |
118 |
memcpy(path, p, end - p); |
memcpy(origpath, p, end - p); |
119 |
if (need_slash) |
if (need_slash) |
120 |
path[end - p] = '/'; |
origpath[end - p] = '/'; |
121 |
strcpy(path + (end - p) + need_slash, name); |
strcpy(origpath + (end - p) + need_slash, name); |
122 |
|
#if 0 |
123 |
|
fprintf(stderr, "origpath `%s'\n", origpath); |
124 |
|
#endif |
125 |
|
char *path = relocate(origpath); |
126 |
|
a_delete origpath; |
127 |
#if 0 |
#if 0 |
128 |
fprintf(stderr, "trying `%s'\n", path); |
fprintf(stderr, "trying `%s'\n", path); |
129 |
#endif |
#endif |
171 |
if (!end) |
if (!end) |
172 |
end = strchr(p, '\0'); |
end = strchr(p, '\0'); |
173 |
int need_slash = end > p && strchr(DIR_SEPS, end[-1]) == 0; |
int need_slash = end > p && strchr(DIR_SEPS, end[-1]) == 0; |
174 |
char *path = new char[(end - p) + need_slash + namelen + 1]; |
char *origpath = new char[(end - p) + need_slash + namelen + 1]; |
175 |
memcpy(path, p, end - p); |
memcpy(origpath, p, end - p); |
176 |
if (need_slash) |
if (need_slash) |
177 |
path[end - p] = '/'; |
origpath[end - p] = '/'; |
178 |
strcpy(path + (end - p) + need_slash, name); |
strcpy(origpath + (end - p) + need_slash, name); |
179 |
|
#if 0 |
180 |
|
fprintf(stderr, "origpath `%s'\n", origpath); |
181 |
|
#endif |
182 |
|
char *path = relocate(origpath); |
183 |
|
a_delete origpath; |
184 |
#if 0 |
#if 0 |
185 |
fprintf(stderr, "trying `%s'\n", path); |
fprintf(stderr, "trying `%s'\n", path); |
186 |
#endif |
#endif |