f0bd657348ac06b4e45f4d9650404986e8769669
[platform/core/api/peripheral-io.git] / include / interface / peripheral_interface_common.h
1 /*
2  * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
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 #ifndef __PERIPHERAL_INTERFACE_COMMON_H__
18 #define __PERIPHERAL_INTERFACE_COMMON_H__
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26
27 #include "peripheral_io.h"
28 #include "peripheral_handle.h"
29 #include "peripheral_common.h"
30
31 #define CHECK_ERROR(val) \
32         do { \
33                 if (val < 0) { \
34                         if (errno == EAGAIN) \
35                                 return -EAGAIN; \
36                         char errmsg[255]; \
37                         strerror_r(errno, errmsg, sizeof(errmsg)); \
38                         _E("Failed the %s(%d) function. errmsg: %s", __FUNCTION__, __LINE__, errmsg); \
39                         return -EIO; \
40                 } \
41         } while (0)
42
43 #endif /*__PERIPHERAL_INTERFACE_COMMON_H__*/