lib: Remove tdb_errorstr_compat
[Samba.git] / lib / util / idtree.h
blobe7864a86968cda9dc6f6dab8cf60b77653fa0d1b
1 /*
2 Unix SMB/CIFS implementation.
4 very efficient functions to manage mapping a id (such as a fnum) to
5 a pointer. This is used for fnum and search id allocation.
7 Copyright (C) Andrew Tridgell 2004
9 This code is derived from lib/idr.c in the 2.6 Linux kernel, which was
10 written by Jim Houston jim.houston@ccur.com, and is
11 Copyright (C) 2002 by Concurrent Computer Corporation
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #ifndef _SAMBA_IDTREE_H_
28 #define _SAMBA_IDTREE_H_
30 #include <talloc.h>
32 struct idr_context;
34 /**
35 initialise a idr tree. The context return value must be passed to
36 all subsequent idr calls. To destroy the idr tree use talloc_free()
37 on this context
39 struct idr_context *idr_init(TALLOC_CTX *mem_ctx);
41 /**
42 allocate the next available id, and assign 'ptr' into its slot.
43 you can retrieve later this pointer using idr_find()
45 int idr_get_new(struct idr_context *idp, void *ptr, int limit);
47 /**
48 allocate a new id, giving the first available value greater than or
49 equal to the given starting id
51 int idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id, int limit);
53 /**
54 allocate a new id randomly in the given range
56 int idr_get_new_random(struct idr_context *idp, void *ptr, int limit);
58 /**
59 find a pointer value previously set with idr_get_new given an id
61 void *idr_find(struct idr_context *idp, int id);
63 /**
64 remove an id from the idr tree
66 int idr_remove(struct idr_context *idp, int id);
68 #endif /* _SAMBA_IDTREE_H_ */