bitmap.c revision 5ffa42cb8028833440040c2e240e0d788f11c112
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen This file is part of systemd.
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen Copyright 2015 Tom Gundersen
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen systemd is free software; you can redistribute it and/or modify it
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen under the terms of the GNU Lesser General Public License as published by
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen the Free Software Foundation; either version 2.1 of the License, or
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen (at your option) any later version.
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen systemd is distributed in the hope that it will be useful, but
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen Lesser General Public License for more details.
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen You should have received a copy of the GNU Lesser General Public License
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen long long unsigned *bitmaps;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen/* Bitmaps are only meant to store relatively small numbers
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen * (corresponding to, say, an enum), so it is ok to limit
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen * the max entry. 64k should be plenty. */
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen/* This indicates that we reached the end of the bitmap */
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen#define BITMAP_NUM_TO_OFFSET(n) ((n) / (sizeof(long long unsigned) * 8))
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen#define BITMAP_NUM_TO_REM(n) ((n) % (sizeof(long long unsigned) * 8))
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen#define BITMAP_OFFSET_TO_NUM(offset, rem) ((offset) * sizeof(long long unsigned) * 8 + (rem))
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen /* we refuse to allocate huge bitmaps */
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen if (!GREEDY_REALLOC0(b->bitmaps, b->bitmaps_allocated, offset + 1))
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen if (!b || !b->bitmaps)
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen for (i = 0; i < b->n_bitmaps; i++)
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen for (i = 0; i < b->n_bitmaps; i++)
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen for (i = 0; i < a->n_bitmaps; i++)
5ffa42cb8028833440040c2e240e0d788f11c112Tom Gundersen return false;