1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/*-------------------------------------------------------------------------
*
* oid.c--
* Functions for the built-in type Oid.
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oid.c,v 1.15 1998/02/26 04:37:16 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string.h>
#include "postgres.h"
#include "utils/builtins.h" /* where function declarations go */
/*****************************************************************************
* USER I/O ROUTINES *
*****************************************************************************/
/*
* oid8in - converts "num num ..." to internal form
*
* Note:
* Fills any nonexistent digits with NULL oids.
*/
Oid *
oid8in(char *oidString)
{
Oid (*result)[];
int nums;
if (oidString == NULL)
return (NULL);
result = (Oid (*)[]) palloc(sizeof(Oid[8]));
if ((nums = sscanf(oidString, "%d%d%d%d%d%d%d%d",
&(*result)[0],
&(*result)[1],
&(*result)[2],
&(*result)[3],
&(*result)[4],
&(*result)[5],
&(*result)[6],
&(*result)[7])) != 8)
{
do
(*result)[nums++] = 0;
while (nums < 8);
}
return ((Oid *) result);
}
/*
* oid8out - converts internal form to "num num ..."
*/
char *
oid8out(Oid (*oidArray)[])
{
int num;
Oid *sp;
char *rp;
char *result;
if (oidArray == NULL)
{
result = (char *) palloc(2);
result[0] = '-';
result[1] = '\0';
return (result);
}
/* assumes sign, 10 digits, ' ' */
rp = result = (char *) palloc(8 * 12);
sp = *oidArray;
for (num = 8; num != 0; num--)
{
ltoa(*sp++, rp);
while (*++rp != '\0')
;
*rp++ = ' ';
}
*--rp = '\0';
return (result);
}
Oid
oidin(char *s)
{
return (int4in(s));
}
char *
oidout(Oid o)
{
return (int4out(o));
}
/*****************************************************************************
* PUBLIC ROUTINES *
*****************************************************************************/
/*
* If you change this function, change heap_keytest()
* because we have hardcoded this in there as an optimization
*/
bool
oideq(Oid arg1, Oid arg2)
{
return (arg1 == arg2);
}
bool
oidne(Oid arg1, Oid arg2)
{
return (arg1 != arg2);
}
bool
oid8eq(Oid arg1[], Oid arg2[])
{
return (bool) (memcmp(arg1, arg2, 8 * sizeof(Oid)) == 0);
}
bool
oideqint4(Oid arg1, int32 arg2)
{
/* oid is unsigned, but int4 is signed */
return (arg2 >= 0 && arg1 == arg2);
}
bool
int4eqoid(int32 arg1, Oid arg2)
{
/* oid is unsigned, but int4 is signed */
return (arg1 >= 0 && arg1 == arg2);
}
text *
oid_text(Oid oid)
{
text *result;
int len;
char *str;
str = oidout(oid);
len = (strlen(str) + VARHDRSZ);
result = palloc(len);
VARSIZE(result) = len;
memmove(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
return (result);
} /* oid_text() */
Oid
text_oid(text *string)
{
Oid result;
int len;
char *str;
len = (VARSIZE(string) - VARHDRSZ);
str = palloc(len + 1);
memmove(str, VARDATA(string), len);
*(str + len) = '\0';
result = oidin(str);
pfree(str);
return (result);
} /* oid_text() */
|