summaryrefslogtreecommitdiffstats
path: root/base/android
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-18 19:34:34 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-18 19:34:34 +0000
commitcd1990648f5b2c00274f7f49491a2a55c4f64cb8 (patch)
tree19c75a936deba61fa67dea7856a151ded8e37b9d /base/android
parenta5152777f762a86da0445fe4e29c255245251aaa (diff)
downloadchromium_src-cd1990648f5b2c00274f7f49491a2a55c4f64cb8.zip
chromium_src-cd1990648f5b2c00274f7f49491a2a55c4f64cb8.tar.gz
chromium_src-cd1990648f5b2c00274f7f49491a2a55c4f64cb8.tar.bz2
Move CreateFIFO() and RedirectStream() from testing/android/ to base/android/.
They will be used by content_shell to create the necessary fifos when running layout tests. BUG=232044 TBR=darin,yfriedman Review URL: https://chromiumcodereview.appspot.com/16599008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207060 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/android')
-rw-r--r--base/android/fifo_utils.cc25
-rw-r--r--base/android/fifo_utils.h32
2 files changed, 57 insertions, 0 deletions
diff --git a/base/android/fifo_utils.cc b/base/android/fifo_utils.cc
new file mode 100644
index 0000000..8f3e95f
--- /dev/null
+++ b/base/android/fifo_utils.cc
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/android/fifo_utils.h"
+
+#include <sys/stat.h>
+
+#include "base/files/file_path.h"
+
+namespace base {
+namespace android {
+
+bool CreateFIFO(const FilePath& path, int mode) {
+ // Default permissions for mkfifo() is ignored, chmod() is required.
+ return mkfifo(path.value().c_str(), mode) == 0 &&
+ chmod(path.value().c_str(), mode) == 0;
+}
+
+bool RedirectStream(FILE* stream, const FilePath& path, const char* mode) {
+ return freopen(path.value().c_str(), mode, stream) != NULL;
+}
+
+} // namespace android
+} // namespace base
diff --git a/base/android/fifo_utils.h b/base/android/fifo_utils.h
new file mode 100644
index 0000000..1936def
--- /dev/null
+++ b/base/android/fifo_utils.h
@@ -0,0 +1,32 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_ANDROID_FIFO_UTILS_H_
+#define BASE_ANDROID_FIFO_UTILS_H_
+
+#include <stdio.h>
+
+#include "base/base_export.h"
+#include "base/basictypes.h"
+
+namespace base {
+
+class FilePath;
+
+namespace android {
+
+// Creates a fifo at the given |path| with POSIX permissions set to |mode|,
+// returning true if it was successfully created and permissions were set.
+BASE_EXPORT bool CreateFIFO(const FilePath& path, int mode);
+
+// Redirects the |stream| to the file provided by |path| with |mode|
+// permissions, returning true if successful.
+BASE_EXPORT bool RedirectStream(FILE* stream,
+ const FilePath& path,
+ const char* mode);
+
+} // namespace android
+} // namespace base
+
+#endif // BASE_ANDROID_FIFO_UTILS_H_