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
Matombo
AndroidSystemCore
Commits
dd6e73f4
Commit
dd6e73f4
authored
May 3, 2017
by
Elliott Hughes
Committed by
Gerrit Code Review
May 3, 2017
Browse files
Options
Downloads
Plain Diff
Merge "Preserve errno better in native_handle functions."
parents
66b25eb8
bf0492a9
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
libcutils/native_handle.c
+17
-25
17 additions, 25 deletions
libcutils/native_handle.c
with
17 additions
and
25 deletions
libcutils/native_handle.c
+
17
−
25
View file @
dd6e73f4
...
...
@@ -14,7 +14,7 @@
* limitations under the License.
*/
#
define LOG_TAG "N
ative
H
andle
"
#
include
<cutils/n
ative
_h
andle
.h>
#include
<errno.h>
#include
<stdint.h>
...
...
@@ -22,15 +22,12 @@
#include
<string.h>
#include
<unistd.h>
#include
<android/log.h>
#include
<cutils/native_handle.h>
static
const
int
kMaxNativeFds
=
1024
;
static
const
int
kMaxNativeInts
=
1024
;
native_handle_t
*
native_handle_init
(
char
*
storage
,
int
numFds
,
int
numInts
)
{
native_handle_t
*
native_handle_init
(
char
*
storage
,
int
numFds
,
int
numInts
)
{
if
((
uintptr_t
)
storage
%
alignof
(
native_handle_t
))
{
errno
=
EINVAL
;
return
NULL
;
}
...
...
@@ -38,13 +35,12 @@ native_handle_t* native_handle_init(char* storage, int numFds, int numInts)
handle
->
version
=
sizeof
(
native_handle_t
);
handle
->
numFds
=
numFds
;
handle
->
numInts
=
numInts
;
return
handle
;
}
native_handle_t
*
native_handle_create
(
int
numFds
,
int
numInts
)
{
native_handle_t
*
native_handle_create
(
int
numFds
,
int
numInts
)
{
if
(
numFds
<
0
||
numInts
<
0
||
numFds
>
kMaxNativeFds
||
numInts
>
kMaxNativeInts
)
{
errno
=
EINVAL
;
return
NULL
;
}
...
...
@@ -58,14 +54,13 @@ native_handle_t* native_handle_create(int numFds, int numInts)
return
h
;
}
native_handle_t
*
native_handle_clone
(
const
native_handle_t
*
handle
)
{
native_handle_t
*
native_handle_clone
(
const
native_handle_t
*
handle
)
{
native_handle_t
*
clone
=
native_handle_create
(
handle
->
numFds
,
handle
->
numInts
);
i
nt
i
;
i
f
(
clone
==
NULL
)
return
NULL
;
for
(
i
=
0
;
i
<
handle
->
numFds
;
i
++
)
{
for
(
int
i
=
0
;
i
<
handle
->
numFds
;
i
++
)
{
clone
->
data
[
i
]
=
dup
(
handle
->
data
[
i
]);
if
(
clone
->
data
[
i
]
<
0
)
{
if
(
clone
->
data
[
i
]
==
-
1
)
{
clone
->
numFds
=
i
;
native_handle_close
(
clone
);
native_handle_delete
(
clone
);
...
...
@@ -79,25 +74,22 @@ native_handle_t* native_handle_clone(const native_handle_t* handle)
return
clone
;
}
int
native_handle_delete
(
native_handle_t
*
h
)
{
int
native_handle_delete
(
native_handle_t
*
h
)
{
if
(
h
)
{
if
(
h
->
version
!=
sizeof
(
native_handle_t
))
return
-
EINVAL
;
if
(
h
->
version
!=
sizeof
(
native_handle_t
))
return
-
EINVAL
;
free
(
h
);
}
return
0
;
}
int
native_handle_close
(
const
native_handle_t
*
h
)
{
if
(
h
->
version
!=
sizeof
(
native_handle_t
))
return
-
EINVAL
;
int
native_handle_close
(
const
native_handle_t
*
h
)
{
if
(
h
->
version
!=
sizeof
(
native_handle_t
))
return
-
EINVAL
;
int
saved_errno
=
errno
;
const
int
numFds
=
h
->
numFds
;
int
i
;
for
(
i
=
0
;
i
<
numFds
;
i
++
)
{
for
(
int
i
=
0
;
i
<
numFds
;
++
i
)
{
close
(
h
->
data
[
i
]);
}
errno
=
saved_errno
;
return
0
;
}
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
sign in
to comment