Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: base/files/file_util_posix.cc

Issue 693493004: Revert of Allow POSIX callers to specify a new file's mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/files/file_util.h ('k') | base/files/file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file_util.h" 5 #include "base/files/file_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <libgen.h> 10 #include <libgen.h>
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0640)); 688 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0640));
689 if (fd < 0) 689 if (fd < 0)
690 return -1; 690 return -1;
691 691
692 int bytes_written = WriteFileDescriptor(fd, data, size) ? size : -1; 692 int bytes_written = WriteFileDescriptor(fd, data, size) ? size : -1;
693 if (IGNORE_EINTR(close(fd)) < 0) 693 if (IGNORE_EINTR(close(fd)) < 0)
694 return -1; 694 return -1;
695 return bytes_written; 695 return bytes_written;
696 } 696 }
697 697
698 bool WriteFileWithMode(const FilePath& filename, const char* data, int size,
699 mode_t mode) {
700 ThreadRestrictions::AssertIOAllowed();
701 ScopedFD file(HANDLE_EINTR(creat(filename.value().c_str(), mode)));
702 if (!file.is_valid())
703 return false;
704 return WriteFileDescriptor(file.get(), data, size);
705 }
706
707 bool WriteFileDescriptor(const int fd, const char* data, int size) { 698 bool WriteFileDescriptor(const int fd, const char* data, int size) {
708 // Allow for partial writes. 699 // Allow for partial writes.
709 ssize_t bytes_written_total = 0; 700 ssize_t bytes_written_total = 0;
710 for (ssize_t bytes_written_partial = 0; bytes_written_total < size; 701 for (ssize_t bytes_written_partial = 0; bytes_written_total < size;
711 bytes_written_total += bytes_written_partial) { 702 bytes_written_total += bytes_written_partial) {
712 bytes_written_partial = 703 bytes_written_partial =
713 HANDLE_EINTR(write(fd, data + bytes_written_total, 704 HANDLE_EINTR(write(fd, data + bytes_written_total,
714 size - bytes_written_total)); 705 size - bytes_written_total));
715 if (bytes_written_partial < 0) 706 if (bytes_written_partial < 0)
716 return false; 707 return false;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 result = false; 923 result = false;
933 924
934 return result; 925 return result;
935 } 926 }
936 #endif // !defined(OS_MACOSX) 927 #endif // !defined(OS_MACOSX)
937 928
938 } // namespace internal 929 } // namespace internal
939 930
940 #endif // !defined(__native_client_nonsfi__) 931 #endif // !defined(__native_client_nonsfi__)
941 } // namespace base 932 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_util.h ('k') | base/files/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698