| 1 |
/** BEGIN COPYRIGHT BLOCK |
| 2 |
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission. |
| 3 |
* Copyright (C) 2005 Red Hat, Inc. |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* License: GPL (version 3 or any later version). |
| 7 |
* See LICENSE for details. |
| 8 |
* END COPYRIGHT BLOCK **/ |
| 9 |
|
| 10 |
#ifdef HAVE_CONFIG_H |
| 11 |
#include <config.h> |
| 12 |
#endif |
| 13 |
|
| 14 |
#ifndef __usi_h |
| 15 |
#define __usi_h |
| 16 |
|
| 17 |
/* |
| 18 |
* Description (usi.h) |
| 19 |
* |
| 20 |
* This file defines the interface to an unsigned integer datatype. |
| 21 |
* Unsigned integers are used to represent object identifiers of |
| 22 |
* various sorts, including user ids and group ids. Functions |
| 23 |
* for manipulating lists of USIs are also provided in this |
| 24 |
* interface. |
| 25 |
*/ |
| 26 |
|
| 27 |
/* Define a type to contain an unsigned integer value */ |
| 28 |
typedef unsigned int USI_t; |
| 29 |
|
| 30 |
/* Define a type to describe a list of USI_t values */ |
| 31 |
typedef struct USIList_s USIList_t; |
| 32 |
struct USIList_s |
| 33 |
{ |
| 34 |
int uil_count; /* number of active values in list */ |
| 35 |
int uil_size; /* current size of list area in USI_t */ |
| 36 |
USI_t *uil_list; /* pointer to array of values */ |
| 37 |
}; |
| 38 |
|
| 39 |
/* Define macro to initialize a USIList_t structure */ |
| 40 |
#define UILINIT(uilptr) \ |
| 41 |
{ \ |
| 42 |
(uilptr)->uil_count = 0; \ |
| 43 |
(uilptr)->uil_size = 0; \ |
| 44 |
(uilptr)->uil_list = 0; \ |
| 45 |
} |
| 46 |
|
| 47 |
/* Define a macro to replace the contents of one USIList_t with another's */ |
| 48 |
#define UILREPLACE(dst, src) \ |
| 49 |
{ \ |
| 50 |
if ((dst)->uil_size > 0) { \ |
| 51 |
FREE((dst)->uil_list); \ |
| 52 |
} \ |
| 53 |
(dst)->uil_count = (src)->uil_count; \ |
| 54 |
(dst)->uil_size = (src)->uil_size; \ |
| 55 |
(dst)->uil_list = (src)->uil_list; \ |
| 56 |
(src)->uil_count = 0; \ |
| 57 |
(src)->uil_size = 0; \ |
| 58 |
(src)->uil_list = 0; \ |
| 59 |
} |
| 60 |
|
| 61 |
/* Define a variation of UILINIT() that frees any allocated space */ |
| 62 |
#define UILFREE(uilptr) \ |
| 63 |
{ \ |
| 64 |
if ((uilptr)->uil_size > 0) { \ |
| 65 |
FREE((uilptr)->uil_list); \ |
| 66 |
} \ |
| 67 |
(uilptr)->uil_count = 0; \ |
| 68 |
(uilptr)->uil_size = 0; \ |
| 69 |
(uilptr)->uil_list = 0; \ |
| 70 |
} |
| 71 |
|
| 72 |
/* Define a macro to extract the current number of items in a USIList_t */ |
| 73 |
#define UILCOUNT(uilptr) ((uilptr)->uil_count) |
| 74 |
|
| 75 |
/* Define a macro to return a pointer to the array of values */ |
| 76 |
#define UILLIST(uilptr) ((uilptr)->uil_list) |
| 77 |
|
| 78 |
NSPR_BEGIN_EXTERN_C |
| 79 |
|
| 80 |
/* Define functions in usi.c */ |
| 81 |
extern USI_t *usiAlloc(USIList_t *uilptr, int count); |
| 82 |
extern int usiInsert(USIList_t *uilptr, USI_t usi); |
| 83 |
extern int usiPresent(USIList_t *uilptr, USI_t usi); |
| 84 |
extern int usiRemove(USIList_t *uilptr, USI_t usi); |
| 85 |
extern int uilDuplicate(USIList_t *dstptr, USIList_t *srcptr); |
| 86 |
extern int uilMerge(USIList_t *dstptr, USIList_t *srcptr); |
| 87 |
|
| 88 |
NSPR_END_EXTERN_C |
| 89 |
|
| 90 |
#endif /* __usi_h */ |