Imported Upstream version 0.1.0+git20131207+e452e83
[deb_libhybris.git] / hybris / egl / platforms / common / native_handle.c
CommitLineData
d42e7319
JB
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "NativeHandle"
18
19#include <stdint.h>
20#include <errno.h>
21#include <string.h>
22#include <stdlib.h>
23#include <unistd.h>
24
25#include <android/cutils/native_handle.h>
26
27native_handle_t* native_handle_create(int numFds, int numInts)
28{
29 native_handle_t* h = malloc(
30 sizeof(native_handle_t) + sizeof(int)*(numFds+numInts));
31
32 h->version = sizeof(native_handle_t);
33 h->numFds = numFds;
34 h->numInts = numInts;
35 return h;
36}
37
38int native_handle_delete(native_handle_t* h)
39{
40 if (h) {
41 if (h->version != sizeof(native_handle_t))
42 return -EINVAL;
43 free(h);
44 }
45 return 0;
46}
47
48int native_handle_close(const native_handle_t* h)
49{
50 if (h->version != sizeof(native_handle_t))
51 return -EINVAL;
52
53 const int numFds = h->numFds;
54 int i;
55 for (i=0 ; i<numFds ; i++) {
56 close(h->data[i]);
57 }
58 return 0;
59}