summaryrefslogtreecommitdiffstats
path: root/tools/aidl/search_path.cpp
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:31:44 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:31:44 -0800
commit9066cfe9886ac131c34d59ed0e2d287b0e3c0087 (patch)
treed88beb88001f2482911e3d28e43833b50e4b4e97 /tools/aidl/search_path.cpp
parentd83a98f4ce9cfa908f5c54bbd70f03eec07e7553 (diff)
downloadframeworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.zip
frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.tar.gz
frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.tar.bz2
auto import from //depot/cupcake/@135843
Diffstat (limited to 'tools/aidl/search_path.cpp')
-rw-r--r--tools/aidl/search_path.cpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/aidl/search_path.cpp b/tools/aidl/search_path.cpp
new file mode 100644
index 0000000..ffb6cb2
--- /dev/null
+++ b/tools/aidl/search_path.cpp
@@ -0,0 +1,57 @@
+#include <unistd.h>
+#include "search_path.h"
+#include "options.h"
+#include <string.h>
+
+#ifdef HAVE_MS_C_RUNTIME
+#include <io.h>
+#endif
+
+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;
+}
+