Merge "Add native_handle_clone" am: e8f6c7398b
am: 462e087e40
Change-Id: I745341bf4c76fc8c75f36e578cf1086808119426
This commit is contained in:
commit
cb52dc258e
2 changed files with 30 additions and 0 deletions
|
|
@ -56,6 +56,15 @@ int native_handle_close(const native_handle_t* h);
|
||||||
*/
|
*/
|
||||||
native_handle_t* native_handle_create(int numFds, int numInts);
|
native_handle_t* native_handle_create(int numFds, int numInts);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* native_handle_clone
|
||||||
|
*
|
||||||
|
* creates a native_handle_t and initializes it from another native_handle_t.
|
||||||
|
* Must be destroyed with native_handle_delete().
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
native_handle_t* native_handle_clone(const native_handle_t* handle);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* native_handle_delete
|
* native_handle_delete
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,27 @@ native_handle_t* native_handle_create(int numFds, int numInts)
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
native_handle_t* native_handle_clone(const native_handle_t* handle)
|
||||||
|
{
|
||||||
|
native_handle_t* clone = native_handle_create(handle->numFds, handle->numInts);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < handle->numFds; i++) {
|
||||||
|
clone->data[i] = dup(handle->data[i]);
|
||||||
|
if (clone->data[i] < 0) {
|
||||||
|
clone->numFds = i;
|
||||||
|
native_handle_close(clone);
|
||||||
|
native_handle_delete(clone);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(&clone->data[handle->numFds], &handle->data[handle->numFds],
|
||||||
|
sizeof(int) * handle->numInts);
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
int native_handle_delete(native_handle_t* h)
|
int native_handle_delete(native_handle_t* h)
|
||||||
{
|
{
|
||||||
if (h) {
|
if (h) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue