forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Chromecast] Remove usage of nonreetrant functions.
Remove usage of dmtime & readdir_r Replace usage of time_t with base::Time::ToDoubleT() Replace int error codes with bool error codes Remove unix headers in favor of chromium-equivalent functions These changes are applied to files in directory crash/linux/ BUG=internal b/27252596 TEST=builds, cast_crash_unittests Review-Url: https://codereview.chromium.org/2203123003 Cr-Commit-Position: refs/heads/master@{#410441}
- Loading branch information
ameyak
authored and
Commit bot
committed
Aug 8, 2016
1 parent
c8c2305
commit 0625111
Showing
14 changed files
with
303 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2016 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 "chromecast/base/file_utils.h" | ||
|
||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <sys/file.h> | ||
|
||
namespace { | ||
|
||
// Calls flock on valid file descriptor |fd| with flag |flag|. Returns true | ||
// on success, false on failure. | ||
bool CallFlockOnFileWithFlag(const int fd, int flag) { | ||
int ret = -1; | ||
if ((ret = TEMP_FAILURE_RETRY(flock(fd, flag))) < 0) | ||
PLOG(ERROR) << "Error locking " << fd; | ||
|
||
return !ret; | ||
} | ||
|
||
} // namespace | ||
|
||
namespace chromecast { | ||
|
||
int OpenAndLockFile(const base::FilePath& path, bool write) { | ||
int fd = -1; | ||
const char* file = path.value().c_str(); | ||
|
||
if ((fd = open(file, write ? O_RDWR : O_RDONLY)) < 0) { | ||
PLOG(ERROR) << "Error opening " << file; | ||
} else if (!CallFlockOnFileWithFlag(fd, LOCK_EX)) { | ||
close(fd); | ||
fd = -1; | ||
} | ||
|
||
return fd; | ||
} | ||
|
||
bool UnlockAndCloseFile(const int fd) { | ||
if (!CallFlockOnFileWithFlag(fd, LOCK_UN)) | ||
return false; | ||
return !close(fd); | ||
} | ||
|
||
} // namespace chromecast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2016 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. | ||
|
||
#ifndef CHROMECAST_BASE_FILE_UTILS_H_ | ||
#define CHROMECAST_BASE_FILE_UTILS_H_ | ||
|
||
#include "base/files/file_path.h" | ||
|
||
namespace chromecast { | ||
|
||
// Lock a file (blocking request) with filepath |path|. Returns the file | ||
// descriptor on success, an invalid file descriptor (-1) on failure. Failure | ||
// indicates that |path| does not exist, or the locking procedure failed. | ||
// A true |write| value opens the file in RW mode, false opens in R-only. | ||
int OpenAndLockFile(const base::FilePath& path, bool write); | ||
|
||
// Unlock a file (blocking request) denoted by file descriptor |fd|. Returns | ||
// true on success, false on failure. | ||
bool UnlockAndCloseFile(const int fd); | ||
|
||
} // namespace chromecast | ||
|
||
#endif // CHROMECAST_BASE_FILE_UTILS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.