Add jaylink_device_get_usb_bus_ports()
[libjaylink.git] / libjaylink / util.c
blob4862d4e449040ca13bd8c08591d075c1b2573749
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 <stdbool.h>
22 #include "libjaylink.h"
24 /**
25 * @file
27 * Utility functions.
30 /**
31 * Check for a capability.
33 * The capabilities are expected to be stored in a bit array consisting of one
34 * or more bytes where each individual bit represents a capability. The first
35 * bit of this array is the least significant bit of the first byte and the
36 * following bits are sequentially numbered in order of increasing bit
37 * significance and byte index. A set bit indicates a supported capability.
39 * @param[in] caps Buffer with capabilities.
40 * @param[in] cap Bit position of the capability to check for.
42 * @retval true Capability is supported.
43 * @retval false Capability is not supported or invalid argument.
45 * @since 0.1.0
47 JAYLINK_API bool jaylink_has_cap(const uint8_t *caps, uint32_t cap)
49 if (!caps)
50 return false;
52 if (caps[cap / 8] & (1 << (cap % 8)))
53 return true;
55 return false;