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

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: Remove time_t usage 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
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 base::FilePath& path, int flag) {
14 int fd, ret;
15 const char* file = path.value().c_str();
16
17 if ((fd = open(file, O_RDONLY)) < 0) {
18 LOG(ERROR) << "Error opening " << file << " error = " << strerror(errno);
19 return false;
20 }
21 if ((ret = TEMP_FAILURE_RETRY(flock(fd, flag))) < 0)
22 LOG(ERROR) << "Error locking " << file << " error = " << strerror(errno);
23
24 close(fd);
25 return !ret;
26 }
27
28 } // namespace
29
30 namespace chromecast {
31
32 bool LockFile(const base::FilePath& path) {
33 return AttemptLockOnFileWithFlag(path, LOCK_EX);
34 }
35
36 bool UnlockFile(const base::FilePath& path) {
37 return AttemptLockOnFileWithFlag(path, LOCK_UN);
38 }
39
40 } // namspace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698