Bug 785026 - Merge file_util_linux.cc into file_util_posix.cc. r=cjones
authorJan Beich <jbeich@tormail.org>
Sat, 25 Aug 2012 22:29:06 -0400
changeset 105504 f551e52160e062737ea77c0b1eece31000c81ddd
parent 105503 8a566c3bff64acba851640a8919610e35452202b
child 105505 c4f20a024113801c6df7037d6cbb391f8fe96f4d
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerscjones
bugs785026
milestone17.0a1
Bug 785026 - Merge file_util_linux.cc into file_util_posix.cc. r=cjones
ipc/chromium/Makefile.in
ipc/chromium/src/base/file_util_linux.cc
ipc/chromium/src/base/file_util_posix.cc
--- a/ipc/chromium/Makefile.in
+++ b/ipc/chromium/Makefile.in
@@ -210,17 +210,16 @@ CPPSRCS += \
 
 endif # } OS_MACOSX
 
 ifdef OS_LINUX # {
 
 CPPSRCS += \
   atomicops_internals_x86_gcc.cc \
   base_paths_linux.cc \
-  file_util_linux.cc \
   file_version_info_linux.cc \
   idle_timer_none.cc \
   process_util_linux.cc \
   time_posix.cc \
   $(NULL)
 
 ifdef MOZ_ENABLE_GTK2
 CPPSRCS += \
deleted file mode 100644
--- a/ipc/chromium/src/base/file_util_linux.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) 2006-2008 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/file_util.h"
-
-#include <fcntl.h>
-#if defined(ANDROID) || defined(OS_POSIX)
-#include <unistd.h>
-#endif
-
-#include <string>
-#include <vector>
-
-#include "base/eintr_wrapper.h"
-#include "base/file_path.h"
-#include "base/string_util.h"
-
-namespace file_util {
-
-bool GetTempDir(FilePath* path) {
-  const char* tmp = getenv("TMPDIR");
-  if (tmp)
-    *path = FilePath(tmp);
-  else
-    *path = FilePath("/tmp");
-  return true;
-}
-
-bool GetShmemTempDir(FilePath* path) {
-#ifdef ANDROID
-  return GetTempDir(path);
-#else
-  *path = FilePath("/dev/shm");
-  return true;
-#endif
-}
-
-bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
-  int infile = open(from_path.value().c_str(), O_RDONLY);
-  if (infile < 0)
-    return false;
-
-  int outfile = creat(to_path.value().c_str(), 0666);
-  if (outfile < 0) {
-    close(infile);
-    return false;
-  }
-
-  const size_t kBufferSize = 32768;
-  std::vector<char> buffer(kBufferSize);
-  bool result = true;
-
-  while (result) {
-    ssize_t bytes_read = HANDLE_EINTR(read(infile, &buffer[0], buffer.size()));
-    if (bytes_read < 0) {
-      result = false;
-      break;
-    }
-    if (bytes_read == 0)
-      break;
-    // Allow for partial writes
-    ssize_t bytes_written_per_read = 0;
-    do {
-      ssize_t bytes_written_partial = HANDLE_EINTR(write(
-          outfile,
-          &buffer[bytes_written_per_read],
-          bytes_read - bytes_written_per_read));
-      if (bytes_written_partial < 0) {
-        result = false;
-        break;
-      }
-      bytes_written_per_read += bytes_written_partial;
-    } while (bytes_written_per_read < bytes_read);
-  }
-
-  if (HANDLE_EINTR(close(infile)) < 0)
-    result = false;
-  if (HANDLE_EINTR(close(outfile)) < 0)
-    result = false;
-
-  return result;
-}
-
-}  // namespace file_util
--- a/ipc/chromium/src/base/file_util_posix.cc
+++ b/ipc/chromium/src/base/file_util_posix.cc
@@ -17,16 +17,18 @@
 #include <sys/errno.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <time.h>
 #include <unistd.h>
 
 #include <fstream>
+#include <string>
+#include <vector>
 
 #include "base/basictypes.h"
 #include "base/eintr_wrapper.h"
 #include "base/file_path.h"
 #include "base/logging.h"
 #include "base/string_util.h"
 #include "base/time.h"
 
@@ -514,16 +516,82 @@ bool GetCurrentDirectory(FilePath* dir) 
 }
 
 // Sets the current working directory for the process.
 bool SetCurrentDirectory(const FilePath& path) {
   int ret = chdir(path.value().c_str());
   return !ret;
 }
 
+#if !defined(OS_MACOSX)
+bool GetTempDir(FilePath* path) {
+  const char* tmp = getenv("TMPDIR");
+  if (tmp)
+    *path = FilePath(tmp);
+  else
+    *path = FilePath("/tmp");
+  return true;
+}
+
+bool GetShmemTempDir(FilePath* path) {
+#if defined(OS_LINUX) && !defined(ANDROID)
+  *path = FilePath("/dev/shm");
+  return true;
+#else
+  return GetTempDir(path);
+#endif
+}
+
+bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
+  int infile = open(from_path.value().c_str(), O_RDONLY);
+  if (infile < 0)
+    return false;
+
+  int outfile = creat(to_path.value().c_str(), 0666);
+  if (outfile < 0) {
+    close(infile);
+    return false;
+  }
+
+  const size_t kBufferSize = 32768;
+  std::vector<char> buffer(kBufferSize);
+  bool result = true;
+
+  while (result) {
+    ssize_t bytes_read = HANDLE_EINTR(read(infile, &buffer[0], buffer.size()));
+    if (bytes_read < 0) {
+      result = false;
+      break;
+    }
+    if (bytes_read == 0)
+      break;
+    // Allow for partial writes
+    ssize_t bytes_written_per_read = 0;
+    do {
+      ssize_t bytes_written_partial = HANDLE_EINTR(write(
+          outfile,
+          &buffer[bytes_written_per_read],
+          bytes_read - bytes_written_per_read));
+      if (bytes_written_partial < 0) {
+        result = false;
+        break;
+      }
+      bytes_written_per_read += bytes_written_partial;
+    } while (bytes_written_per_read < bytes_read);
+  }
+
+  if (HANDLE_EINTR(close(infile)) < 0)
+    result = false;
+  if (HANDLE_EINTR(close(outfile)) < 0)
+    result = false;
+
+  return result;
+}
+#endif // !defined(OS_MACOSX)
+
 ///////////////////////////////////////////////
 // FileEnumerator
 
 FileEnumerator::FileEnumerator(const FilePath& root_path,
                                bool recursive,
                                FileEnumerator::FILE_TYPE file_type)
     : recursive_(recursive),
       file_type_(file_type),