summaryrefslogtreecommitdiff
path: root/rsScriptC.cpp
diff options
context:
space:
mode:
authorChris Wailes <chriswailes@google.com>2014-08-11 17:30:51 -0700
committerStephen Hines <srhines@google.com>2014-08-20 16:24:00 -0700
commit6847e73314e13aa02231268cca245a81eb0539ca (patch)
tree5e7ee3e65eb25bb10c73c776c9c55e488ab1f82e /rsScriptC.cpp
parent74f0b28d3314a21c26d8bb2dc06efb835d86bfcb (diff)
downloadrs-6847e73314e13aa02231268cca245a81eb0539ca.tar.gz
Replace android::String8 with std::string
Change-Id: I5b2b6d3e38afd0b040f0a584613745206bf01ba0
Diffstat (limited to 'rsScriptC.cpp')
-rw-r--r--rsScriptC.cpp54
1 files changed, 41 insertions, 13 deletions
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index 2958e84e..96a771f1 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -31,6 +31,19 @@
#include <sys/stat.h>
+#ifdef USE_MINGW
+/* Define the default path separator for the platform. */
+#define OS_PATH_SEPARATOR '\\'
+#define OS_PATH_SEPARATOR_STR "\\"
+
+#else /* not USE_MINGW */
+
+/* Define the default path separator for the platform. */
+#define OS_PATH_SEPARATOR '/'
+#define OS_PATH_SEPARATOR_STR "/"
+
+#endif
+
using namespace android;
using namespace android::renderscript;
@@ -60,29 +73,45 @@ ScriptC::~ScriptC() {
#ifndef RS_COMPATIBILITY_LIB
bool ScriptC::createCacheDir(const char *cacheDir) {
- String8 cacheDirString, currentDir;
+ std::string currentDir;
+ const std::string cacheDirString(cacheDir);
+
struct stat statBuf;
int statReturn = stat(cacheDir, &statBuf);
if (!statReturn) {
return true;
}
- // String8 path functions strip leading /'s
- // insert if necessary
- if (cacheDir[0] == '/') {
- currentDir += "/";
- }
+ // Start from the beginning of the cacheDirString.
+ int currPos = 0;
+
+ // Reserve space in currentDir for the entire cacheDir path.
+ currentDir.reserve(cacheDirString.length());
+
+ while (currPos >= 0) {
+ /*
+ * The character at currPos should be a path separator. We need to look
+ * for the next one.
+ */
+ int nextPos = cacheDirString.find(OS_PATH_SEPARATOR_STR, currPos + 1);
+
+ if (nextPos > 0) {
+ // A new path separator has been found.
+ currentDir += cacheDirString.substr(currPos, nextPos - currPos);
+ } else {
+ // There are no more path separators.
+ currentDir += cacheDirString.substr(currPos);
+ }
+
+ currPos = nextPos;
- cacheDirString.setPathName(cacheDir);
+ statReturn = stat(currentDir.c_str(), &statBuf);
- while (cacheDirString.length()) {
- currentDir += (cacheDirString.walkPath(&cacheDirString));
- statReturn = stat(currentDir.string(), &statBuf);
if (statReturn) {
if (errno == ENOENT) {
- if (mkdir(currentDir.string(), S_IRUSR | S_IWUSR | S_IXUSR)) {
+ if (mkdir(currentDir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR)) {
ALOGE("Couldn't create cache directory: %s",
- currentDir.string());
+ currentDir.c_str());
ALOGE("Error: %s", strerror(errno));
return false;
}
@@ -91,7 +120,6 @@ bool ScriptC::createCacheDir(const char *cacheDir) {
return false;
}
}
- currentDir += "/";
}
return true;
}