diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-21 21:11:36 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-21 21:11:36 +0000 |
commit | 84cb19128979726fe4369029c8c09a7f434fe9a2 (patch) | |
tree | 29ebea7ea02bb9537316a6242d50bb835dec592a | |
parent | 765c16207e8c10ed3a0f79db0ecdbd89bcf0c1a6 (diff) | |
download | chromium_src-84cb19128979726fe4369029c8c09a7f434fe9a2.zip chromium_src-84cb19128979726fe4369029c8c09a7f434fe9a2.tar.gz chromium_src-84cb19128979726fe4369029c8c09a7f434fe9a2.tar.bz2 |
bsd: move POSIXy functions back into file_util_posix
This is so the other non-Mac platforms don't need to
build file_util_linux.
Review URL: http://codereview.chromium.org/1732003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@45242 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/base.gypi | 1 | ||||
-rw-r--r-- | base/file_util_linux.cc | 78 | ||||
-rw-r--r-- | base/file_util_posix.cc | 62 |
3 files changed, 62 insertions, 79 deletions
diff --git a/base/base.gypi b/base/base.gypi index abdb161..d57e587 100644 --- a/base/base.gypi +++ b/base/base.gypi @@ -76,7 +76,6 @@ 'file_util.cc', 'file_util.h', 'file_util_deprecated.h', - 'file_util_linux.cc', 'file_util_mac.mm', 'file_util_posix.cc', 'file_util_win.cc', diff --git a/base/file_util_linux.cc b/base/file_util_linux.cc deleted file mode 100644 index 0f9795e..0000000 --- a/base/file_util_linux.cc +++ /dev/null @@ -1,78 +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> - -#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) { - *path = FilePath("/dev/shm"); - return true; -} - -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 diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index 2047636..8947d6a 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -713,4 +713,66 @@ bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, return find_info.stat.st_mtime >= cutoff_time.ToTimeT(); } +#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) { + *path = FilePath("/dev/shm"); + return true; +} + +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) + } // namespace file_util |