summaryrefslogtreecommitdiffstats
path: root/base/include
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2018-11-12 12:29:14 -0800
committerMark Salyzyn <salyzyn@google.com>2018-11-13 12:44:21 -0800
commit0790b2465ab8f2f9b0d86869a896d63358b00099 (patch)
treef09ed69dbd5f1401a42ab844471b83e2e76fa44a /base/include
parentc55fab4a59cfa461857c6a61d8a0f1ae4591900c (diff)
downloadsystem_core-0790b2465ab8f2f9b0d86869a896d63358b00099.tar.gz
system_core-0790b2465ab8f2f9b0d86869a896d63358b00099.tar.bz2
system_core-0790b2465ab8f2f9b0d86869a896d63358b00099.zip
base: move TemporaryFile and TemporaryDir to android-base/file.h
Allow a wider legitimate audience to use TemporaryFile and TemporaryDir by moving them from android-base/test_utils.h to android-base/file.h. Test: compile Bug: 119313545 Change-Id: Ie558c5873ce5b3937914918b6bfb427e5b61d0da
Diffstat (limited to 'base/include')
-rw-r--r--base/include/android-base/file.h38
-rw-r--r--base/include/android-base/test_utils.h37
2 files changed, 39 insertions, 36 deletions
diff --git a/base/include/android-base/file.h b/base/include/android-base/file.h
index 86d537d76..80d71346d 100644
--- a/base/include/android-base/file.h
+++ b/base/include/android-base/file.h
@@ -18,8 +18,10 @@
#include <sys/stat.h>
#include <sys/types.h>
+
#include <string>
+#include <android-base/macros.h>
#include "android-base/off64_t.h"
#if !defined(_WIN32) && !defined(O_BINARY)
@@ -32,6 +34,42 @@
#define O_CLOEXEC O_NOINHERIT
#endif
+class TemporaryFile {
+ public:
+ TemporaryFile();
+ explicit TemporaryFile(const std::string& tmp_dir);
+ ~TemporaryFile();
+
+ // Release the ownership of fd, caller is reponsible for closing the
+ // fd or stream properly.
+ int release();
+ // Don't remove the temporary file in the destructor.
+ void DoNotRemove() { remove_file_ = false; }
+
+ int fd;
+ char path[1024];
+
+ private:
+ void init(const std::string& tmp_dir);
+
+ bool remove_file_ = true;
+
+ DISALLOW_COPY_AND_ASSIGN(TemporaryFile);
+};
+
+class TemporaryDir {
+ public:
+ TemporaryDir();
+ ~TemporaryDir();
+
+ char path[1024];
+
+ private:
+ bool init(const std::string& tmp_dir);
+
+ DISALLOW_COPY_AND_ASSIGN(TemporaryDir);
+};
+
namespace android {
namespace base {
diff --git a/base/include/android-base/test_utils.h b/base/include/android-base/test_utils.h
index 2abe68e02..b20f27846 100644
--- a/base/include/android-base/test_utils.h
+++ b/base/include/android-base/test_utils.h
@@ -19,44 +19,9 @@
#include <regex>
#include <string>
+#include <android-base/file.h>
#include <android-base/macros.h>
-class TemporaryFile {
- public:
- TemporaryFile();
- explicit TemporaryFile(const std::string& tmp_dir);
- ~TemporaryFile();
-
- // Release the ownership of fd, caller is reponsible for closing the
- // fd or stream properly.
- int release();
- // Don't remove the temporary file in the destructor.
- void DoNotRemove() { remove_file_ = false; }
-
- int fd;
- char path[1024];
-
- private:
- void init(const std::string& tmp_dir);
-
- bool remove_file_ = true;
-
- DISALLOW_COPY_AND_ASSIGN(TemporaryFile);
-};
-
-class TemporaryDir {
- public:
- TemporaryDir();
- ~TemporaryDir();
-
- char path[1024];
-
- private:
- bool init(const std::string& tmp_dir);
-
- DISALLOW_COPY_AND_ASSIGN(TemporaryDir);
-};
-
class CapturedStdFd {
public:
CapturedStdFd(int std_fd);