int inv_seek(struct lobj *obj_desc, int offset, int whence) { ASSERT(PTR_VALID(obj_desc)); switch (whence) { case SEEK_SET: if (offset < 0) elog(ERROR, "invalid seek offset: %d", offset); obj_desc->offset = offset; break; case SEEK_CUR: if (offset < 0 && obj_desc->offset < ((uint32) (-offset))) elog(ERROR, "invalid seek offset: %d", offset); obj_desc->offset += offset; break; case SEEK_END: { uint32 size = inv_getsize(obj_desc); if (offset < 0 && size < ((uint32) (-offset))) elog(ERROR, "invalid seek offset: %d", offset); obj_desc->offset = size + offset; } break; default: elog(ERROR, "invalid whence: %d", whence); } return obj_desc->offset; }
int inv_seek(LargeObjectDesc *obj_desc, int offset, int whence) { Assert(PointerIsValid(obj_desc)); switch (whence) { case SEEK_SET: if (offset < 0) elog(ERROR, "invalid seek offset: %d", offset); obj_desc->offset = offset; break; case SEEK_CUR: if (offset < 0 && obj_desc->offset < ((uint32) (-offset))) elog(ERROR, "invalid seek offset: %d", offset); obj_desc->offset += offset; break; case SEEK_END: { uint32 size = inv_getsize(obj_desc); if (offset < 0 && size < ((uint32) (-offset))) elog(ERROR, "invalid seek offset: %d", offset); obj_desc->offset = size + offset; } break; default: elog(ERROR, "invalid whence: %d", whence); } return obj_desc->offset; }
int64 inv_seek(LargeObjectDesc *obj_desc, int64 offset, int whence) { int64 newoffset; Assert(PointerIsValid(obj_desc)); /* * Note: overflow in the additions is possible, but since we will reject * negative results, we don't need any extra test for that. */ switch (whence) { case SEEK_SET: newoffset = offset; break; case SEEK_CUR: newoffset = obj_desc->offset + offset; break; case SEEK_END: newoffset = inv_getsize(obj_desc) + offset; break; default: ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("invalid whence setting: %d", whence))); newoffset = 0; /* keep compiler quiet */ break; } /* * use errmsg_internal here because we don't want to expose INT64_FORMAT * in translatable strings; doing better is not worth the trouble */ if (newoffset < 0 || newoffset > MAX_LARGE_OBJECT_SIZE) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg_internal("invalid large object seek target: " INT64_FORMAT, newoffset))); obj_desc->offset = newoffset; return newoffset; }