summaryrefslogtreecommitdiff
path: root/src/backend/libpq/be-fsstubs.c
diff options
context:
space:
mode:
authorTom Lane2012-10-08 22:24:06 +0000
committerTom Lane2012-10-08 22:24:32 +0000
commit26fe56481c0f7baa705f0b3265b5a0676f894a94 (patch)
tree60bfe35565e16c168915e10500f3b61440f7865f /src/backend/libpq/be-fsstubs.c
parent878daf2e72755feadbfb8d21aad26dafd8658086 (diff)
Code review for 64-bit-large-object patch.
Fix broken-on-bigendian-machines byte-swapping functions, add missed update of alternate regression expected file, improve error reporting, remove some unnecessary code, sync testlo64.c with current testlo.c (it seems to have been cloned from a very old copy of that), assorted cosmetic improvements.
Diffstat (limited to 'src/backend/libpq/be-fsstubs.c')
-rw-r--r--src/backend/libpq/be-fsstubs.c60
1 files changed, 21 insertions, 39 deletions
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index 4bc81ba9f4d..c4ac1a650f5 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -39,7 +39,6 @@
#include "postgres.h"
#include <fcntl.h>
-#include <limits.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -57,7 +56,9 @@
*/
bool lo_compat_privileges;
-/*#define FSDB 1*/
+/* define this to enable debug logging */
+/* #define FSDB 1 */
+/* chunk size for lo_import/lo_export transfers */
#define BUFSIZE 8192
/*
@@ -210,7 +211,6 @@ lo_write(int fd, const char *buf, int len)
return status;
}
-
Datum
lo_lseek(PG_FUNCTION_ARGS)
{
@@ -226,42 +226,31 @@ lo_lseek(PG_FUNCTION_ARGS)
status = inv_seek(cookies[fd], offset, whence);
- if (INT_MAX < status)
- {
+ /* guard against result overflow */
+ if (status != (int32) status)
ereport(ERROR,
- (errcode(ERRCODE_BLOB_OFFSET_OVERFLOW),
- errmsg("offset overflow: %d", fd)));
- PG_RETURN_INT32(-1);
- }
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("lo_lseek result out of range for large-object descriptor %d",
+ fd)));
- PG_RETURN_INT32(status);
+ PG_RETURN_INT32((int32) status);
}
-
Datum
lo_lseek64(PG_FUNCTION_ARGS)
{
int32 fd = PG_GETARG_INT32(0);
int64 offset = PG_GETARG_INT64(1);
int32 whence = PG_GETARG_INT32(2);
- MemoryContext currentContext;
- int64 status;
+ int64 status;
if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
- {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("invalid large-object descriptor: %d", fd)));
- PG_RETURN_INT64(-1);
- }
-
- Assert(fscxt != NULL);
- currentContext = MemoryContextSwitchTo(fscxt);
status = inv_seek(cookies[fd], offset, whence);
- MemoryContextSwitchTo(currentContext);
-
PG_RETURN_INT64(status);
}
@@ -301,7 +290,7 @@ Datum
lo_tell(PG_FUNCTION_ARGS)
{
int32 fd = PG_GETARG_INT32(0);
- int64 offset = 0;
+ int64 offset;
if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
ereport(ERROR,
@@ -310,37 +299,30 @@ lo_tell(PG_FUNCTION_ARGS)
offset = inv_tell(cookies[fd]);
- if (INT_MAX < offset)
- {
+ /* guard against result overflow */
+ if (offset != (int32) offset)
ereport(ERROR,
- (errcode(ERRCODE_BLOB_OFFSET_OVERFLOW),
- errmsg("offset overflow: %d", fd)));
- PG_RETURN_INT32(-1);
- }
+ (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+ errmsg("lo_tell result out of range for large-object descriptor %d",
+ fd)));
- PG_RETURN_INT32(offset);
+ PG_RETURN_INT32((int32) offset);
}
-
Datum
lo_tell64(PG_FUNCTION_ARGS)
{
int32 fd = PG_GETARG_INT32(0);
+ int64 offset;
if (fd < 0 || fd >= cookies_size || cookies[fd] == NULL)
- {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("invalid large-object descriptor: %d", fd)));
- PG_RETURN_INT64(-1);
- }
- /*
- * We assume we do not need to switch contexts for inv_tell. That is
- * true for now, but is probably more than this module ought to
- * assume...
- */
- PG_RETURN_INT64(inv_tell(cookies[fd]));
+ offset = inv_tell(cookies[fd]);
+
+ PG_RETURN_INT64(offset);
}
Datum