@@ -158,13 +158,13 @@ size_t GetThreadCount() {
158
158
// we cannot detect it.
159
159
size_t GetThreadCount () {
160
160
int mib[] = {
161
- CTL_KERN,
162
- KERN_PROC,
163
- KERN_PROC_PID,
164
- getpid (),
161
+ CTL_KERN,
162
+ KERN_PROC,
163
+ KERN_PROC_PID,
164
+ getpid (),
165
165
#ifdef GTEST_OS_NETBSD
166
- sizeof (struct kinfo_proc ),
167
- 1 ,
166
+ sizeof (struct kinfo_proc ),
167
+ 1 ,
168
168
#endif
169
169
};
170
170
u_int miblen = sizeof (mib) / sizeof (mib[0 ]);
@@ -1028,6 +1028,16 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
1028
1028
1029
1029
#if GTEST_HAS_STREAM_REDIRECTION
1030
1030
1031
+ namespace {
1032
+
1033
+ #if defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_IOS)
1034
+ bool EndsWithPathSeparator (const std::string& path) {
1035
+ return !path.empty () && path.back () == GTEST_PATH_SEP_[0 ];
1036
+ }
1037
+ #endif
1038
+
1039
+ } // namespace
1040
+
1031
1041
// Object that captures an output stream (stdout/stderr).
1032
1042
class CapturedStream {
1033
1043
public:
@@ -1064,7 +1074,13 @@ class CapturedStream {
1064
1074
// The location /data/local/tmp is directly accessible from native code.
1065
1075
// '/sdcard' and other variants cannot be relied on, as they are not
1066
1076
// guaranteed to be mounted, or may have a delay in mounting.
1067
- name_template = " /data/local/tmp/" ;
1077
+ //
1078
+ // However, prefer using the TMPDIR environment variable if set, as newer
1079
+ // devices may have /data/local/tmp read-only.
1080
+ name_template = TempDir ();
1081
+ if (!EndsWithPathSeparator (name_template))
1082
+ name_template.push_back (GTEST_PATH_SEP_[0 ]);
1083
+
1068
1084
#elif defined(GTEST_OS_IOS)
1069
1085
char user_temp_dir[PATH_MAX + 1 ];
1070
1086
@@ -1084,7 +1100,7 @@ class CapturedStream {
1084
1100
::confstr (_CS_DARWIN_USER_TEMP_DIR, user_temp_dir, sizeof (user_temp_dir));
1085
1101
1086
1102
name_template = user_temp_dir;
1087
- if (name_template. back () != GTEST_PATH_SEP_[ 0 ] )
1103
+ if (! EndsWithPathSeparator (name_template) )
1088
1104
name_template.push_back (GTEST_PATH_SEP_[0 ]);
1089
1105
#else
1090
1106
name_template = " /tmp/" ;
0 commit comments