aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-02-14 16:14:07 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2013-02-14 16:14:07 -0800
commit0f1ce3dd0b880b6ae0cf7f5413702b8ef542efb2 (patch)
treeeba4352a2914f712c1d077e4a68b68c19a766c9a
parentdac6030289c87010b31bad60b769399b387ef15c (diff)
parent8c212ebe53bb2baab3575f03069016f1fb11e449 (diff)
downloadgtest-jb-mr2.0.0-release.tar.gz
# Via Elliott Hughes (1) and Gerrit Code Review (1) * commit '8c212ebe53bb2baab3575f03069016f1fb11e449': Only use $EXTERNAL_STORAGE if it exists and is writable.
-rw-r--r--src/gtest-port.cc17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/gtest-port.cc b/src/gtest-port.cc
index 01c5e1e..f914dbc 100644
--- a/src/gtest-port.cc
+++ b/src/gtest-port.cc
@@ -508,16 +508,23 @@ class CapturedStream {
// ANDROID
#elif GTEST_OS_LINUX_ANDROID
// Get $EXTERNAL_STORAGE from the environment, since this can change
- // for shell users (fallback is still /sdcard, but this probably will
- // never work properly again).
- ::std::string external_storage = "/sdcard";
+ // for shell users (fallback is /data/nativetest, for emulator users).
+ ::std::string external_storage = "/data/nativetest";
char *sdcard_path = getenv("EXTERNAL_STORAGE");
- if (sdcard_path) {
- external_storage = sdcard_path;
+ if (sdcard_path != NULL) {
+ // Check that $EXTERNAL_STORAGE exists and is writable before trying to use it.
+ struct stat sb;
+ if (stat(sdcard_path, &sb) != -1) {
+ if ((sb.st_mode & S_IWUSR) != 0) {
+ external_storage = sdcard_path;
+ }
+ }
}
external_storage += "/captured_stderr.XXXXXX";
char *name_template = strdup(external_storage.c_str());
const int captured_fd = mkstemp(name_template);
+ GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file "
+ << name_template;
filename_ = name_template;
free(name_template);
name_template = NULL;