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

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

Issue 639253004: Allow POSIX callers to specify a new file's mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use ScopedFD, rename function, adhere to the bool return value. Created 6 years, 2 months 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 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0640)); 686 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0640));
687 if (fd < 0) 687 if (fd < 0)
688 return -1; 688 return -1;
689 689
690 int bytes_written = WriteFileDescriptor(fd, data, size) ? size : -1; 690 int bytes_written = WriteFileDescriptor(fd, data, size) ? size : -1;
691 if (IGNORE_EINTR(close(fd)) < 0) 691 if (IGNORE_EINTR(close(fd)) < 0)
692 return -1; 692 return -1;
693 return bytes_written; 693 return bytes_written;
694 } 694 }
695 695
696 bool WriteFileWithMode(const FilePath& filename, const char* data, int size,
697 mode_t mode) {
698 ThreadRestrictions::AssertIOAllowed();
699 int fd = HANDLE_EINTR(creat(filename.value().c_str(), mode));
rvargas (doing something else) 2014/10/22 00:57:38 tiny nit: declare fd (or file) directly to be a Sc
palmer 2014/10/22 01:03:02 Done.
700 if (fd < 0)
701 return false;
702
703 ScopedFD file(fd);
704 bool status = WriteFileDescriptor(file.get(), data, size);
rvargas (doing something else) 2014/10/22 00:57:38 tiny nit: return directly here.
palmer 2014/10/22 01:03:02 Done.
705 return status;
706 }
707
696 bool WriteFileDescriptor(const int fd, const char* data, int size) { 708 bool WriteFileDescriptor(const int fd, const char* data, int size) {
697 // Allow for partial writes. 709 // Allow for partial writes.
698 ssize_t bytes_written_total = 0; 710 ssize_t bytes_written_total = 0;
699 for (ssize_t bytes_written_partial = 0; bytes_written_total < size; 711 for (ssize_t bytes_written_partial = 0; bytes_written_total < size;
700 bytes_written_total += bytes_written_partial) { 712 bytes_written_total += bytes_written_partial) {
701 bytes_written_partial = 713 bytes_written_partial =
702 HANDLE_EINTR(write(fd, data + bytes_written_total, 714 HANDLE_EINTR(write(fd, data + bytes_written_total,
703 size - bytes_written_total)); 715 size - bytes_written_total));
704 if (bytes_written_partial < 0) 716 if (bytes_written_partial < 0)
705 return false; 717 return false;
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 result = false; 933 result = false;
922 934
923 return result; 935 return result;
924 } 936 }
925 #endif // !defined(OS_MACOSX) 937 #endif // !defined(OS_MACOSX)
926 938
927 } // namespace internal 939 } // namespace internal
928 940
929 #endif // !defined(__native_client_nonsfi__) 941 #endif // !defined(__native_client_nonsfi__)
930 } // namespace base 942 } // 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