-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsearch_path.cpp
More file actions
78 lines (67 loc) · 1.83 KB
/
search_path.cpp
File metadata and controls
78 lines (67 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* iFeelSmart
*
* Copyright © 2012-2013, iFeelSmart.
*
*
* GNU Lesser General Public License Usage
* This file may be used under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation and
* appearing in the file LICENSE.LGPL included in the packaging of this
* file. Please review the following information to ensure the GNU Lesser
* General Public License version 2.1 requirements will be met:
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
*
* File: search_path.cpp
*
*/
#include <unistd.h>
#include "search_path.h"
#include "options.h"
#include <string.h>
#ifdef HAVE_MS_C_RUNTIME
#include <io.h>
#endif
// <GRT>
#define OS_PATH_SEPARATOR '/'
// </GRT>
static vector<string> g_importPaths;
void
set_import_paths(const vector<string>& importPaths)
{
g_importPaths = importPaths;
}
char*
find_import_file(const char* given)
{
string expected = given;
int N = expected.length();
for (int i=0; i<N; i++) {
char c = expected[i];
if (c == '.') {
expected[i] = OS_PATH_SEPARATOR;
}
}
expected += ".aidl";
vector<string>& paths = g_importPaths;
for (vector<string>::iterator it=paths.begin(); it!=paths.end(); it++) {
string f = *it;
if (f.size() == 0) {
f = ".";
f += OS_PATH_SEPARATOR;
}
else if (f[f.size()-1] != OS_PATH_SEPARATOR) {
f += OS_PATH_SEPARATOR;
}
f.append(expected);
#ifdef HAVE_MS_C_RUNTIME
/* check that the file exists and is not write-only */
if (0 == _access(f.c_str(), 0) && /* mode 0=exist */
0 == _access(f.c_str(), 4) ) { /* mode 4=readable */
#else
if (0 == access(f.c_str(), R_OK)) {
#endif
return strdup(f.c_str());
}
}
return NULL;
}