usi.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. int uil_count; /* number of active values in list */
  29. int uil_size; /* current size of list area in USI_t */
  30. USI_t * uil_list; /* pointer to array of values */
  31. };
  32. /* Define macro to initialize a USIList_t structure */
  33. #define UILINIT(uilptr) \
  34. { \
  35. (uilptr)->uil_count = 0; \
  36. (uilptr)->uil_size = 0; \
  37. (uilptr)->uil_list = 0; \
  38. }
  39. /* Define a macro to replace the contents of one USIList_t with another's */
  40. #define UILREPLACE(dst, src) \
  41. { \
  42. if ((dst)->uil_size > 0) { \
  43. FREE((dst)->uil_list); \
  44. } \
  45. (dst)->uil_count = (src)->uil_count; \
  46. (dst)->uil_size = (src)->uil_size; \
  47. (dst)->uil_list = (src)->uil_list; \
  48. (src)->uil_count = 0; \
  49. (src)->uil_size = 0; \
  50. (src)->uil_list = 0; \
  51. }
  52. /* Define a variation of UILINIT() that frees any allocated space */
  53. #define UILFREE(uilptr) \
  54. { \
  55. if ((uilptr)->uil_size > 0) { \
  56. FREE((uilptr)->uil_list); \
  57. } \
  58. (uilptr)->uil_count = 0; \
  59. (uilptr)->uil_size = 0; \
  60. (uilptr)->uil_list = 0; \
  61. }
  62. /* Define a macro to extract the current number of items in a USIList_t */
  63. #define UILCOUNT(uilptr) ((uilptr)->uil_count)
  64. /* Define a macro to return a pointer to the array of values */
  65. #define UILLIST(uilptr) ((uilptr)->uil_list)
  66. NSPR_BEGIN_EXTERN_C
  67. /* Define functions in usi.c */
  68. extern USI_t * usiAlloc(USIList_t * uilptr, int count);
  69. extern int usiInsert(USIList_t * uilptr, USI_t usi);
  70. extern int usiPresent(USIList_t * uilptr, USI_t usi);
  71. extern int usiRemove(USIList_t * uilptr, USI_t usi);
  72. extern int uilDuplicate(USIList_t * dstptr, USIList_t * srcptr);
  73. extern int uilMerge(USIList_t * dstptr, USIList_t * srcptr);
  74. NSPR_END_EXTERN_C
  75. #endif /* __usi_h */