1
1
/*
2
2
* PostgreSQL type definitions for managed LargeObjects.
3
3
*
4
- * $Id: lo .c,v 1.5 2000/11/20 20:36:55 tgl Exp $
4
+ * $Header: /cvsroot/pgsql/contrib/lo/lo .c,v 1.6 2000/11/21 21:51:58 tgl Exp $
5
5
*
6
6
*/
7
7
8
+ #include "postgres.h"
9
+
8
10
#include <stdio.h>
9
11
10
- #include <postgres.h>
11
- #include <utils/palloc.h>
12
+ #include "utils/palloc.h"
12
13
13
14
/* Required for largeobjects */
14
- #include < libpq/libpq-fs.h>
15
- #include < libpq/be-fsstubs.h>
15
+ #include " libpq/libpq-fs.h"
16
+ #include " libpq/be-fsstubs.h"
16
17
17
18
/* Required for SPI */
18
- #include < executor/spi.h>
19
+ #include " executor/spi.h"
19
20
20
21
/* Required for triggers */
21
- #include <commands/trigger.h>
22
+ #include "commands/trigger.h"
23
+
24
+
25
+ #define atooid (x ) ((Oid) strtoul((x), NULL, 10))
22
26
23
- /* required for tolower() */
24
27
25
28
/*
26
29
* This is the internal storage format for managed large objects
@@ -40,7 +43,7 @@ Blob *lo(Oid oid); /* Return Blob based on oid */
40
43
Datum lo_manage (PG_FUNCTION_ARGS ); /* Trigger handler */
41
44
42
45
/*
43
- * This creates a large object, and set's its OID to the value in the
46
+ * This creates a large object, and sets its OID to the value in the
44
47
* supplied string.
45
48
*
46
49
* If the string is empty, then a new LargeObject is created, and its oid
@@ -55,20 +58,13 @@ lo_in(char *str)
55
58
56
59
if (strlen (str ) > 0 )
57
60
{
58
-
59
- count = sscanf (str , "%d" , & oid );
61
+ count = sscanf (str , "%u" , & oid );
60
62
61
63
if (count < 1 )
62
- {
63
64
elog (ERROR , "lo_in: error in parsing \"%s\"" , str );
64
- return (NULL );
65
- }
66
65
67
- if (oid < 0 )
68
- {
66
+ if (oid == InvalidOid )
69
67
elog (ERROR , "lo_in: illegal oid \"%s\"" , str );
70
- return (NULL );
71
- }
72
68
}
73
69
else
74
70
{
@@ -79,10 +75,7 @@ lo_in(char *str)
79
75
oid = DatumGetObjectId (DirectFunctionCall1 (lo_creat ,
80
76
Int32GetDatum (INV_READ | INV_WRITE )));
81
77
if (oid == InvalidOid )
82
- {
83
78
elog (ERROR , "lo_in: InvalidOid returned from lo_creat" );
84
- return (NULL );
85
- }
86
79
}
87
80
88
81
result = (Blob * ) palloc (sizeof (Blob ));
@@ -104,7 +97,7 @@ lo_out(Blob * addr)
104
97
return (NULL );
105
98
106
99
result = (char * ) palloc (32 );
107
- sprintf (result , "%d " , * addr );
100
+ sprintf (result , "%u " , * addr );
108
101
return (result );
109
102
}
110
103
@@ -190,7 +183,7 @@ lo_manage(PG_FUNCTION_ARGS)
190
183
191
184
if ((orig != newv && (orig == NULL || newv == NULL )) || (orig != NULL && newv != NULL && strcmp (orig , newv )))
192
185
DirectFunctionCall1 (lo_unlink ,
193
- ObjectIdGetDatum (( Oid ) atoi (orig )));
186
+ ObjectIdGetDatum (atooid (orig )));
194
187
195
188
if (newv )
196
189
pfree (newv );
@@ -211,7 +204,7 @@ lo_manage(PG_FUNCTION_ARGS)
211
204
if (orig != NULL )
212
205
{
213
206
DirectFunctionCall1 (lo_unlink ,
214
- ObjectIdGetDatum (( Oid ) atoi (orig )));
207
+ ObjectIdGetDatum (atooid (orig )));
215
208
216
209
pfree (orig );
217
210
}
0 commit comments