LCOV - code coverage report
Current view: top level - common - utils.h (source / functions) Hit Total Coverage
Test: out.info Lines: 5 5 100.0 %
Date: 2022-01-27 10:43:00 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
       2             : /*
       3             :    Copyright (C) 2010, 2011, 2018 Red Hat, Inc.
       4             : 
       5             :    This library is free software; you can redistribute it and/or
       6             :    modify it under the terms of the GNU Lesser General Public
       7             :    License as published by the Free Software Foundation; either
       8             :    version 2.1 of the License, or (at your option) any later version.
       9             : 
      10             :    This library is distributed in the hope that it will be useful,
      11             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13             :    Lesser General Public License for more details.
      14             : 
      15             :    You should have received a copy of the GNU Lesser General Public
      16             :    License along with this library; if not, see <http://www.gnu.org/licenses/>.
      17             : */
      18             : 
      19             : #ifndef H_SPICE_COMMON_UTILS
      20             : #define H_SPICE_COMMON_UTILS
      21             : 
      22             : #include <glib.h>
      23             : #include <glib-object.h>
      24             : #include <stdint.h>
      25             : 
      26             : G_BEGIN_DECLS
      27             : 
      28             : const char *spice_genum_get_nick(GType enum_type, gint value);
      29             : int spice_genum_get_value(GType enum_type, const char *nick,
      30             :                           gint default_value);
      31             : 
      32             : #define BIT_BYTE(nr)            ((nr) / 8)
      33             : #define BIT_MASK(nr)            (1 << ((nr) % 8))
      34             : 
      35             : /**
      36             :  * set_bitmap - Set a bit in memory
      37             :  * @nr: the bit to set
      38             :  * @addr: the address to start counting from
      39             :  */
      40           4 : static inline void set_bitmap(uint32_t nr, uint8_t *addr)
      41             : {
      42           4 :     addr[BIT_BYTE(nr)] |= BIT_MASK(nr);
      43           4 : }
      44             : 
      45             : /**
      46             :  * test_bitmap - Determine whether a bit is set
      47             :  * @nr: bit number to test
      48             :  * @addr: Address to start counting from
      49             :  */
      50          10 : static inline int test_bitmap(uint32_t nr, const uint8_t *addr)
      51             : {
      52          10 :     return 1 & (addr[BIT_BYTE(nr)] >> (nr % 8));
      53             : }
      54             : 
      55             : G_END_DECLS
      56             : 
      57             : #endif //H_SPICE_COMMON_UTILS

Generated by: LCOV version 1.14