7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.8 1997/09/08 21:48:29 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/int.c,v 1.9 1997/10/25 05:19:22 thomas Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
16
16
* I/O routines:
17
17
* int2in, int2out, int28in, int28out, int4in, int4out
18
18
* Conversion routines:
19
- * itoi
19
+ * itoi, int2_text, int4_text
20
20
* Boolean operators:
21
21
* inteq, intne, intlt, intle, intgt, intge
22
22
* Arithmetic operators:
29
29
* fix me when we figure out what we want to do about ANSIfication...
30
30
*/
31
31
#include <stdio.h>
32
+ #include <string.h>
32
33
33
34
#include "postgres.h"
34
35
#include "fmgr.h"
@@ -50,7 +51,7 @@ int2in(char *num)
50
51
/*
51
52
* int2out - converts short to "num"
52
53
*/
53
- char *
54
+ char *
54
55
int2out (int16 sh )
55
56
{
56
57
char * result ;
@@ -66,7 +67,7 @@ int2out(int16 sh)
66
67
* Note:
67
68
* Fills any nonexistent digits with NULLs.
68
69
*/
69
- int16 *
70
+ int16 *
70
71
int28in (char * shs )
71
72
{
72
73
register int16 (* result )[];
@@ -95,7 +96,7 @@ int28in(char *shs)
95
96
/*
96
97
* int28out - converts internal form to "num num ..."
97
98
*/
98
- char *
99
+ char *
99
100
int28out (int16 (* shs )[])
100
101
{
101
102
register int num ;
@@ -130,7 +131,7 @@ int28out(int16 (*shs)[])
130
131
* Note:
131
132
* Fills any nonexistent digits with NULLs.
132
133
*/
133
- int32 *
134
+ int32 *
134
135
int44in (char * input_string )
135
136
{
136
137
int32 * foo = (int32 * ) palloc (4 * sizeof (int32 ));
@@ -151,7 +152,7 @@ int44in(char *input_string)
151
152
/*
152
153
* int28out - converts internal form to "num num ..."
153
154
*/
154
- char *
155
+ char *
155
156
int44out (int32 an_array [])
156
157
{
157
158
int temp = 4 ;
@@ -194,7 +195,7 @@ int4in(char *num)
194
195
/*
195
196
* int4out - converts int4 to "num"
196
197
*/
197
- char *
198
+ char *
198
199
int4out (int32 l )
199
200
{
200
201
char * result ;
@@ -228,6 +229,88 @@ i4toi2(int32 arg1)
228
229
return ((int16 ) arg1 );
229
230
}
230
231
232
+ text *
233
+ int2_text (int16 arg1 )
234
+ {
235
+ text * result ;
236
+
237
+ int len ;
238
+ char * str ;
239
+
240
+ str = int2out (arg1 );
241
+ len = (strlen (str ) + VARHDRSZ );
242
+
243
+ result = PALLOC (len );
244
+
245
+ VARSIZE (result ) = len ;
246
+ memmove (VARDATA (result ), str , (len - VARHDRSZ ));
247
+
248
+ PFREE (str );
249
+
250
+ return (result );
251
+ } /* int2_text() */
252
+
253
+ int16
254
+ text_int2 (text * string )
255
+ {
256
+ int16 result ;
257
+
258
+ int len ;
259
+ char * str ;
260
+
261
+ len = (VARSIZE (string ) - VARHDRSZ );
262
+
263
+ str = PALLOC (len + 1 );
264
+ memmove (str , VARDATA (string ), len );
265
+ * (str + len ) = '\0' ;
266
+
267
+ result = int2in (str );
268
+ PFREE (str );
269
+
270
+ return (result );
271
+ } /* text_int2() */
272
+
273
+ text *
274
+ int4_text (int32 arg1 )
275
+ {
276
+ text * result ;
277
+
278
+ int len ;
279
+ char * str ;
280
+
281
+ str = int4out (arg1 );
282
+ len = (strlen (str ) + VARHDRSZ );
283
+
284
+ result = PALLOC (len );
285
+
286
+ VARSIZE (result ) = len ;
287
+ memmove (VARDATA (result ), str , (len - VARHDRSZ ));
288
+
289
+ PFREE (str );
290
+
291
+ return (result );
292
+ } /* int4_text() */
293
+
294
+ int32
295
+ text_int4 (text * string )
296
+ {
297
+ int32 result ;
298
+
299
+ int len ;
300
+ char * str ;
301
+
302
+ len = (VARSIZE (string ) - VARHDRSZ );
303
+
304
+ str = PALLOC (len + 1 );
305
+ memmove (str , VARDATA (string ), len );
306
+ * (str + len ) = '\0' ;
307
+
308
+ result = int4in (str );
309
+ PFREE (str );
310
+
311
+ return (result );
312
+ } /* text_int4() */
313
+
231
314
232
315
/*
233
316
* =========================
0 commit comments