usi.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #ifdef HAVE_CONFIG_H
  10. #include <config.h>
  11. #endif
  12. #ifndef __usi_h
  13. #define __usi_h
  14. /*
  15. * Description (usi.h)
  16. *
  17. * This file defines the interface to an unsigned integer datatype.
  18. * Unsigned integers are used to represent object identifiers of
  19. * various sorts, including user ids and group ids. Functions
  20. * for manipulating lists of USIs are also provided in this
  21. * interface.
  22. */
  23. /* Define a type to contain an unsigned integer value */
  24. typedef unsigned int USI_t;
  25. /* Define a type to describe a list of USI_t values */
  26. typedef struct USIList_s USIList_t;
  27. struct USIList_s
  28. {
  29. int uil_count; /* number of active values in list */
  30. int uil_size; /* current size of list area in USI_t */
  31. USI_t *uil_list; /* pointer to array of values */
  32. };
  33. /* Define macro to initialize a USIList_t structure */
  34. #define UILINIT(uilptr) \
  35. { \
  36. (uilptr)->uil_count = 0; \
  37. (uilptr)->uil_size = 0; \
  38. (uilptr)->uil_list = 0; \
  39. }
  40. /* Define a macro to replace the contents of one USIList_t with another's */
  41. #define UILREPLACE(dst, src) \
  42. { \
  43. if ((dst)->uil_size > 0) { \
  44. FREE((dst)->uil_list); \
  45. } \
  46. (dst)->uil_count = (src)->uil_count; \
  47. (dst)->uil_size = (src)->uil_size; \
  48. (dst)->uil_list = (src)->uil_list; \
  49. (src)->uil_count = 0; \
  50. (src)->uil_size = 0; \
  51. (src)->uil_list = 0; \
  52. }
  53. /* Define a variation of UILINIT() that frees any allocated space */
  54. #define UILFREE(uilptr) \
  55. { \
  56. if ((uilptr)->uil_size > 0) { \
  57. FREE((uilptr)->uil_list); \
  58. } \
  59. (uilptr)->uil_count = 0; \
  60. (uilptr)->uil_size = 0; \
  61. (uilptr)->uil_list = 0; \
  62. }
  63. /* Define a macro to extract the current number of items in a USIList_t */
  64. #define UILCOUNT(uilptr) ((uilptr)->uil_count)
  65. /* Define a macro to return a pointer to the array of values */
  66. #define UILLIST(uilptr) ((uilptr)->uil_list)
  67. NSPR_BEGIN_EXTERN_C
  68. /* Define functions in usi.c */
  69. extern USI_t *usiAlloc(USIList_t *uilptr, int count);
  70. extern int usiInsert(USIList_t *uilptr, USI_t usi);
  71. extern int usiPresent(USIList_t *uilptr, USI_t usi);
  72. extern int usiRemove(USIList_t *uilptr, USI_t usi);
  73. extern int uilDuplicate(USIList_t *dstptr, USIList_t *srcptr);
  74. extern int uilMerge(USIList_t *dstptr, USIList_t *srcptr);
  75. NSPR_END_EXTERN_C
  76. #endif /* __usi_h */