Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AndroidSystemCore
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Werner Sembach
AndroidSystemCore
Commits
19388fc3
Commit
19388fc3
authored
Mar 26, 2016
by
Elliott Hughes
Committed by
Gerrit Code Review
Mar 26, 2016
Browse files
Options
Downloads
Plain Diff
Merge "Copy the good comment and warn_unused_result from ScopedFd to unique_fd."
parents
68af3483
c0e6e40c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
base/include/android-base/unique_fd.h
+19
-15
19 additions, 15 deletions
base/include/android-base/unique_fd.h
with
19 additions
and
15 deletions
base/include/android-base/unique_fd.h
+
19
−
15
View file @
19388fc3
...
...
@@ -21,18 +21,18 @@
#include
<android-base/macros.h>
/
*
Container for a file descriptor that automatically closes the descriptor as
*
it goes out of scope.
*
*
unique_fd ufd(open("/some/path", "r"));
*
* if (ufd.get() < 0) // invalid descriptor
*
return error;
*
*
// Do something useful
*
* return 0; // descriptor is closed here
*/
/
/
Container for a file descriptor that automatically closes the descriptor as
//
it goes out of scope.
//
//
unique_fd ufd(open("/some/path", "r"));
// if (ufd.get() == -1) return error;
//
//
// Do something useful, possibly including 'return'.
//
//
return 0; // Descriptor is closed for you.
//
// unique_fd is also known as ScopedFd/ScopedFD/scoped_fd; mentioned here to help
// you find this class if you're searching for one of those names.
namespace
android
{
namespace
base
{
...
...
@@ -50,8 +50,12 @@ class unique_fd final {
}
void
reset
(
int
new_value
)
{
if
(
value_
>=
0
)
if
(
value_
!=
-
1
)
{
// Even if close(2) fails with EINTR, the fd will have been closed.
// Using TEMP_FAILURE_RETRY will either lead to EBADF or closing someone else's fd.
// http://lkml.indiana.edu/hypermail/linux/kernel/0509.1/0877.html
close
(
value_
);
}
value_
=
new_value
;
}
...
...
@@ -61,7 +65,7 @@ class unique_fd final {
int
get
()
const
{
return
value_
;
}
int
release
()
{
int
release
()
__attribute__
((
warn_unused_result
))
{
int
ret
=
value_
;
value_
=
-
1
;
return
ret
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment