xref: /plan9/sys/src/cmd/gs/src/gsuid.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1992, 1993, 1998 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gsuid.h,v 1.6 2002/06/19 01:06:12 lpd Exp $ */
18 /* Unique id definitions for Ghostscript */
19 
20 #ifndef gsuid_INCLUDED
21 #  define gsuid_INCLUDED
22 
23 /* A unique id (uid) may be either a UniqueID or an XUID. */
24 /* (XUIDs are a Level 2 feature.) */
25 #ifndef gs_uid_DEFINED
26 #  define gs_uid_DEFINED
27 typedef struct gs_uid_s gs_uid;
28 #endif
29 struct gs_uid_s {
30     /* id >= 0 is a UniqueID, xvalues is 0. */
31     /* id < 0 is an XUID, size of xvalues is -id. */
32     long id;
33     long *xvalues;
34 };
35 
36 /*
37  * A UniqueID of no_UniqueID is an indication that there is no uid.
38  * Since we sometimes use gs_ids as UniqueIDs, we want to choose as large
39  * a (positive) value as possible for no_UniqueID.
40  */
41 #define no_UniqueID max_long
42 #define uid_is_valid(puid)\
43   ((puid)->id != no_UniqueID)
44 #define uid_set_invalid(puid)\
45   ((puid)->id = no_UniqueID, (puid)->xvalues = 0)
46 #define uid_is_UniqueID(puid)\
47   (((puid)->id & ~0xffffff) == 0)
48 #define uid_is_XUID(puid)\
49   ((puid)->id < 0)
50 
51 /* Initialize a uid. */
52 #define uid_set_UniqueID(puid, idv)\
53   ((puid)->id = idv, (puid)->xvalues = 0)
54 #define uid_set_XUID(puid, pvalues, siz)\
55   ((puid)->id = -(long)(siz), (puid)->xvalues = pvalues)
56 
57 /* Get the size and the data of an XUID. */
58 #define uid_XUID_size(puid) ((uint)(-(puid)->id))
59 #define uid_XUID_values(puid) ((puid)->xvalues)
60 
61 /* Compare two uids for equality. */
62 /* This could be a macro, but the Zortech compiler compiles it wrong. */
63 bool uid_equal(const gs_uid *, const gs_uid *);	/* in gsutil.c */
64 
65 /* Copy the XUID data for a uid, if needed, updating the uid in place. */
66 int uid_copy(gs_uid *puid, gs_memory_t *mem, client_name_t cname);
67 
68 /* Free the XUID array of a uid if necessary. */
69 #define uid_free(puid, mem, cname)\
70   gs_free_object(mem, (puid)->xvalues, cname)
71 
72 #endif /* gsuid_INCLUDED */
73