/* Copyright (C) 2015-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: dk4bf.ctr */ #ifndef DK4BF_H_INCLUDED /** Avoid multiple inclusions. */ #define DK4BF_H_INCLUDED 1 #line 10 "dk4bf.ctr" /** @file dk4bf.h Bit fields. */ #ifndef DK4CONF_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4conf.h" #else #include #endif #endif #ifndef DK4ERROR_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4error.h" #else #include #endif #endif /** Bit field structure. */ typedef struct { unsigned char *d; /**< Data buffer. */ size_t s; /**< Number of bits in the array. */ } dk4_bit_field_t; #ifdef __cplusplus extern "C" { #endif /** Open bit field. @param sz Size of the bit field (number of bits). @param erp Error report, may be NULL. @return Pointer to new bit field on success, NULL on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if sz is 0, - DK4_E_MEMORY_ALLOCATION_FAILED
if not enough memory was available. */ dk4_bit_field_t * dk4bf_open(size_t sz, dk4_er_t *erp); /** Set one bit in a bit field. @param dptr Bit field. @param bitno Index of bit to modify. @param val Bit value. @param erp Error report, may be NULL. @return 1 on success, 0 on error. Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr is 0 or bitno is outside the bit field size. */ int dk4bf_set(dk4_bit_field_t *dptr, size_t bitno, int val, dk4_er_t *erp); /** Retrieve one value from bit field. @param dptr Address of result variable. @param bfptr Bit field. @param bitno Number of bit to obtain. @param erp Error report, may be NULL. @return 1 on success (dptr set), 0 on error (dptr unchanged). Error codes: - DK4_E_INVALID_ARGUMENTS
if dptr or bfptr is NULL or bitno is outside the bit field size. */ int dk4bf_get(int *dptr, dk4_bit_field_t const *bfptr, size_t bitno, dk4_er_t *erp); /** Close bit field. @param ptr Pointer to bit field previously opened using dk4bf_open(). */ void dk4bf_close(dk4_bit_field_t *ptr); #ifdef __cplusplus } #endif #endif