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

Side by Side Diff: chromecast/base/file_utils.cc

Issue 2203123003: [Chromecast] Remove usage of nonreentrant functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: bcf@ comments Created 4 years, 4 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 | « chromecast/base/file_utils.h ('k') | chromecast/crash/linux/crash_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chromecast/base/file_utils.h"
6
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <sys/file.h>
10
11 namespace {
12
13 bool AttemptLockOnFileWithFlag(const char* file, int flag) {
bcf 2016/08/03 20:45:10 nit: pass in const base::FilePath& so you only hav
ameyak 2016/08/04 15:25:30 Done.
14 int fd;
15 if ((fd = open(file, O_RDONLY)) < 0) {
16 LOG(ERROR) << "Error opening " << file << " error = " << strerror(errno);
17 return false;
18 }
19
20 flag = TEMP_FAILURE_RETRY(flock(fd, flag));
bcf 2016/08/03 20:45:10 Should log on error.
bcf 2016/08/03 20:45:10 You shouldn't reuse this variable for another purp
ameyak 2016/08/04 15:25:30 Done.
ameyak 2016/08/04 15:25:30 Done.
21 close(fd);
22 return !flag;
23 }
24
25 } // namespace
26
27 namespace chromecast {
28
29 bool LockFile(const base::FilePath& path) {
30 return AttemptLockOnFileWithFlag(path.value().c_str(), LOCK_EX);
31 }
32
33 bool UnlockFile(const base::FilePath& path) {
34 return AttemptLockOnFileWithFlag(path.value().c_str(), LOCK_UN);
35 }
36
37 } // namspace chromecast
OLDNEW
« no previous file with comments | « chromecast/base/file_utils.h ('k') | chromecast/crash/linux/crash_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698