Add build support for Cygwin
[libjaylink.git] / libjaylink / util.c
blob62c7c90426cc9cda7dfca1f736ebe56715d10911
1 /*
2 * This file is part of the libjaylink project.
4 * Copyright (C) 2014-2015 Marc Schink <jaylink-dev@marcschink.de>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "libjaylink.h"
22 /**
23 * @file
25 * Utility functions.
28 /**
29 * Check for a capability.
31 * The capabilities are expected to be stored in a bit array consisting of one
32 * or more bytes where each individual bit represents a capability. The first
33 * bit of this array is the least significant bit of the first byte and the
34 * following bits are sequentially numbered in order of increasing bit
35 * significance and byte index. A set bit indicates a supported capability.
37 * @param[in] caps Buffer with capabilities.
38 * @param[in] cap Bit position of the capability to check for.
40 * @return 1 if the capability is supported, 0 otherwise.
42 JAYLINK_API int jaylink_has_cap(const uint8_t *caps, uint32_t cap)
44 if (!caps)
45 return 0;
47 if (caps[cap / 8] & (1 << (cap % 8)))
48 return 1;
50 return 0;