]> granicus.if.org Git - postgresql/blob - src/include/postgres.h
Remove NT-specific file open defines by defining our own open macros for
[postgresql] / src / include / postgres.h
1 /*-------------------------------------------------------------------------
2  *
3  * postgres.h
4  *        definition of (and support for) postgres system types.
5  * this file is included by almost every .c in the system
6  *
7  * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8  * Portions Copyright (c) 1995, Regents of the University of California
9  *
10  * $Id: postgres.h,v 1.40 2000/06/02 15:57:40 momjian Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 /*
15  *       NOTES
16  *              this file will eventually contain the definitions for the
17  *              following (and perhaps other) system types:
18  *
19  *                              int2       int4           float4           float8
20  *                              Oid                regproc        RegProcedure
21  *                              aclitem
22  *                              struct varlena
23  *                              int2vector        oidvector
24  *                              bytea      text
25  *                              NameData   Name
26  *
27  *       TABLE OF CONTENTS
28  *              1)              simple type definitions
29  *              2)              varlena and array types
30  *              3)              TransactionId and CommandId
31  *              4)              genbki macros used by catalog/pg_xxx.h files
32  *              5)              random stuff
33  *
34  * ----------------------------------------------------------------
35  */
36 #ifndef POSTGRES_H
37 #define POSTGRES_H
38
39 #include "postgres_ext.h"
40 #include "c.h"
41 #include "utils/elog.h"
42 #include "utils/mcxt.h"
43 #include "utils/palloc.h"
44
45 /* ----------------------------------------------------------------
46  *                              Section 1:      simple type definitions
47  * ----------------------------------------------------------------
48  */
49
50 typedef int4 aclitem;
51
52 #define InvalidOid              0
53 #define OidIsValid(objectId)  ((bool) ((objectId) != InvalidOid))
54
55 /* unfortunately, both regproc and RegProcedure are used */
56 typedef Oid regproc;
57 typedef Oid RegProcedure;
58
59 #define RegProcedureIsValid(p)  OidIsValid(p)
60
61 /* ----------------------------------------------------------------
62  *                              Section 2:      variable length and array types
63  * ----------------------------------------------------------------
64  */
65 /* ----------------
66  *              struct varlena
67  * ----------------
68  */
69 struct varlena
70 {
71         int32           vl_len;
72         char            vl_dat[1];
73 };
74
75 #define VARSIZE(PTR)    (((struct varlena *)(PTR))->vl_len)
76 #define VARDATA(PTR)    (((struct varlena *)(PTR))->vl_dat)
77 #define VARHDRSZ                ((int32) sizeof(int32))
78
79 typedef struct varlena bytea;
80 typedef struct varlena text;
81
82 typedef int2 int2vector[INDEX_MAX_KEYS];
83 typedef Oid oidvector[INDEX_MAX_KEYS];
84
85
86 /*
87  * Proposed new layout for variable length attributes
88  * DO NOT USE YET - Jan
89  */
90 #undef TUPLE_TOASTER_ACTIVE
91 #undef TUPLE_TOASTER_ALL_TYPES
92
93 #ifdef TUPLE_TOASTER_ACTIVE
94 typedef struct varattrib
95 {
96         int32           va_header;              /* External/compressed storage */
97         /* flags and item size */
98         union
99         {
100                 struct
101                 {
102                         int32           va_rawsize;             /* Plain data size */
103                 }                       va_compressed;          /* Compressed stored attribute */
104
105                 struct
106                 {
107                         int32           va_rawsize;             /* Plain data size */
108                         Oid                     va_valueid;             /* Unique identifier of value */
109                         Oid                     va_longrelid;   /* RelID where to find chunks */
110                         Oid                     va_rowid;               /* Main tables row Oid */
111                         int16           va_attno;               /* Main tables attno */
112                 }                       va_external;/* External stored attribute */
113
114                 char            va_data[1]; /* Plain stored attribute */
115         }                       va_content;
116 }                       varattrib;
117
118 #define VARATT_FLAG_EXTERNAL    0x8000
119 #define VARATT_FLAG_COMPRESSED  0x4000
120 #define VARATT_MASK_FLAGS               0xc000
121 #define VARATT_MASK_SIZE                0x3fff
122
123 #define VARATT_SIZEP(_PTR)      (((varattrib *)(_PTR))->va_header)
124 #define VARATT_SIZE(PTR)        (VARATT_SIZEP(PTR) & VARATT_MASK_SIZE)
125 #define VARATT_DATA(PTR)        (((varattrib *)(PTR))->va_content.va_data)
126
127 #define VARATT_IS_EXTENDED(PTR)         \
128                                 ((VARATT_SIZEP(PTR) & VARATT_MASK_FLAGS) != 0)
129 #define VARATT_IS_EXTERNAL(PTR)         \
130                                 ((VARATT_SIZEP(PTR) & VARATT_FLAG_EXTERNAL) != 0)
131 #define VARATT_IS_COMPRESSED(PTR)       \
132                                 ((VARATT_SIZEP(PTR) & VARATT_FLAG_COMPRESSED) != 0)
133
134 /* ----------
135  * This is regularly declared in access/tuptoaster.h,
136  * but we don't want to include that into every source,
137  * so we (evil evil evil) declare it here once more.
138  * ----------
139  */
140 extern varattrib *heap_tuple_untoast_attr(varattrib * attr);
141
142 #define VARATT_GETPLAIN(_ARG,_VAR) {                                                            \
143                                 if (VARATTR_IS_EXTENDED(_ARG))                                          \
144                                         (_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
145                                 else                                                                                            \
146                                         (_VAR) = (_ARG);                                                                \
147                         }
148 #define VARATT_FREE(_ARG,VAR) do {                                                                      \
149                                 if ((void *)(_VAR) != (void *)(_ARG))                           \
150                                         pfree((void *)(_VAR));                                                  \
151                         } while (0)
152 #else                                                   /* TUPLE_TOASTER_ACTIVE */
153 #define VARATT_SIZE(__PTR) VARSIZE(__PTR)
154 #define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
155 #endif   /* TUPLE_TOASTER_ACTIVE */
156
157
158 /* We want NameData to have length NAMEDATALEN and int alignment,
159  * because that's how the data type 'name' is defined in pg_type.
160  * Use a union to make sure the compiler agrees.
161  */
162 typedef union nameData
163 {
164         char            data[NAMEDATALEN];
165         int                     alignmentDummy;
166 } NameData;
167 typedef NameData *Name;
168
169 #define NameStr(name)   ((name).data)
170
171 /* ----------------------------------------------------------------
172  *                              Section 3: TransactionId and CommandId
173  * ----------------------------------------------------------------
174  */
175
176 typedef uint32 TransactionId;
177
178 #define InvalidTransactionId    0
179 typedef uint32 CommandId;
180
181 #define FirstCommandId  0
182
183 /* ----------------------------------------------------------------
184  *                              Section 4: genbki macros used by the
185  *                                                 catalog/pg_xxx.h files
186  * ----------------------------------------------------------------
187  */
188 #define CATALOG(x) \
189         typedef struct CppConcat(FormData_,x)
190
191 /* Huh? */
192 #define DATA(x) extern int errno
193 #define DESCR(x) extern int errno
194 #define DECLARE_INDEX(x) extern int errno
195 #define DECLARE_UNIQUE_INDEX(x) extern int errno
196
197 #define BUILD_INDICES
198 #define BOOTSTRAP
199
200 #define BKI_BEGIN
201 #define BKI_END
202
203 /* ----------------------------------------------------------------
204  *                              Section 5:      random stuff
205  *                                                      CSIGNBIT, STATUS...
206  * ----------------------------------------------------------------
207  */
208
209 /* msb for int/unsigned */
210 #define ISIGNBIT (0x80000000)
211 #define WSIGNBIT (0x8000)
212
213 /* msb for char */
214 #define CSIGNBIT (0x80)
215
216 #define STATUS_OK                               (0)
217 #define STATUS_ERROR                    (-1)
218 #define STATUS_NOT_FOUND                (-2)
219 #define STATUS_INVALID                  (-3)
220 #define STATUS_UNCATALOGUED             (-4)
221 #define STATUS_REPLACED                 (-5)
222 #define STATUS_NOT_DONE                 (-6)
223 #define STATUS_BAD_PACKET               (-7)
224 #define STATUS_FOUND                    (1)
225
226 /* ---------------
227  * Cyrillic on the fly charsets recode
228  * ---------------
229  */
230 #ifdef CYR_RECODE
231 extern void SetCharSet();
232 #endif   /* CYR_RECODE */
233
234 #endif   /* POSTGRES_H */