77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.29 1999/05/03 19:09:39 momjian Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.30 1999/05/09 00:54:30 tgl Exp $
1111 *
1212 * NOTES
1313 * This should be moved to a more appropriate place. It is here
@@ -99,7 +99,7 @@ lo_close(int fd)
9999{
100100MemoryContext currentContext ;
101101
102- if (fd >=MAX_LOBJ_FDS )
102+ if (fd < 0 || fd >=MAX_LOBJ_FDS )
103103{
104104elog (ERROR ,"lo_close: large obj descriptor (%d) out of range" ,fd );
105105return -2 ;
@@ -131,14 +131,34 @@ lo_close(int fd)
131131int
132132lo_read (int fd ,char * buf ,int len )
133133{
134- Assert (cookies [fd ]!= NULL );
134+ if (fd < 0 || fd >=MAX_LOBJ_FDS )
135+ {
136+ elog (ERROR ,"lo_read: large obj descriptor (%d) out of range" ,fd );
137+ return -2 ;
138+ }
139+ if (cookies [fd ]== NULL )
140+ {
141+ elog (ERROR ,"lo_read: invalid large obj descriptor (%d)" ,fd );
142+ return -3 ;
143+ }
144+
135145return inv_read (cookies [fd ],buf ,len );
136146}
137147
138148int
139149lo_write (int fd ,char * buf ,int len )
140150{
141- Assert (cookies [fd ]!= NULL );
151+ if (fd < 0 || fd >=MAX_LOBJ_FDS )
152+ {
153+ elog (ERROR ,"lo_write: large obj descriptor (%d) out of range" ,fd );
154+ return -2 ;
155+ }
156+ if (cookies [fd ]== NULL )
157+ {
158+ elog (ERROR ,"lo_write: invalid large obj descriptor (%d)" ,fd );
159+ return -3 ;
160+ }
161+
142162return inv_write (cookies [fd ],buf ,len );
143163}
144164
@@ -149,11 +169,16 @@ lo_lseek(int fd, int offset, int whence)
149169MemoryContext currentContext ;
150170int ret ;
151171
152- if (fd >=MAX_LOBJ_FDS )
172+ if (fd < 0 || fd >=MAX_LOBJ_FDS )
153173{
154- elog (ERROR ,"lo_seek : large obj descriptor (%d) out of range" ,fd );
174+ elog (ERROR ,"lo_lseek : large obj descriptor (%d) out of range" ,fd );
155175return -2 ;
156176}
177+ if (cookies [fd ]== NULL )
178+ {
179+ elog (ERROR ,"lo_lseek: invalid large obj descriptor (%d)" ,fd );
180+ return -3 ;
181+ }
157182
158183currentContext = MemoryContextSwitchTo ((MemoryContext )fscxt );
159184
@@ -197,7 +222,7 @@ lo_creat(int mode)
197222int
198223lo_tell (int fd )
199224{
200- if (fd >=MAX_LOBJ_FDS )
225+ if (fd < 0 || fd >=MAX_LOBJ_FDS )
201226{
202227elog (ERROR ,"lo_tell: large object descriptor (%d) out of range" ,fd );
203228return -2 ;
@@ -255,7 +280,7 @@ lowrite(int fd, struct varlena * wbuf)
255280Oid
256281lo_import (text * filename )
257282{
258- int fd ;
283+ File fd ;
259284int nbytes ,
260285tmp ;
261286
@@ -269,13 +294,13 @@ lo_import(text *filename)
269294 */
270295StrNCpy (fnamebuf ,VARDATA (filename ),VARSIZE (filename )- VARHDRSZ + 1 );
271296#ifndef __CYGWIN32__
272- fd = open (fnamebuf ,O_RDONLY ,0666 );
297+ fd = PathNameOpenFile (fnamebuf ,O_RDONLY ,0666 );
273298#else
274- fd = open (fnamebuf ,O_RDONLY |O_BINARY ,0666 );
299+ fd = PathNameOpenFile (fnamebuf ,O_RDONLY |O_BINARY ,0666 );
275300#endif
276301if (fd < 0 )
277302{/* error */
278- elog (ERROR ,"be_lo_import: can't open unix file\"%s\"\n" ,
303+ elog (ERROR ,"be_lo_import: can't open unix file \"%s\"\n" ,
279304fnamebuf );
280305}
281306
@@ -298,7 +323,7 @@ lo_import(text *filename)
298323/*
299324 * read in from the Unix file and write to the inversion file
300325 */
301- while ((nbytes = read (fd ,buf ,BUFSIZE ))> 0 )
326+ while ((nbytes = FileRead (fd ,buf ,BUFSIZE ))> 0 )
302327{
303328tmp = inv_write (lobj ,buf ,nbytes );
304329if (tmp < nbytes )
@@ -308,7 +333,7 @@ lo_import(text *filename)
308333}
309334}
310335
311- close (fd );
336+ FileClose (fd );
312337inv_close (lobj );
313338
314339return lobjOid ;
@@ -321,7 +346,7 @@ lo_import(text *filename)
321346int4
322347lo_export (Oid lobjId ,text * filename )
323348{
324- int fd ;
349+ File fd ;
325350int nbytes ,
326351tmp ;
327352
@@ -331,7 +356,7 @@ lo_export(Oid lobjId, text *filename)
331356mode_t oumask ;
332357
333358/*
334- *create an inversion "object"
359+ *open the inversion "object"
335360 */
336361lobj = inv_open (lobjId ,INV_READ );
337362if (lobj == NULL )
@@ -343,17 +368,17 @@ lo_export(Oid lobjId, text *filename)
343368/*
344369 * open the file to be written to
345370 */
346- oumask = umask ((mode_t )0 );
347371StrNCpy (fnamebuf ,VARDATA (filename ),VARSIZE (filename )- VARHDRSZ + 1 );
372+ oumask = umask ((mode_t )0 );
348373#ifndef __CYGWIN32__
349- fd = open (fnamebuf ,O_CREAT |O_WRONLY |O_TRUNC ,0666 );
374+ fd = PathNameOpenFile (fnamebuf ,O_CREAT |O_WRONLY |O_TRUNC ,0666 );
350375#else
351- fd = open (fnamebuf ,O_CREAT |O_WRONLY |O_TRUNC |O_BINARY ,0666 );
376+ fd = PathNameOpenFile (fnamebuf ,O_CREAT |O_WRONLY |O_TRUNC |O_BINARY ,0666 );
352377#endif
353378umask (oumask );
354379if (fd < 0 )
355380{/* error */
356- elog (ERROR ,"lo_export: can't open unix file\"%s\"" ,
381+ elog (ERROR ,"lo_export: can't open unix file \"%s\"" ,
357382fnamebuf );
358383}
359384
@@ -362,7 +387,7 @@ lo_export(Oid lobjId, text *filename)
362387 */
363388while ((nbytes = inv_read (lobj ,buf ,BUFSIZE ))> 0 )
364389{
365- tmp = write (fd ,buf ,nbytes );
390+ tmp = FileWrite (fd ,buf ,nbytes );
366391if (tmp < nbytes )
367392{
368393elog (ERROR ,"lo_export: error while writing \"%s\"" ,
@@ -371,7 +396,7 @@ lo_export(Oid lobjId, text *filename)
371396}
372397
373398inv_close (lobj );
374- close (fd );
399+ FileClose (fd );
375400
376401return 1 ;
377402}