*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.38 2001/08/21 20:39:54 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.39 2001/09/17 20:05:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include
#include
-#include "libpq-fe.h"
-#include "libpq-int.h"
-
#ifdef WIN32
#include "win32.h"
#include "io.h"
#include
#endif
+#include "libpq-fe.h"
+#include "libpq-int.h"
#include "libpq/libpq-fs.h" /* must come after sys/stat.h */
+
#define LO_BUFSIZE 8192
static int lo_initialize(PGconn *conn);
+
/*
* lo_open
* opens an existing large object
* lo_read
* read len bytes of the large object into buf
*
- * returns the length of bytes read.
+ * returns the number of bytes read, or -1 on failure.
* the CALLER must have allocated enough space to hold the result returned
*/
* lo_write
* write len bytes of buf into the large object fd
*
+ * returns the number of bytes written, or -1 on failure.
*/
int
lo_write(PGconn *conn, int fd, char *buf, size_t len)
if (conn->lobjfuncs == (PGlobjfuncs *) NULL)
{
if (lo_initialize(conn) < 0)
- return -1;
+ return InvalidOid;
}
argv[0].isint = 1;
/*
* lo_import -
* imports a file as an (inversion) large object.
- * returns the oid of that object upon success,
- * returns InvalidOid upon failure
*
+ * returns the oid of that object upon success,
+ * returns InvalidOid upon failure
*/
Oid
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not create large object for file \"%s\"\n"),
filename);
+ (void) close(fd);
return InvalidOid;
}
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not open large object %u\n"),
lobjOid);
+ (void) close(fd);
return InvalidOid;
}
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("error while reading file \"%s\"\n"),
filename);
+ (void) close(fd);
+ (void) lo_close(conn, lobj);
return InvalidOid;
}
}
int lobj;
/*
- * create an inversion "object"
+ * open the large object.
*/
lobj = lo_open(conn, lobjId, INV_READ);
if (lobj == -1)
}
/*
- * open the file to be written to
+ * create the file to be written to
*/
fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC | PG_BINARY, 0666);
if (fd < 0)
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not open file \"%s\": %s\n"),
filename, strerror(errno));
- return 0;
+ (void) lo_close(conn, lobj);
+ return -1;
}
/*
printfPQExpBuffer(&conn->errorMessage,
libpq_gettext("error while writing to file \"%s\"\n"),
filename);
+ (void) lo_close(conn, lobj);
+ (void) close(fd);
return -1;
}
}