Skip to content

Commit 317acd0

Browse files
author
Thomas G. Lockhart
committed
Add conversions for int2 and int4 to and from text.
1 parent 2c1557a commit 317acd0

File tree

1 file changed

+91
-8
lines changed
  • src/backend/utils/adt

1 file changed

+91
-8
lines changed

src/backend/utils/adt/int.c

Lines changed: 91 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* 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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -16,7 +16,7 @@
1616
* I/O routines:
1717
* int2in, int2out, int28in, int28out, int4in, int4out
1818
* Conversion routines:
19-
* itoi
19+
* itoi, int2_text, int4_text
2020
* Boolean operators:
2121
* inteq, intne, intlt, intle, intgt, intge
2222
* Arithmetic operators:
@@ -29,6 +29,7 @@
2929
* fix me when we figure out what we want to do about ANSIfication...
3030
*/
3131
#include <stdio.h>
32+
#include <string.h>
3233

3334
#include "postgres.h"
3435
#include "fmgr.h"
@@ -50,7 +51,7 @@ int2in(char *num)
5051
/*
5152
* int2out - converts short to "num"
5253
*/
53-
char *
54+
char *
5455
int2out(int16 sh)
5556
{
5657
char *result;
@@ -66,7 +67,7 @@ int2out(int16 sh)
6667
* Note:
6768
* Fills any nonexistent digits with NULLs.
6869
*/
69-
int16 *
70+
int16 *
7071
int28in(char *shs)
7172
{
7273
register int16 (*result)[];
@@ -95,7 +96,7 @@ int28in(char *shs)
9596
/*
9697
* int28out - converts internal form to "num num ..."
9798
*/
98-
char *
99+
char *
99100
int28out(int16 (*shs)[])
100101
{
101102
register int num;
@@ -130,7 +131,7 @@ int28out(int16 (*shs)[])
130131
* Note:
131132
* Fills any nonexistent digits with NULLs.
132133
*/
133-
int32 *
134+
int32 *
134135
int44in(char *input_string)
135136
{
136137
int32 *foo = (int32 *) palloc(4 * sizeof(int32));
@@ -151,7 +152,7 @@ int44in(char *input_string)
151152
/*
152153
* int28out - converts internal form to "num num ..."
153154
*/
154-
char *
155+
char *
155156
int44out(int32 an_array[])
156157
{
157158
int temp = 4;
@@ -194,7 +195,7 @@ int4in(char *num)
194195
/*
195196
* int4out - converts int4 to "num"
196197
*/
197-
char *
198+
char *
198199
int4out(int32 l)
199200
{
200201
char *result;
@@ -228,6 +229,88 @@ i4toi2(int32 arg1)
228229
return ((int16) arg1);
229230
}
230231

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+
231314

232315
/*
233316
* =========================

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy