2 #include "search_path.h"
6 #ifdef HAVE_MS_C_RUNTIME
10 static vector<string> g_importPaths;
13 set_import_paths(const vector<string>& importPaths)
15 g_importPaths = importPaths;
19 find_import_file(const char* given)
21 string expected = given;
23 int N = expected.length();
24 for (int i=0; i<N; i++) {
27 expected[i] = OS_PATH_SEPARATOR;
32 vector<string>& paths = g_importPaths;
33 for (vector<string>::iterator it=paths.begin(); it!=paths.end(); it++) {
37 f += OS_PATH_SEPARATOR;
39 else if (f[f.size()-1] != OS_PATH_SEPARATOR) {
40 f += OS_PATH_SEPARATOR;
44 #ifdef HAVE_MS_C_RUNTIME
45 /* check that the file exists and is not write-only */
46 if (0 == _access(f.c_str(), 0) && /* mode 0=exist */
47 0 == _access(f.c_str(), 4) ) { /* mode 4=readable */
49 if (0 == access(f.c_str(), R_OK)) {
51 return strdup(f.c_str());