| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | simple bitmap functions
|
|---|
| 4 | Copyright (C) Andrew Tridgell 1992-1998
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with this program; if not, write to the Free Software
|
|---|
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #include "includes.h"
|
|---|
| 22 |
|
|---|
| 23 | /* these functions provide a simple way to allocate integers from a
|
|---|
| 24 | pool without repetition */
|
|---|
| 25 |
|
|---|
| 26 | /****************************************************************************
|
|---|
| 27 | allocate a bitmap of the specified size
|
|---|
| 28 | ****************************************************************************/
|
|---|
| 29 | struct bitmap *bitmap_allocate(int n)
|
|---|
| 30 | {
|
|---|
| 31 | struct bitmap *bm;
|
|---|
| 32 |
|
|---|
| 33 | bm = SMB_MALLOC_P(struct bitmap);
|
|---|
| 34 |
|
|---|
| 35 | if (!bm) return NULL;
|
|---|
| 36 |
|
|---|
| 37 | bm->n = n;
|
|---|
| 38 | bm->b = SMB_MALLOC_ARRAY(uint32, (n+31)/32);
|
|---|
| 39 | if (!bm->b) {
|
|---|
| 40 | SAFE_FREE(bm);
|
|---|
| 41 | return NULL;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | memset(bm->b, 0, sizeof(uint32)*((n+31)/32));
|
|---|
| 45 |
|
|---|
| 46 | return bm;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | /****************************************************************************
|
|---|
| 50 | free a bitmap.
|
|---|
| 51 | ****************************************************************************/
|
|---|
| 52 |
|
|---|
| 53 | void bitmap_free(struct bitmap *bm)
|
|---|
| 54 | {
|
|---|
| 55 | if (!bm)
|
|---|
| 56 | return;
|
|---|
| 57 |
|
|---|
| 58 | SAFE_FREE(bm->b);
|
|---|
| 59 | SAFE_FREE(bm);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | /****************************************************************************
|
|---|
| 63 | talloc a bitmap
|
|---|
|
|---|